99import ioh
1010import numpy as np
1111
12- from smac import Scenario ,AlgorithmConfigurationFacade
12+ from smac import Scenario , AlgorithmConfigurationFacade
13+ from smac .acquisition .maximizer import (
14+ LocalAndSortedRandomSearch ,
15+ )
1316from smac .main .config_selector import ConfigSelector
1417from ConfigSpace import Configuration , ConfigurationSpace
1518from ConfigSpace .hyperparameters import CategoricalHyperparameter
2023DATA_DIR = os .path .abspath (os .path .join (os .path .dirname (__file__ ), "data" ))
2124
2225
23- def calc_aoc (logger : ioh .logger .Store , budget : int , fid : int , iid : int , dim : int ) -> float :
26+ def calc_aoc (problem : ioh .ProblemType , logger : ioh .logger .Store , budget : int ) -> float :
27+ """
28+ Compute the Area Over the Curve (AOC) for an optimization run.
29+
30+ The AOC summarizes optimization performance over time by averaging
31+ the log-scaled best-so-far objective values across a fixed evaluation
32+ budget. Lower values indicate better and faster convergence.
33+
34+ Steps:
35+ - Extract best-so-far objective values ("raw_y_best") from the logger.
36+ - Replace NaNs with a large penalty value (1e8).
37+ - Pad the trajectory to the full budget using the best observed value.
38+ - Clip values to [1e-8, 1e2] and apply log10 scaling.
39+ - Shift values to [0, 10] and normalize to [0, 1].
40+ - Return the mean over the budget (the AOC score).
41+
42+ Parameters
43+ ----------
44+ problem : ioh.ProblemType
45+ The evaluated problem
46+ logger : ioh.logger.Store
47+ IOH logger containing experiment data.
48+ budget : int
49+ Maximum number of function evaluations to consider.
50+ Returns
51+ -------
52+ float
53+ AOC score in [0, 1], where lower values indicate better performance.
54+ """
55+
2456 data = logger .data ()
25- data1 = data ['None' ][fid ][ dim ][ iid ][0 ]
57+ data1 = data ['None' ][problem . meta_data . problem_id ][ problem . meta_data . n_variables ][ problem . meta_data . instance ][0 ]
2658 fvals = [x ['raw_y_best' ] for x in data1 .values ()]
2759 fvals = np .array (fvals )
2860 if np .isnan (fvals ).any ():
@@ -43,7 +75,7 @@ def get_bbob_performance(
4375
4476 problem = ioh .get_problem (fid , iid , dim )
4577 logger = ioh .logger .Store (
46- triggers = [ioh .logger .trigger .ON_IMPROVEMENT ],
78+ triggers = [ioh .logger .trigger .ALWAYS ],
4779 properties = [ioh .logger .property .RAWYBEST ]
4880 )
4981 problem .attach_logger (logger )
@@ -55,17 +87,30 @@ def get_bbob_performance(
5587 ub = problem .bounds .ub ,
5688 lb = problem .bounds .lb
5789 )
90+ settings .modules .center_placement = c_maes .options .CenterPlacement .UNIFORM
5891 par = c_maes .Parameters (settings )
5992
6093 try :
6194 cma = c_maes .ModularCMAES (par )
6295 cma .run (problem )
96+ aoc = calc_aoc (problem , logger , BUDGET )
6397 except Exception as e :
6498 print (
6599 f"Found target { problem .state .current_best .y } target, but exception ({ e } ), so run failed"
66100 )
67- return np .inf
68- return calc_aoc (problem , logger , BUDGET )
101+ aoc = np .inf
102+
103+ extra = {
104+ "fid" : fid ,
105+ "iid" : iid ,
106+ "dim" : dim ,
107+ "target" : float (problem .optimum .y + 9e-9 ),
108+ "final_y" : float (problem .state .current_best .y ),
109+ "evals" : int (problem .state .evaluations ),
110+ "hit_target" : bool (problem .state .current_best .y <= problem .optimum .y + 9e-9 ),
111+ "precision" : float (abs (problem .state .current_best .y - problem .optimum .y )),
112+ }
113+ return aoc , extra
69114
70115def make_new (hp : CategoricalHyperparameter , filter : list [str ]):
71116 new_choices = [c for c in hp .choices if c not in filter ]
@@ -117,8 +162,8 @@ def run_smac(fid, dim, use_learning_rates, add_popsize, add_sigma, n_workers):
117162 eval_func = partial (get_bbob_performance , fid = fid , dim = dim )
118163 config_selector = ConfigSelector (
119164 scenario ,
120- retrain_after = 500 ,
121- min_trials = 1000 ,
165+ retrain_after = 250 ,
166+ min_trials = 500 ,
122167 retries = 16 ,
123168 )
124169
@@ -127,7 +172,23 @@ def run_smac(fid, dim, use_learning_rates, add_popsize, add_sigma, n_workers):
127172 intensifier = AlgorithmConfigurationFacade .get_intensifier (
128173 scenario , max_config_calls = 25
129174 ),
130- config_selector = config_selector
175+ config_selector = config_selector ,
176+ initial_design = AlgorithmConfigurationFacade .get_initial_design (scenario ),
177+ model = AlgorithmConfigurationFacade .get_model (
178+ scenario ,
179+ n_trees = 5 ,
180+ ratio_features = 0.5 ,
181+ min_samples_split = 10 ,
182+ min_samples_leaf = 5 ,
183+ max_depth = 10 ,
184+ bootstrapping = True ,
185+ pca_components = 13
186+ ),
187+ acquisition_maximizer = LocalAndSortedRandomSearch (
188+ scenario .configspace ,
189+ seed = scenario .seed ,
190+ challengers = 500
191+ )
131192 )
132193 smac .optimize ()
133194
0 commit comments