Skip to content

Commit 1622bdf

Browse files
0.24.17
1 parent 5586460 commit 1622bdf

4 files changed

Lines changed: 15 additions & 11 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.24.16"
10+
version = "0.24.17"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

src/spotpython/spot/spot.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def __init__(
233233

234234
# The writer (Tensorboard) must be initialized before the surrogate model,
235235
# because the writer is passed to the surrogate model:
236-
self.init_spot_writer()
236+
self._init_spot_writer()
237237

238238
self._surrogate_setup(surrogate)
239239

@@ -862,6 +862,8 @@ def run(self, X_start: np.ndarray = None) -> Spot:
862862
self.initialize_design(X_start)
863863
self.update_stats()
864864
self.fit_surrogate()
865+
if self.verbosity > 0:
866+
print("\n------ Starting optimization on the Surrogate for the given Budget ------\n")
865867
timeout_start = time.time()
866868
while self.should_continue(timeout_start):
867869
self.update_design()
@@ -1083,7 +1085,7 @@ def evaluate_initial_design(self) -> None:
10831085
logger.debug("In Spot() evaluate_initial_design(), before calling self.fun: fun_control: %s", self.fun_control)
10841086

10851087
self.y = self.fun(X=X_all, fun_control=self.fun_control)
1086-
self.y = apply_penalty_NA(self.y, self.fun_control["penalty_NA"])
1088+
self.y = apply_penalty_NA(self.y, self.fun_control["penalty_NA"], verbosity=self.verbosity)
10871089
logger.debug("In Spot() evaluate_initial_design(), after calling self.fun: self.y: %s", self.y)
10881090

10891091
# TODO: Error if only nan values are returned
@@ -1410,7 +1412,7 @@ def update_design(self) -> None:
14101412
)
14111413
# (S-18): Evaluating New Solutions:
14121414
y0 = self.fun(X=X_all, fun_control=self.fun_control)
1413-
y0 = apply_penalty_NA(y0, self.fun_control["penalty_NA"])
1415+
y0 = apply_penalty_NA(y0, self.fun_control["penalty_NA"], verbosity=self.verbosity)
14141416
X0, y0 = remove_nan(X0, y0, stop_on_zero_return=False)
14151417
# Append New Solutions (only if they are not nan):
14161418
if y0.shape[0] > 0:
@@ -1580,7 +1582,7 @@ def _get_pickle_safe_spot_tuner(self, unpickleables="file_io", verbosity=0) -> S
15801582

15811583
return picklable_instance
15821584

1583-
def init_spot_writer(self) -> None:
1585+
def _init_spot_writer(self) -> None:
15841586
"""
15851587
Initialize the spot_writer for the current experiment if in fun_control
15861588
the tensorboard_log is set to True
@@ -1590,7 +1592,7 @@ def init_spot_writer(self) -> None:
15901592
if self.fun_control["tensorboard_log"] and self.fun_control["spot_tensorboard_path"] is not None:
15911593
self.spot_writer = SummaryWriter(log_dir=self.fun_control["spot_tensorboard_path"])
15921594
if self.verbosity > 0:
1593-
print(f"Created spot_tensorboard_path: {self.fun_control['spot_tensorboard_path']} for SummaryWriter()")
1595+
print(f"_init_spot_writer(): Created spot_tensorboard_path: {self.fun_control['spot_tensorboard_path']} for SummaryWriter()")
15941596
else:
15951597
self.spot_writer = None
15961598
if self.verbosity > 0:
@@ -1643,7 +1645,7 @@ def generate_random_point(self):
16431645
logger.debug("In Spot() generate_random_point(), before calling self.fun: X_all: %s", X_all)
16441646
logger.debug("In Spot() generate_random_point(), before calling self.fun: fun_control: %s", self.fun_control)
16451647
y0 = self.fun(X=X_all, fun_control=self.fun_control)
1646-
y0 = apply_penalty_NA(y0, self.fun_control["penalty_NA"])
1648+
y0 = apply_penalty_NA(y0, self.fun_control["penalty_NA"], verbosity=self.verbosity)
16471649
X0, y0 = remove_nan(X0, y0, stop_on_zero_return=False)
16481650
return X0, y0
16491651

@@ -1978,7 +1980,7 @@ def plot_model(self, y_min=None, y_max=None) -> None:
19781980
if self.k == 1:
19791981
X_test = np.linspace(self.lower[0], self.upper[0], 100)
19801982
y_test = self.fun(X=X_test.reshape(-1, 1), fun_control=self.fun_control)
1981-
y_test = apply_penalty_NA(y_test, self.fun_control["penalty_NA"])
1983+
y_test = apply_penalty_NA(y_test, self.fun_control["penalty_NA"], verbosity=self.verbosity)
19821984
if isinstance(self.surrogate, Kriging):
19831985
y_hat = self.surrogate.predict(X_test[:, np.newaxis], return_val="y")
19841986
else:

src/spotpython/utils/init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def fun_control_init(
7474
prep_model=None,
7575
prep_model_name=None,
7676
progress_file=None,
77-
save_experiment=True,
77+
save_experiment=False,
7878
save_result=True,
7979
scaler=None,
8080
scaler_name=None,

src/spotpython/utils/repair.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def remove_nan(X: np.ndarray, y: np.ndarray, stop_on_zero_return: bool = False)
7878
return X_cleaned, y_cleaned
7979

8080

81-
def apply_penalty_NA(y: np.ndarray, penalty_NA: float, sd=0.1, stop_on_zero_return: bool = False) -> np.ndarray:
81+
def apply_penalty_NA(y: np.ndarray, penalty_NA: float, sd=0.1, stop_on_zero_return: bool = False, verbosity=0) -> np.ndarray:
8282
"""
8383
Replaces NaN values in y with a penalty value of penalty_NA and issues a warning if necessary.
8484
@@ -87,6 +87,7 @@ def apply_penalty_NA(y: np.ndarray, penalty_NA: float, sd=0.1, stop_on_zero_retu
8787
penalty_NA (float): penalty value to replace NaN values in y
8888
sd (float): standard deviation for the random noise added to penalty_NA. Default is 0.1.
8989
stop_on_zero_return (bool): whether to stop if the returned dimension is less than 1. Default is False.
90+
verbosity (int): verbosity level. Default is 0.
9091
9192
Returns:
9293
numpy.ndarray: y array with NaN values replaced by penalty value
@@ -124,8 +125,9 @@ def apply_penalty_NA(y: np.ndarray, penalty_NA: float, sd=0.1, stop_on_zero_retu
124125
if nan_dim > 1:
125126
warnings.warn(f"\n!!! The dimension of the returned y array is {y_cleaned.shape[0]}, " f"which is smaller than the original dimension {original_dim}.")
126127
warnings.warn("\n!!! Check whether continuing with the reduced dimension is useful.")
128+
if verbosity > 0:
129+
print(f"y before penalty: {y}. y after penalty: {y_cleaned}")
127130

128131
if (original_dim - nan_dim) < 1 and stop_on_zero_return:
129132
raise ValueError("!!!! The dimension of the returned y array is less than 1. Check the input data.")
130-
131133
return y_cleaned

0 commit comments

Comments
 (0)