Skip to content

Commit bd278eb

Browse files
0.9.5
cleanup main
1 parent 6ab567d commit bd278eb

2 files changed

Lines changed: 39 additions & 26 deletions

File tree

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.4"
10+
version = "0.9.5"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotPython/spot/spot.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,14 @@ class Spot:
5959
* Displaying information. The `plot` method can be used for visualizing results. The `print` methods summarizes
6060
information about the tuning run.
6161
62-
The `Spot` class is built in a modular manner. It combines the following three components:
62+
The `Spot` class is built in a modular manner. It combines the following components:
6363
6464
1. Design
6565
2. Surrogate
66-
3. Fun (Evaluation of the objective function)
66+
3. Fun (objective function)
67+
4. Optimizer
6768
68-
For each of the three components different implementations can be selected and combined.
69+
For each of the components different implementations can be selected and combined.
6970
Internal components are selected as default.
7071
These can be replaced by components from other packages, e.g., scikit-learn or scikit-optimize.
7172
@@ -221,6 +222,9 @@ def __init__(
221222
optimizer: object = None,
222223
optimizer_control: Dict[str, Union[int, float]] = {},
223224
):
225+
# small value:
226+
self.eps = sqrt(spacing(1))
227+
224228
self.fun = fun
225229
if self.fun is None:
226230
raise Exception("No objective function specified.")
@@ -238,8 +242,10 @@ def __init__(
238242
# objective functions from the spotPython.fun.objectivefunctions module.
239243
set_fun_control_key_value(fun_control=self.fun_control, key="sigma", value=sigma)
240244
set_fun_control_key_value(fun_control=self.fun_control, key="seed", value=seed)
245+
# Random number generator:
246+
self.rng = default_rng(self.fun_control["seed"])
241247

242-
# 2. self attributes updates:
248+
# 2. lower attribute updates:
243249
# -----------------------
244250
# if lower is in the fun_control dictionary, use the value of the key "lower" as the lower bound
245251
# else use the lower bound lower
@@ -249,12 +255,16 @@ def __init__(
249255
# Number of dimensions is based on lower
250256
self.k = self.lower.size
251257

258+
# 3. upper attribute updates:
259+
# -----------------------
252260
# if upper is in fun_control dictionary, use the value of the key "upper" as the upper bound
253261
# else use the upper bound upper
254262
self.upper = upper
255263
if get_bound_values(self.fun_control, "upper") is not None:
256264
self.upper = get_bound_values(self.fun_control, "upper")
257265

266+
# 4. var_type attribute updates:
267+
# -----------------------
258268
self.set_self_attribute("var_type", var_type, self.fun_control)
259269
# Force numeric type as default in every dim:
260270
# assume all variable types are "num" if "num" is
@@ -263,6 +273,8 @@ def __init__(
263273
self.var_type = self.var_type * self.k
264274
logger.warning("All variable types forced to 'num'.")
265275

276+
# 5. var_name attribute updates:
277+
# -----------------------
266278
self.set_self_attribute("var_name", var_name, self.fun_control)
267279
# use x0, x1, ... as default variable names:
268280
if self.var_name is None:
@@ -272,6 +284,8 @@ def __init__(
272284
# modifies lower, upper, var_type, and var_name
273285
self.to_red_dim()
274286

287+
# 6. Additional self attributes updates:
288+
# -----------------------
275289
self.set_self_attribute("fun_evals", fun_evals, self.fun_control)
276290
self.set_self_attribute("fun_repeats", fun_repeats, self.fun_control)
277291
self.set_self_attribute("max_time", max_time, self.fun_control)
@@ -284,8 +298,9 @@ def __init__(
284298
self.set_self_attribute("infill_criterion", infill_criterion, self.fun_control)
285299
self.set_self_attribute("n_points", n_points, self.fun_control)
286300

287-
# Random number generator:
288-
self.rng = default_rng(self.fun_control["seed"])
301+
# if the key "spot_writer" is not in the dictionary fun_control,
302+
# set self.spot_writer to None else to the value of the key "spot_writer"
303+
self.spot_writer = self.fun_control.get("spot_writer", None)
289304

290305
# Bounds are internal, because they are functions of self.lower and self.upper
291306
# and used by the optimizer:
@@ -316,25 +331,6 @@ def __init__(
316331
"var_type": self.var_type,
317332
"seed": 124,
318333
}
319-
self.X = None
320-
self.y = None
321-
# small value:
322-
self.eps = sqrt(spacing(1))
323-
# Logging information:
324-
self.counter = 0
325-
self.min_y = None
326-
self.min_X = None
327-
self.min_mean_X = None
328-
self.min_mean_y = None
329-
self.mean_X = None
330-
self.mean_y = None
331-
self.var_y = None
332-
logger.setLevel(self.log_level)
333-
logger.info(f"Starting the logger at level {self.log_level} for module {__name__}:")
334-
335-
# if the key "spot_writer" is not in the dictionary fun_control,
336-
# set self.spot_writer to None else to the value of the key "spot_writer"
337-
self.spot_writer = self.fun_control.get("spot_writer", None)
338334
self.surrogate_control.update(surrogate_control)
339335
# If no surrogate model is specified, use the internal
340336
# spotPython kriging surrogate:
@@ -357,12 +353,29 @@ def __init__(
357353
spot_writer=self.spot_writer,
358354
counter=self.design_control["init_size"] * self.design_control["repeats"] - 1,
359355
)
356+
360357
# Optimizer related information:
361358
self.optimizer = optimizer
362359
self.optimizer_control = {"max_iter": 1000, "seed": 125}
363360
self.optimizer_control.update(optimizer_control)
364361
if self.optimizer is None:
365362
self.optimizer = optimize.differential_evolution
363+
364+
# Internal attributes:
365+
self.X = None
366+
self.y = None
367+
# Logging information:
368+
self.counter = 0
369+
self.min_y = None
370+
self.min_X = None
371+
self.min_mean_X = None
372+
self.min_mean_y = None
373+
self.mean_X = None
374+
self.mean_y = None
375+
self.var_y = None
376+
377+
logger.setLevel(self.log_level)
378+
logger.info(f"Starting the logger at level {self.log_level} for module {__name__}:")
366379
logger.debug("In Spot() init(): fun_control: %s", self.fun_control)
367380
logger.debug("In Spot() init(): optimizer_control: %s", self.optimizer_control)
368381
logger.debug("In Spot() init(): surrogate_control: %s", self.surrogate_control)

0 commit comments

Comments
 (0)