...
|
...
|
@@ -125,10 +125,7 @@ class Learner1D(BaseLearner):
|
125
|
125
|
|
126
|
126
|
def loss(self, real=True):
|
127
|
127
|
losses = self.losses if real else self.losses_combined
|
128
|
|
- if len(losses) == 0:
|
129
|
|
- return float('inf')
|
130
|
|
- else:
|
131
|
|
- return max(losses.values())
|
|
128
|
+ return max(losses.values()) if len(losses) > 0 else float('inf')
|
132
|
129
|
|
133
|
130
|
def update_interpolated_loss_in_interval(self, x_left, x_right):
|
134
|
131
|
if x_left is not None and x_right is not None:
|
...
|
...
|
@@ -176,7 +173,7 @@ class Learner1D(BaseLearner):
|
176
|
173
|
if x in neighbors:
|
177
|
174
|
return neighbors[x]
|
178
|
175
|
pos = neighbors.bisect_left(x)
|
179
|
|
- x_left = neighbors.iloc[pos-1] if pos != 0 else None
|
|
176
|
+ x_left = neighbors.iloc[pos - 1] if pos != 0 else None
|
180
|
177
|
x_right = neighbors.iloc[pos] if pos != len(neighbors) else None
|
181
|
178
|
return x_left, x_right
|
182
|
179
|
|
...
|
...
|
@@ -264,10 +261,8 @@ class Learner1D(BaseLearner):
|
264
|
261
|
return [], []
|
265
|
262
|
|
266
|
263
|
# If the bounds have not been chosen yet, we choose them first.
|
267
|
|
- points = []
|
268
|
|
- for bound in self.bounds:
|
269
|
|
- if bound not in self.data and bound not in self.pending_points:
|
270
|
|
- points.append(bound)
|
|
264
|
+ points = [b for b in self.bounds if b not in self.data
|
|
265
|
+ and b not in self.pending_points]
|
271
|
266
|
|
272
|
267
|
if len(points) == 2:
|
273
|
268
|
# First time
|
...
|
...
|
@@ -288,12 +283,10 @@ class Learner1D(BaseLearner):
|
288
|
283
|
|
289
|
284
|
# Calculate how many points belong to each interval.
|
290
|
285
|
x_scale = self._scale[0]
|
291
|
|
-
|
292
|
286
|
quals = []
|
293
|
|
- for ((x_left, x_right), loss) in self.losses_combined.items():
|
294
|
|
- quality = -loss if not math.isinf(loss) else -(x_right - x_left) / x_scale
|
295
|
|
- quals.append((quality, (x_left, x_right), 1))
|
296
|
|
-
|
|
287
|
+ for x, loss in self.losses_combined.items():
|
|
288
|
+ quality = -loss if not math.isinf(loss) else -(x[1] - x[0]) / x_scale
|
|
289
|
+ quals.append((quality, x, 1))
|
297
|
290
|
heapq.heapify(quals)
|
298
|
291
|
|
299
|
292
|
for point_number in range(n):
|