Skip to content

Commit 8540f9d

Browse files
authored
Improved drawing of Pareto set (#201)
* Added Pareto set drawing * Improved drawing of Pareto set
1 parent bc7abd9 commit 8540f9d

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

examples/Machine_learning/SVC/_2D/Example_SVC_2D_MCO_Transformators_State.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def factory_dataset():
3434
kernel_coefficient_bound = {'low': -3, 'up': 1}
3535
problem = MCO_SVC_2D_Transformators_State.MCO_SVC_2D_Transformators_State(X, Y, regularization_value_bound,
3636
kernel_coefficient_bound)
37-
method_params = SolverParameters(r=np.double(2.0), iters_limit=500, number_of_parallel_points=1,
37+
method_params = SolverParameters(r=np.double(2.0), iters_limit=500, number_of_parallel_points=10,
3838
evolvent_density=12, number_of_lambdas=5)
3939
solver = Solver(problem=problem, parameters=method_params)
4040
# Добавляем вывод результатов в консоль
@@ -49,14 +49,14 @@ def factory_dataset():
4949

5050
# Выводим множество Парето (координаты - значения функций)
5151
var = [trial.point.float_variables for trial in sol.best_trials]
52-
val = [[-trial.function_values[i].value for i in range(2)] for trial in sol.best_trials]
52+
val = [[trial.function_values[i].value for i in range(2)] for trial in sol.best_trials]
5353

5454
print("size pareto set: ", len(var))
5555
for fvar, fval in zip(var, val):
5656
print(fvar, fval)
5757

5858
# Строим график множества Парето z[0]-z[1]
59-
fv1 = [-trial.function_values[0].value for trial in sol.best_trials]
59+
fv1 = [trial.function_values[0].value for trial in sol.best_trials]
6060
fv2 = [-trial.function_values[1].value for trial in sol.best_trials]
6161
plt.plot(fv1, fv2, 'ro')
6262
plt.show()

iOpt/output_system/listeners/console_outputers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ def on_end_iteration(self, curr_points: List[SearchDataItem], curr_solution: Sol
4343

4444
def on_method_stop(self, search_data: SearchData, solution: Solution, status: bool):
4545
self.__outputer.print_final_result_info(solution, status)
46+
if self.mode == 'full' and solution.best_trials.size > 1:
47+
self.__outputer.print_pareto_set_info(solution)

iOpt/output_system/outputers/console_outputer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def print_final_result_info(self, solution: Solution, status: bool):
8585
best_trial_value, self.ndv
8686
)
8787

88+
def print_pareto_set_info(self, solution: Solution):
89+
self.__functions.print_pareto_set(solution.best_trials)
8890

8991
class OutputFunctions:
9092

@@ -186,3 +188,21 @@ def print_best(self, number_of_global_trials, number_of_local_trials, solution_a
186188
print("|{:>29} {:<{width}.8f}|".format("currant accuracy: ", solution_accuracy,
187189
width=size_max_one_output * dim))
188190
print("." * (30 + size_max_one_output * dim + 2))
191+
192+
def print_pareto_set(self, best_trials):
193+
size_max_one_output = 15
194+
dim = len(best_trials[0].point.float_variables)
195+
criteria_count = len(best_trials[0].function_values)
196+
197+
var = [trial.point.float_variables for trial in best_trials]
198+
val = [[trial.function_values[i].value for i in range(len(trial.function_values))] for trial in best_trials]
199+
200+
string_len = size_max_one_output * (dim + criteria_count) + 6
201+
print("| {:^{width}} |".format(f"Size pareto set: {len(var)}", width=string_len))
202+
print("-" * (string_len + 4))
203+
204+
for fvar, fval in zip(var, val):
205+
print("| {:>{width_point}}".format(str(fvar), width_point=dim * size_max_one_output), end=' ')
206+
print("{:<{width_criteria}} |".format(str(fval), width_criteria=criteria_count * size_max_one_output))
207+
208+
print("-" * (string_len + 4))

iOpt/output_system/painters/plotters/plotters.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,5 +441,9 @@ class PlotterPareto(Plotter2D):
441441
def __init__(self):
442442
super().__init__(None, None, None)
443443

444-
def plot_pareto(self, first_criteria_values, second_criteria_values, clr='blue', mrkr='o', mrkrs=8):
444+
def plot_pareto(self, first_criteria_values, second_criteria_values,
445+
first_criteria_indx, second_criteria_indx, clr='blue', mrkr='o', mrkrs=8):
445446
self.plot_points(first_criteria_values, second_criteria_values, clr, mrkr, mrkrs)
447+
self.ax.set_title('Pareto set', fontsize=8)
448+
self.ax.set_xlabel(f'Values of criteria number: {first_criteria_indx}', fontsize=8)
449+
self.ax.set_ylabel(f'Values of criteria number: {second_criteria_indx}', fontsize=8)

iOpt/output_system/painters/static_painters.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,20 @@ def __init__(self,
295295
self.path_for_saves = path_for_saves
296296
self.file_name = file_name
297297

298+
# numbers of criteria selected by user
299+
self.first_criteria_indx = criteria_indxs[0]
300+
self.second_criteria_indx = criteria_indxs[1]
301+
298302
# values of Pareto-efficient criteria with input indices
299-
self.first_criteria_values = [trial.function_values[criteria_indxs[0]].value for trial in solution.best_trials]
300-
self.second_criteria_values = [trial.function_values[criteria_indxs[1]].value for trial in solution.best_trials]
303+
self.first_criteria_values = [trial.function_values[self.first_criteria_indx].value for trial in solution.best_trials]
304+
self.second_criteria_values = [trial.function_values[self.second_criteria_indx].value for trial in solution.best_trials]
301305

302306
# definition of plotter
303307
self.plotter = PlotterPareto()
304308

305309
def paint_pareto(self):
306-
self.plotter.plot_pareto(self.first_criteria_values, self.second_criteria_values)
310+
self.plotter.plot_pareto(self.first_criteria_values, self.second_criteria_values,
311+
self.first_criteria_indx, self.second_criteria_indx)
307312

308313
def save_image(self):
309314
if not os.path.isdir(self.path_for_saves):

0 commit comments

Comments
 (0)