Skip to content

Commit 67d47c5

Browse files
v0.5.16
logging for noise
1 parent b699c20 commit 67d47c5

2 files changed

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

src/spotPython/spot/spot.py

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ def update_stats(self):
436436
437437
"""
438438
self.min_y = min(self.y)
439-
# get the last y value:
440-
self.last_y = self.y[-1]
441439
self.min_X = self.X[argmin(self.y)]
442440
self.counter = self.y.size
443441
# Update aggregated x and y values (if noise):
@@ -446,43 +444,52 @@ def update_stats(self):
446444
self.mean_X = Z[0]
447445
self.mean_y = Z[1]
448446
self.var_y = Z[2]
449-
self.min_mean_y = min(self.mean_y)
447+
# X value of the best mean y value so far:
450448
self.min_mean_X = self.mean_X[argmin(self.mean_y)]
449+
# variance of the best mean y value so far:
450+
self.min_var_y = self.var_y[argmin(self.mean_y)]
451+
# best mean y value so far:
452+
self.min_mean_y = self.mean_y[argmin(self.mean_y)]
451453

452454
def update_writer(self):
453455
if self.spot_writer is not None:
454456
writer = self.spot_writer
455-
y_min = self.min_y.copy()
456-
y_last = self.last_y.copy()
457-
X_min = self.min_X.copy()
458-
# y_min: best y value so far
459-
# y_last: last y value, can he worse than y_min
460-
writer.add_scalars("spot_y", {"min": y_min, "last": y_last}, self.counter)
461-
# X_min: X value of the best y value so far
462-
writer.add_scalars("spot_X", {f"X_{i}": X_min[i] for i in range(self.k)}, self.counter)
463-
# get last value of self.X and convert to dict. take the values from self.var_name as keys:
464-
X_last = self.X[-1].copy()
465-
config = {self.var_name[i]: X_last[i] for i in range(self.k)}
466-
# hyperparameters X and value y of the last configuration:
467-
writer.add_hparams(config, {"spot_y": y_last})
468-
writer.flush()
469-
if self.noise:
470-
writer = self.spot_writer
457+
# get the last y value:
458+
y_last = self.y[-1].copy()
459+
if self.noise is False:
460+
y_min = self.min_y.copy()
461+
X_min = self.min_X.copy()
462+
# y_min: best y value so far
463+
# y_last: last y value, can be worse than y_min
464+
writer.add_scalars("spot_y", {"min": y_min, "last": y_last}, self.counter)
465+
# X_min: X value of the best y value so far
466+
writer.add_scalars("spot_X", {f"X_{i}": X_min[i] for i in range(self.k)}, self.counter)
467+
else:
468+
# get the last n y values:
469+
y_last_n = self.y[-self.fun_repeats :].copy()
471470
# y_min_mean: best mean y value so far
472471
y_min_mean = self.min_mean_y.copy()
473472
# X_min_mean: X value of the best mean y value so far
474473
X_min_mean = self.min_mean_X.copy()
475-
# y_var: variance of the y values
476-
y_var = self.var_y.copy()
477-
writer.add_scalar("spot_y_var", y_var, self.counter)
474+
# y_min_var: variance of the min y value so far
475+
y_min_var = self.min_var_y.copy()
476+
writer.add_scalar("spot_y_min_var", y_min_var, self.counter)
478477
# y_min_mean: best mean y value so far (see above)
479-
# y_last: last y value, can he worse than y_min_mean
480-
writer.add_scalars("spot_y_noise", {"min_mean_y": y_min_mean, "last": y_last}, self.counter)
478+
writer.add_scalar("spot_y", y_min_mean, self.counter)
479+
# last n y values (noisy):
480+
writer.add_scalars(
481+
"spot_y", {f"y_last_n{i}": y_last_n[i] for i in range(self.fun_repeats)}, self.counter
482+
)
481483
# X_min_mean: X value of the best mean y value so far (see above)
482484
writer.add_scalars(
483485
"spot_X_noise", {f"X_min_mean{i}": X_min_mean[i] for i in range(self.k)}, self.counter
484486
)
485-
writer.flush()
487+
# get last value of self.X and convert to dict. take the values from self.var_name as keys:
488+
X_last = self.X[-1].copy()
489+
config = {self.var_name[i]: X_last[i] for i in range(self.k)}
490+
# hyperparameters X and value y of the last configuration:
491+
writer.add_hparams(config, {"spot_y": y_last})
492+
writer.flush()
486493

487494
def suggest_new_X_old(self):
488495
"""

0 commit comments

Comments
 (0)