Skip to content

Commit e0aa92e

Browse files
last before 0.10
1 parent 16da920 commit e0aa92e

21 files changed

Lines changed: 465 additions & 273 deletions

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotPython"
10-
version = "0.9.20"
10+
version = "0.9.21"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/hyperparameters/values.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,26 +1056,31 @@ def get_control_key_value(control_dict=None, key=None) -> Any:
10561056
key="key")
10571057
"value"
10581058
"""
1059-
if key == "lower":
1060-
lower = get_bound_values(fun_control=control_dict, bound="lower")
1061-
return lower
1062-
if key == "upper":
1063-
upper = get_bound_values(fun_control=control_dict, bound="upper")
1064-
return upper
1065-
if key == "var_name":
1066-
var_name = get_var_name(fun_control=control_dict)
1067-
return var_name
1068-
if key == "var_type":
1069-
var_type = get_var_type(fun_control=control_dict)
1070-
return var_type
1071-
if key == "transform":
1072-
transform = get_transform(fun_control=control_dict)
1073-
return transform
1074-
# check if key exists in control_dict:
1075-
if control_dict is None or key not in control_dict.keys():
1059+
if control_dict is None:
10761060
return None
10771061
else:
1078-
return control_dict[key]
1062+
# check if key "core_model_hyper_dict" exists in fun_control:
1063+
if "core_model_hyper_dict" in control_dict.keys():
1064+
if key == "lower":
1065+
lower = get_bound_values(fun_control=control_dict, bound="lower")
1066+
return lower
1067+
if key == "upper":
1068+
upper = get_bound_values(fun_control=control_dict, bound="upper")
1069+
return upper
1070+
if key == "var_name":
1071+
var_name = get_var_name(fun_control=control_dict)
1072+
return var_name
1073+
if key == "var_type":
1074+
var_type = get_var_type(fun_control=control_dict)
1075+
return var_type
1076+
if key == "transform":
1077+
transform = get_transform(fun_control=control_dict)
1078+
return transform
1079+
# check if key exists in control_dict:
1080+
elif control_dict is None or key not in control_dict.keys():
1081+
return None
1082+
else:
1083+
return control_dict[key]
10791084

10801085

10811086
def get_var_type_from_var_name(fun_control, var_name) -> str:

src/spotPython/spot/spot.py

Lines changed: 76 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import pandas as pd
99
import pylab
1010
from scipy import optimize
11-
from scipy.optimize import differential_evolution
1211
from math import inf
1312
from math import isfinite
1413
import matplotlib.pyplot as plt
@@ -22,6 +21,7 @@
2221
from numpy import array
2322
from numpy import append
2423
from numpy import min, max
24+
from spotPython.utils.init import fun_control_init, optimizer_control_init, surrogate_control_init, design_control_init
2525
from spotPython.utils.compare import selectNew
2626
from spotPython.utils.aggregate import aggregate_mean_var
2727
from spotPython.utils.repair import remove_nan
@@ -36,7 +36,7 @@
3636
get_ith_hyperparameter_name_from_fun_control,
3737
)
3838
import plotly.graph_objects as go
39-
from typing import Union, Callable, Dict
39+
from typing import Callable
4040

4141

4242
logger = logging.getLogger(__name__)
@@ -196,32 +196,36 @@ def __str__(self):
196196

197197
def __init__(
198198
self,
199+
design: object = None,
200+
design_control: dict = design_control_init(),
199201
fun: Callable = None,
200-
lower: np.array = None,
201-
upper: np.array = None,
202+
fun_control: dict = fun_control_init(),
202203
fun_evals: int = 15,
203204
fun_repeats: int = 1,
204-
fun_control: dict = {},
205-
max_time: int = inf,
206-
noise: bool = False,
207-
tolerance_x: float = 0,
208-
var_type: list = ["num"],
209-
var_name: list = None,
210205
infill_criterion: str = "y",
206+
log_level: int = 50,
207+
lower: np.array = None,
208+
max_time: int = inf,
211209
n_points: int = 1,
210+
noise: bool = False,
211+
optimizer: object = None,
212+
optimizer_control: dict = optimizer_control_init(),
212213
ocba_delta: int = 0,
213214
seed: int = 123,
214-
sigma: float = 0.0,
215-
log_level: int = 50,
216215
show_models: bool = False,
217216
show_progress: bool = True,
218-
design: object = None,
219-
design_control: Dict[str, Union[int, float]] = {},
217+
sigma: float = 0.0,
220218
surrogate: object = None,
221-
surrogate_control: Dict[str, Union[int, float]] = {},
222-
optimizer: object = None,
223-
optimizer_control: Dict[str, Union[int, float]] = {},
219+
surrogate_control: dict = surrogate_control_init(),
220+
tolerance_x: float = 0,
221+
upper: np.array = None,
222+
var_name: list = None,
223+
var_type: list = ["num"],
224224
):
225+
self.design_control = design_control
226+
self.optimizer_control = optimizer_control
227+
self.surrogate_control = surrogate_control
228+
225229
# small value:
226230
self.eps = sqrt(spacing(1))
227231

@@ -234,6 +238,7 @@ def __init__(
234238
# 1. fun_control updates:
235239
# -----------------------
236240
self.fun_control = fun_control
241+
print(f"self.fun_control: {self.fun_control}")
237242

238243
# set fun_control["sigma"] to sigma if "sigma" is not in fun_control dictionary
239244
# If no fun_control is provided, the fun_control dictionary is initialized with the
@@ -254,49 +259,70 @@ def __init__(
254259
self.lower = get_control_key_value(control_dict=self.fun_control, key="lower")
255260
# Number of dimensions is based on lower
256261
self.k = self.lower.size
262+
print(f"self.k: {self.k}")
257263

258264
# 3. upper attribute updates:
259265
# -----------------------
260266
# if upper is in fun_control dictionary, use the value of the key "upper" as the upper bound
261267
# else use the upper bound upper
268+
print(f"fun_control['upper']: {fun_control['upper']}")
262269
self.upper = upper
263270
if get_control_key_value(control_dict=self.fun_control, key="upper") is not None:
264271
self.upper = get_control_key_value(control_dict=self.fun_control, key="upper")
265272

266273
# 4. var_type attribute updates:
267274
# -----------------------
268-
self.set_self_attribute("var_type", var_type, self.fun_control)
275+
# self.set_self_attribute("var_type", var_type, self.fun_control)
276+
self.var_type = self.fun_control["var_type"]
269277
# Force numeric type as default in every dim:
270278
# assume all variable types are "num" if "num" is
271279
# specified less than k times
280+
print(f"fun_control['var_type']: {fun_control['var_type']}")
272281
if len(self.var_type) < self.k:
273282
self.var_type = self.var_type * self.k
274283
logger.warning("All variable types forced to 'num'.")
275284

276285
# 5. var_name attribute updates:
277286
# -----------------------
278-
self.set_self_attribute("var_name", var_name, self.fun_control)
287+
# self.set_self_attribute("var_name", var_name, self.fun_control)
288+
self.var_name = self.fun_control["var_name"]
279289
# use x0, x1, ... as default variable names:
280290
if self.var_name is None:
281291
self.var_name = ["x" + str(i) for i in range(len(self.lower))]
282292

283293
# Reduce dim based on lower == upper logic:
284294
# modifies lower, upper, var_type, and var_name
295+
296+
print(f"self.lower: {self.lower}")
297+
print(f"self.upper: {self.upper}")
298+
print(f"self.var_type: {self.var_type}")
285299
self.to_red_dim()
286300

287301
# 6. Additional self attributes updates:
288302
# -----------------------
289-
self.set_self_attribute("fun_evals", fun_evals, self.fun_control)
290-
self.set_self_attribute("fun_repeats", fun_repeats, self.fun_control)
291-
self.set_self_attribute("max_time", max_time, self.fun_control)
292-
self.set_self_attribute("noise", noise, self.fun_control)
293-
self.set_self_attribute("tolerance_x", tolerance_x, self.fun_control)
294-
self.set_self_attribute("ocba_delta", ocba_delta, self.fun_control)
295-
self.set_self_attribute("log_level", log_level, self.fun_control)
296-
self.set_self_attribute("show_models", show_models, self.fun_control)
297-
self.set_self_attribute("show_progress", show_progress, self.fun_control)
298-
self.set_self_attribute("infill_criterion", infill_criterion, self.fun_control)
299-
self.set_self_attribute("n_points", n_points, self.fun_control)
303+
self.fun_evals = self.fun_control["fun_evals"]
304+
self.fun_repeats = self.fun_control["fun_repeats"]
305+
self.max_time = self.fun_control["max_time"]
306+
self.noise = self.fun_control["noise"]
307+
self.tolerance_x = self.fun_control["tolerance_x"]
308+
self.ocba_delta = self.fun_control["ocba_delta"]
309+
self.log_level = self.fun_control["log_level"]
310+
self.show_models = self.fun_control["show_models"]
311+
self.show_progress = self.fun_control["show_progress"]
312+
self.infill_criterion = self.fun_control["infill_criterion"]
313+
self.n_points = self.fun_control["n_points"]
314+
315+
# self.set_self_attribute("fun_evals", fun_evals, self.fun_control)
316+
# self.set_self_attribute("fun_repeats", fun_repeats, self.fun_control)
317+
# self.set_self_attribute("max_time", max_time, self.fun_control)
318+
# self.set_self_attribute("noise", noise, self.fun_control)
319+
# self.set_self_attribute("tolerance_x", tolerance_x, self.fun_control)
320+
# self.set_self_attribute("ocba_delta", ocba_delta, self.fun_control)
321+
# self.set_self_attribute("log_level", log_level, self.fun_control)
322+
# self.set_self_attribute("show_models", show_models, self.fun_control)
323+
# self.set_self_attribute("show_progress", show_progress, self.fun_control)
324+
# self.set_self_attribute("infill_criterion", infill_criterion, self.fun_control)
325+
# self.set_self_attribute("n_points", n_points, self.fun_control)
300326

301327
# if the key "spot_writer" is not in the dictionary fun_control,
302328
# set self.spot_writer to None else to the value of the key "spot_writer"
@@ -313,25 +339,27 @@ def __init__(
313339
self.design = design
314340
if design is None:
315341
self.design = spacefilling(k=self.lower.size, seed=self.fun_control["seed"])
316-
self.design_control = {"init_size": 10, "repeats": 1}
317-
self.design_control.update(design_control)
342+
# self.design_control = {"init_size": 10, "repeats": 1}
343+
# self.design_control.update(design_control)
318344

319345
# Surrogate related information:
320346
self.surrogate = surrogate
321-
self.surrogate_control = {
322-
"noise": self.noise,
323-
"model_optimizer": differential_evolution,
324-
"model_fun_evals": None,
325-
"min_theta": -3.0,
326-
"max_theta": 3.0,
327-
"n_theta": 1,
328-
"theta_init_zero": True,
329-
"n_p": 1,
330-
"optim_p": False,
331-
"var_type": self.var_type,
332-
"seed": 124,
333-
}
334-
self.surrogate_control.update(surrogate_control)
347+
self.surrogate_control.update({"var_type": self.var_type})
348+
349+
# self.surrogate_control = {
350+
# "noise": self.noise,
351+
# "model_optimizer": differential_evolution,
352+
# "model_fun_evals": None,
353+
# "min_theta": -3.0,
354+
# "max_theta": 3.0,
355+
# "n_theta": 1,
356+
# "theta_init_zero": True,
357+
# "n_p": 1,
358+
# "optim_p": False,
359+
# "var_type": self.var_type,
360+
# "seed": 124,
361+
# }
362+
# self.surrogate_control.update(surrogate_control)
335363

336364
# If self.surrogate_control["n_theta"] > 1, use k theta values:
337365
if self.surrogate_control["n_theta"] > 1:
@@ -363,8 +391,8 @@ def __init__(
363391

364392
# Optimizer related information:
365393
self.optimizer = optimizer
366-
self.optimizer_control = {"max_iter": 1000, "seed": 125}
367-
self.optimizer_control.update(optimizer_control)
394+
# self.optimizer_control = {"max_iter": 1000, "seed": 125}
395+
# self.optimizer_control.update(optimizer_control)
368396
if self.optimizer is None:
369397
self.optimizer = optimize.differential_evolution
370398

0 commit comments

Comments
 (0)