Skip to content

Commit

Permalink
Merge pull request #290 from novonordisk-research/fix_warnings_same_p…
Browse files Browse the repository at this point in the history
…oint_and_in1d

Fix warnings for optimizer at old point and dep warning for in1d
  • Loading branch information
RuneChristensen-NN authored Nov 21, 2024
2 parents 4389923 + dbd0b48 commit baa67f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ProcessOptimizer/learning/gbrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def predict(self, X, return_std=False, return_quantiles=False):

elif return_std:
std_quantiles = [0.16, 0.5, 0.84]
is_present_mask = np.in1d(std_quantiles, self.quantiles)
is_present_mask = np.isin(std_quantiles, self.quantiles)
if not np.all(is_present_mask):
raise ValueError(
"return_std works only if the quantiles during "
Expand Down
20 changes: 11 additions & 9 deletions ProcessOptimizer/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def ask(self, n_points=None, strategy="stbr_fill"):
if not ((isinstance(n_points, int) and n_points > 0) or n_points is None):
raise ValueError("n_points should be int > 0, got " + str(n_points))
# These are the only filling strategies which are supported

if strategy == "stbr_full" and self._n_initial_points < 1:
# Steienerberger sampling can not be used from an empty Xi set
if self.Xi == []:
Expand All @@ -446,13 +446,13 @@ def ask(self, n_points=None, strategy="stbr_fill"):
# Returns 'n_points' Steinerberger points
X = self.stbr_scipy(n_points=n_points)
return X

if n_points is None or n_points == 1:
return self._ask()

# The following assertions deal with cases in which the user asks for more than
# single experiments

supported_strategies = [
"cl_min",
"cl_mean",
Expand All @@ -469,7 +469,7 @@ def ask(self, n_points=None, strategy="stbr_fill"):
+ ", "
+ "got %s" % strategy
)

if strategy in ["stbr_fill", "stbr_full"] and self.get_constraints() is not None:
raise ValueError(
"Steinerberger (default setting) sampling can not be used with constraints,\
Expand Down Expand Up @@ -599,7 +599,9 @@ def _ask(self):

if abs(min_delta_x) <= 1e-8:
warnings.warn(
"The objective has been evaluated " "at this point before."
"FYI: The optimizer already has information about the "
"objective at this point. This can e.g., occur when the "
"optimizer assesses noise and uncertainty."
)

# return point computed from last call to tell()
Expand Down Expand Up @@ -1015,19 +1017,19 @@ def set_constraints(self, constraints):
* `constraints` [list] or [Constraints]:
Can either be a list of Constraint objects or a Constraints object
"""

if self.n_objectives > 1:
raise RuntimeError(
"Can't set constraints for multiobjective optimization. The NSGA-II algorithm \
used for multiobjective optimization does not support constraints."
)

if self._n_initial_points > 0 and self._lhs:
raise RuntimeError(
"Can't set constraints while latin hypercube sampling points are not exhausted.\
Consider reinitialising the optimizer with lhs=False as argument."
)

if constraints:
if isinstance(constraints, Constraints):
# If constraints is a Constraints object we simply add it
Expand Down

0 comments on commit baa67f3

Please sign in to comment.