-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_illustrations.py
133 lines (114 loc) · 5.28 KB
/
run_illustrations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
import plotting.plotting
from running import running
import results.results_utils
from solvers.projected_common_directions import ProjectedCommonDirections, ProjectedCommonDirectionsConfig
import matplotlib.pyplot as plt
def main():
running.soft_window_clear()
# Choose problem
test_problems_list = ['rosenbrock_single', # 0, n even
'rosenbrock_multiple', # 1, n even
'powell', # 2, n multiple of 4
'well_conditioned_convex_quadratic', # 3, any n
'ill_conditioned_convex_quadratic', # 4, any n
]
problem_name = test_problems_list[0]
input_dim = 40
extended_problem_name = problem_name + '_n' + str(input_dim)
problem_tup = running.get_problem(problem_name, input_dim)
NO_RUNS = 5
################################################################################
################################################################################
order = 'sd'
experiment_str = 'try_stuff'
if order == 'sd':
if experiment_str == 'try_stuff':
solver_names = [
'solver1',
'solver2',
# 'solver3',
# 'solver4',
]
elif experiment_str == 'granular':
solver_names = [ # NOTE: select solvers
'1d.1d.0',
]
passable_name = 'default_illustrations_sd'
elif order == 'newton':
if experiment_str in ['orth_Pk', 'haar_gauss']:
solver_names = [
'solver1',
'solver2',
'solver3',
'solver4',
]
elif experiment_str == 'sketch_size':
solver_names = [
'solver1',
'solver2',
'solver3',
'solver4',
'solver5',
]
passable_name = 'default_illustrations_newton'
elif order == 'quasi_newton':
solver_names = [
'solver1',
'solver2',
'solver3',
'solver4',
]
passable_name = 'default_illustrations_quasi_newton'
CONFIG_PATH_LIST = [[order, experiment_str, name] for name in solver_names]
RUN = True
SAVE_RESULTS = True
PLOT = True
SAVE_FIG = False
INCLUDE_SOLVER_NAMES = True
FOR_APPENDIX = False
FIGSIZE = (5.9, 2.4) # NOTE: the one most used
# FIGSIZE = (5.9, 2.0) # NOTE: if not much space is required
# FIGSIZE = (5.9, 2.5) # NOTE: if a bit more (vertical) space is required
LABEL_NCOL = 1
################################################################################
################################################################################
configs_list = []
for config_path in CONFIG_PATH_LIST:
config = running.combine_configs(extended_problem_name,
config_path=config_path,
passable_name=passable_name)
configs_list.append(config)
solvers_list = [ProjectedCommonDirections(config) for config in configs_list]
# Run and store results
results_attrs = ['final_f_val']
if RUN:
results_dict = running.run_solvers_single_prob(problem_tup, solvers_list,
no_runs=NO_RUNS,
result_attrs=results_attrs,
save_results=SAVE_RESULTS)
if PLOT:
outputs_list = results.results_utils.generate_illustrations(config_path_list=CONFIG_PATH_LIST,
extended_problem_name=extended_problem_name,
no_runs=NO_RUNS,
passable_config_name=passable_name)
fig = plotting.plotting.plot_loss_vs_iteration(solver_outputs=outputs_list,
include_Pk_orth=False,
include_sketch_size=False,
include_ensemble=False,
figsize=FIGSIZE,
label_ncol=LABEL_NCOL)
plt.show()
if SAVE_FIG:
if not PLOT:
raise Exception('Trying to save plot but none has been created!')
file_path = results.results_utils.generate_pdf_file_name(CONFIG_PATH_LIST,
plot_type='illustration',
for_appendix=FOR_APPENDIX,
include_solver_names=INCLUDE_SOLVER_NAMES,
solver_name_list=solver_names)
# Ensure the directory exists
os.makedirs(os.path.dirname(file_path), exist_ok=True)
fig.savefig(fname=file_path)
if __name__ == '__main__':
main()