Skip to content

Commit 4301874

Browse files
committed
Learner1D: return inf loss when the bounds aren't done
1 parent 3d9397d commit 4301874

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

adaptive/learner/learner1D.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def __init__(self, function, bounds, loss_per_interval=None):
201201
self._dx_eps = 2 * max(np.abs(bounds)) * np.finfo(float).eps
202202

203203
self.bounds = list(bounds)
204+
self.__missing_bounds = set(self.bounds)
204205

205206
self._vdim = None
206207

@@ -231,6 +232,8 @@ def npoints(self):
231232

232233
@cache_latest
233234
def loss(self, real=True):
235+
if self._missing_bounds():
236+
return np.inf
234237
losses = self.losses if real else self.losses_combined
235238
if not losses:
236239
return np.inf
@@ -496,6 +499,15 @@ def ask(self, n, tell_pending=True):
496499

497500
return points, loss_improvements
498501

502+
def _missing_bounds(self):
503+
missing_bounds = []
504+
for b in self.__missing_bounds:
505+
if b in self.data:
506+
self.__missing_bounds.remove(b)
507+
elif b not in self.pending_points:
508+
missing_bounds.append(b)
509+
return missing_bounds
510+
499511
def _ask_points_without_adding(self, n):
500512
"""Return 'n' points that are expected to maximally reduce the loss.
501513
Without altering the state of the learner"""
@@ -511,12 +523,7 @@ def _ask_points_without_adding(self, n):
511523
return [], []
512524

513525
# If the bounds have not been chosen yet, we choose them first.
514-
missing_bounds = [
515-
b
516-
for b in self.bounds
517-
if b not in self.data and b not in self.pending_points
518-
]
519-
526+
missing_bounds = self._missing_bounds()
520527
if len(missing_bounds) >= n:
521528
return missing_bounds[:n], [np.inf] * n
522529

0 commit comments

Comments
 (0)