Skip to content

Commit 47cdfe0

Browse files
committed
tuning
1 parent d588cc1 commit 47cdfe0

6 files changed

Lines changed: 46 additions & 36 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ scripts/distributions/*png
116116
scripts/distributions/*pkl
117117
scripts/distributions/figures
118118

119-
scripts/tuning/*pdf
119+
scripts/tuning/figures
120120
scripts/tuning/configs_*.csv
121+
scripts/tuning/data*
122+
script/tuning/data_new/*
121123

122124
data_old

scripts/repelling/repelling.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def calculate_potential(centers, problem):
5454
return potential, n_duplicate_runs
5555

5656

57-
def plot_contour(X, Y, Z, colorbar=True):
57+
def plot_contour(X, Y, Z, colorbar=True, vmin=-2, vmax=2):
5858
plt.contourf(
59-
X, Y, np.log10(Z), levels=200, cmap="Spectral", zorder=-1, vmin=-1, vmax=2.5
59+
X, Y, np.log10(Z), levels=200, cmap="Spectral",
60+
zorder=-1, vmin=vmin, vmax=vmax
6061
)
6162
plt.xlabel(R"$x_1$")
6263
plt.ylabel(R"$x_2$")
@@ -498,12 +499,12 @@ def interactive(fid=21, instance=6, dim=2, rep=True, coverage=5, save_frames = F
498499
# c_cmaes.constants.tol_min_sigma = 0.01
499500

500501
modules = c_cmaes.parameters.Modules()
501-
modules.restart_strategy = c_cmaes.options.BIPOP
502+
modules.restart_strategy = c_cmaes.options.RestartStrategy.RESTART
502503
# modules.bound_correction = c_cmaes.options.SATURATE
503-
modules.elitist = True
504-
modules.active = True
504+
# modules.elitist = True
505+
# modules.active = True
505506
modules.repelling_restart = rep
506-
modules.center_placement = c_cmaes.options.UNIFORM
507+
modules.center_placement = c_cmaes.options.CenterPlacement.UNIFORM
507508
settings = c_cmaes.parameters.Settings(
508509
dim,
509510
modules,

scripts/tuning/analysis.ipynb

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@
31723172
},
31733173
{
31743174
"cell_type": "code",
3175-
"execution_count": null,
3175+
"execution_count": 310,
31763176
"id": "59d5a6c6",
31773177
"metadata": {},
31783178
"outputs": [
@@ -3273,7 +3273,7 @@
32733273
},
32743274
{
32753275
"cell_type": "code",
3276-
"execution_count": 332,
3276+
"execution_count": null,
32773277
"id": "26fe56ff",
32783278
"metadata": {},
32793279
"outputs": [
@@ -3406,6 +3406,17 @@
34063406
},
34073407
"metadata": {},
34083408
"output_type": "display_data"
3409+
},
3410+
{
3411+
"ename": "",
3412+
"evalue": "",
3413+
"output_type": "error",
3414+
"traceback": [
3415+
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
3416+
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
3417+
"\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
3418+
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
3419+
]
34093420
}
34103421
],
34113422
"source": [
@@ -3426,25 +3437,6 @@
34263437
" plt.savefig(f\"{module}_shap_heat.pdf\")"
34273438
]
34283439
},
3429-
{
3430-
"cell_type": "code",
3431-
"execution_count": null,
3432-
"id": "fce55604",
3433-
"metadata": {},
3434-
"outputs": [
3435-
{
3436-
"data": {
3437-
"text/plain": [
3438-
"np.float64(0.05)"
3439-
]
3440-
},
3441-
"execution_count": 330,
3442-
"metadata": {},
3443-
"output_type": "execute_result"
3444-
}
3445-
],
3446-
"source": []
3447-
},
34483440
{
34493441
"cell_type": "code",
34503442
"execution_count": 317,
@@ -3487,7 +3479,7 @@
34873479
],
34883480
"source": [
34893481
"plt.plot(cat_cols, model.feature_importances_, linestyle='dashed', marker='o')\n",
3490-
"plt.xticks(rotation=90)"
3482+
"plt.xticks(rotation=90);"
34913483
]
34923484
},
34933485
{

scripts/tuning/run_smac.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from modcma import c_maes
2121

2222

23-
DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "data"))
23+
DATA_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "data_new"))
2424

2525

2626
def calc_aoc(problem: ioh.ProblemType, logger: ioh.logger.Store, budget: int) -> float:
@@ -150,7 +150,7 @@ def get_configspace(dim, use_learning_rates, add_popsize, add_sigma):
150150

151151
def run_smac(fid, dim, use_learning_rates, add_popsize, add_sigma, n_workers):
152152
print(f"Running SMAC with fid={fid}, lr={use_learning_rates} and d={dim}")
153-
cs = get_configspace(dim ,use_learning_rates, add_popsize, add_sigma)
153+
cs = get_configspace(dim, use_learning_rates, add_popsize, add_sigma)
154154
scenario = Scenario(
155155
cs,
156156
name=str(int(time.time())) + "-" + "CMA",
@@ -165,7 +165,7 @@ def run_smac(fid, dim, use_learning_rates, add_popsize, add_sigma, n_workers):
165165
eval_func = partial(get_bbob_performance, fid=fid, dim=dim)
166166
config_selector = ConfigSelector(
167167
scenario,
168-
retrain_after=250,
168+
retrain_after=100,
169169
min_trials=500,
170170
retries=16,
171171
)
@@ -183,7 +183,7 @@ def run_smac(fid, dim, use_learning_rates, add_popsize, add_sigma, n_workers):
183183
ratio_features=0.5,
184184
min_samples_split=10,
185185
min_samples_leaf=5,
186-
max_depth=10,
186+
max_depth=8,
187187
bootstrapping=True,
188188
pca_components=13
189189
),

scripts/tuning/smac_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ def plot_convergence(fid: int, dim:int, config_rt: dict[str, list[float]]):
5858
parser = ArgumentParser()
5959
parser.add_argument("--fid", default=1, type=int)
6060
parser.add_argument("--dim", default=5, type=int)
61-
parser.add_argument("--root", default="data", type=str)
61+
parser.add_argument("--root", default="data_new", type=str)
6262
parser.add_argument("--show_all_feasible", action="store_true")
6363
parser.add_argument("--all", action="store_true")
6464
parser.add_argument("--plot", action="store_true")
6565
args = parser.parse_args()
6666

6767
folders = os.listdir(args.root)
68-
arg_folder = f"BBOB_F{args.fid}_{args.dim}D_LRFalse"
68+
arg_folder = f"BBOB_F{args.fid}_{args.dim}D_LRFalseTrue"
6969

7070
for folder in sorted(os.listdir(args.root)):
7171
if not args.all and not folder.endswith(arg_folder): continue

scripts/tuning/test_config.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def get_ert(
7474

7575
suc += problem.state.final_target_found
7676
rt += problem.state.evaluations
77+
print(problem.state)
7778
problem.reset()
7879

7980
if suc == 0:
@@ -87,7 +88,21 @@ def get_ert(
8788
parser.add_argument("--reps", type=int, default=50)
8889
args = parser.parse_args()
8990
config = {
90-
'ssa': "PSR",
91+
'active': True,
92+
'elitist': True,
93+
'lambda0': 4,
94+
'matrix_adaptation': 'MATRIX',
95+
'mirrored': 'PAIRWISE',
96+
'mu0': 4,
97+
'orthogonal': True,
98+
'repelling_restart': True,
99+
'restart_strategy': 'NONE',
100+
'sample_transformation': 'LOGISTIC',
101+
'sampler': 'HALTON',
102+
'sequential_selection': True,
103+
'ssa': 'MXNES',
104+
'threshold_convergence': True,
105+
'weights': 'DEFAULT'
91106
}
92107

93108
settings = c_maes.settings_from_dict(5, **config)

0 commit comments

Comments
 (0)