|
17 | 17 | from spotpython.surrogate.kriging import Kriging |
18 | 18 | from spotpython.utils.repair import apply_penalty_NA |
19 | 19 | from spotpython.utils.seed import set_all_seeds |
| 20 | +from spotpython.utils.sampling import propose_mmphi_intensive_minimizing_point |
20 | 21 | import numpy as np |
21 | 22 | import pandas as pd |
22 | 23 | import pylab |
@@ -367,9 +368,11 @@ def _set_additional_attributes(self) -> None: |
367 | 368 | self.n_points = self.fun_control["n_points"] |
368 | 369 | self.progress_file = self.fun_control["progress_file"] |
369 | 370 | self.tkagg = self.fun_control["tkagg"] |
| 371 | + # self.success_counter = 0 |
370 | 372 | if self.tkagg: |
371 | 373 | matplotlib.use("TkAgg") |
372 | 374 | self.verbosity = self.fun_control["verbosity"] |
| 375 | + self.acquisition_failure_strategy = self.fun_control["acquisition_failure_strategy"] |
373 | 376 | self.max_surrogate_points = self.surrogate_control["max_surrogate_points"] |
374 | 377 | self.use_nystrom = self.surrogate_control["use_nystrom"] |
375 | 378 | self.nystrom_m = self.surrogate_control["nystrom_m"] |
@@ -870,8 +873,18 @@ def get_new_X0(self) -> np.array: |
870 | 873 | return repeat(X0, self.fun_repeats, axis=0) |
871 | 874 | # If no X0 found, then generate self.n_points new solutions: |
872 | 875 | else: |
873 | | - self.design = SpaceFilling(k=self.k, seed=self.fun_control["seed"] + self.counter) |
874 | | - X0 = self.generate_design(size=self.n_points, repeats=self.design_control["repeats"], lower=self.lower, upper=self.upper) |
| 876 | + # No new X0 found on surrogate: |
| 877 | + # use morris-mitchell ("mm") or random design as fallback |
| 878 | + if self.acquisition_failure_strategy == "mm": |
| 879 | + X0 = propose_mmphi_intensive_minimizing_point(X=self.X, n_candidates=1000, q=2, p=2, seed=1, lower=self.lower, upper=self.upper) |
| 880 | + # ensure that X0 is repeated according to repeats=self.design_control["repeats"] |
| 881 | + X0 = repeat(X0, self.design_control["repeats"], axis=0) |
| 882 | + print("Using mmphi minimizing point as fallback.") |
| 883 | + else: |
| 884 | + # fallback to spacefilling design (acquisition_failure_strategy == "random"): |
| 885 | + self.design = SpaceFilling(k=self.k, seed=self.fun_control["seed"] + self.counter) |
| 886 | + X0 = self.generate_design(size=self.n_points, repeats=self.design_control["repeats"], lower=self.lower, upper=self.upper) |
| 887 | + print("Using spacefilling design as fallback.") |
875 | 888 | X0 = repair_non_numeric(X0, self.var_type) |
876 | 889 | logger.warning("No new XO found on surrogate. Generate new solution %s", X0) |
877 | 890 | return X0 |
@@ -1578,6 +1591,19 @@ def update_design(self) -> None: |
1578 | 1591 | # Apply penalty for NA values works only on so values: |
1579 | 1592 | y0 = apply_penalty_NA(y0, self.fun_control["penalty_NA"], verbosity=self.verbosity) |
1580 | 1593 | X0, y0 = remove_nan(X0, y0, stop_on_zero_return=False) |
| 1594 | + # check if the new y0 value is smaller that the min of the self.y values so far and |
| 1595 | + # in this case increase the success_counter. Calculate the success rate, which is defined as |
| 1596 | + # the number of successful improvements divided by the total number of function evaluations over |
| 1597 | + # the last window_size evaluations: |
| 1598 | + # self.success_window_size = 10 |
| 1599 | + # if y0.shape[0] > 0: |
| 1600 | + # for y_val in y0: |
| 1601 | + # if y_val < self.min_y: |
| 1602 | + # self.success_counter += 1 |
| 1603 | + # total_evaluations = self.counter + y0.shape[0] |
| 1604 | + # window_size = min(total_evaluations, self.success_window_size) |
| 1605 | + # self.success_rate = self.success_counter / window_size |
| 1606 | + # print(f"Success rate over the last {window_size} evaluations: {self.success_rate:.4f}") |
1581 | 1607 | # Append New Solutions (only if they are not nan): |
1582 | 1608 | if y0.shape[0] > 0: |
1583 | 1609 | self.X = np.append(self.X, X0, axis=0) |
|
0 commit comments