Skip to content

Commit 909b346

Browse files
committed
pass objective-function instead of experiment
1 parent 3a33ba0 commit 909b346

1 file changed

Lines changed: 14 additions & 16 deletions

File tree

src/hyperactive/optimizers/_optimizer_api.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ def check_list(search_space):
4040
for key in search_space.keys():
4141
search_dim = search_space[key]
4242

43-
error_msg = "Value in '{}' of search space dictionary must be of type list".format(
44-
key
43+
error_msg = (
44+
"Value in '{}' of search space dictionary must be of type list".format(
45+
key
46+
)
4547
)
4648
if not isinstance(search_dim, list):
4749
print("Warning", error_msg)
@@ -93,9 +95,7 @@ def add_search(
9395
pass_through = pass_through or {}
9496
early_stopping = early_stopping or {}
9597

96-
search_id = self._default_search_id(
97-
search_id, experiment.objective_function
98-
)
98+
search_id = self._default_search_id(search_id, experiment.objective_function)
9999
s_space = SearchSpace(search_space)
100100
self.verbosity = verbosity
101101

@@ -135,12 +135,12 @@ def run(
135135
self.comp_opt = CompositeOptimizer(self)
136136
self.comp_opt.run(max_time, distribution, n_processes, self.verbosity)
137137

138-
def best_para(self, id_):
138+
def best_para(self, experiment):
139139
"""
140140
Retrieve the best parameters for a specific ID from the results.
141141
142142
Parameters:
143-
- id_ (int): The ID of the parameters to retrieve.
143+
- experiment (int): The experiment of the optimization run.
144144
145145
Returns:
146146
- Union[Dict[str, Union[int, float]], None]: The best parameters for the specified ID if found, otherwise None.
@@ -149,33 +149,31 @@ def best_para(self, id_):
149149
- ValueError: If the objective function name is not recognized.
150150
"""
151151

152-
return self.comp_opt.results_.best_para(id_)
152+
return self.comp_opt.results_.best_para(experiment.objective_function)
153153

154-
def best_score(self, id_):
154+
def best_score(self, experiment):
155155
"""
156156
Return the best score for a specific ID from the results.
157157
158158
Parameters:
159-
- id_ (int): The ID for which the best score is requested.
159+
- experiment (int): The experiment of the optimization run.
160160
"""
161161

162-
return self.comp_opt.results_.best_score(id_)
162+
return self.comp_opt.results_.best_score(experiment.objective_function)
163163

164-
def search_data(self, id_, times=False):
164+
def search_data(self, experiment, times=False):
165165
"""
166166
Retrieve search data for a specific ID from the results. Optionally exclude evaluation and iteration times if 'times' is set to False.
167167
168168
Parameters:
169-
- id_ (int): The ID of the search data to retrieve.
169+
- experiment (int): The experiment of the optimization run.
170170
- times (bool, optional): Whether to exclude evaluation and iteration times. Defaults to False.
171171
172172
Returns:
173173
- pd.DataFrame: The search data for the specified ID.
174174
"""
175175

176-
search_data_ = self.comp_opt.results_.search_data(
177-
id_.objective_function
178-
)
176+
search_data_ = self.comp_opt.results_.search_data(experiment.objective_function)
179177

180178
if times == False:
181179
search_data_.drop(

0 commit comments

Comments
 (0)