... | ... |
@@ -270,14 +270,8 @@ class LearnerND(BaseLearner): |
270 | 270 |
self._subtriangulations[simpl].add_point(point) |
271 | 271 |
|
272 | 272 |
def ask(self, n=1): |
273 |
- # TODO make this method shorter, and nicer, it should be possible |
|
274 |
- xs = [] |
|
275 |
- losses = [] |
|
276 |
- for i in range(n): |
|
277 |
- x, loss = self._ask() |
|
278 |
- xs.append(*x) |
|
279 |
- losses.append(*loss) |
|
280 |
- return xs, losses |
|
273 |
+ xs, losses = zip(*(self._ask() for _ in range(n))) |
|
274 |
+ return list(xs), list(losses) |
|
281 | 275 |
|
282 | 276 |
def _ask(self, n=1): |
283 | 277 |
# Complexity: O(N log N) |
... | ... |
@@ -296,7 +290,7 @@ class LearnerND(BaseLearner): |
296 | 290 |
self._tell_pending(p) |
297 | 291 |
|
298 | 292 |
if n == 0: |
299 |
- return new_points, new_loss_improvements |
|
293 |
+ return new_points[0], new_loss_improvements[0] |
|
300 | 294 |
|
301 | 295 |
losses = [(-v, k) for k, v in self.losses().items()] |
302 | 296 |
heapq.heapify(losses) |
... | ... |
@@ -310,7 +304,7 @@ class LearnerND(BaseLearner): |
310 | 304 |
r = np.array([self._random.random() for _ in range(self.ndim)]) |
311 | 305 |
p = r * a + b |
312 | 306 |
p = tuple(p) |
313 |
- return [p], [np.inf] |
|
307 |
+ return p, np.inf |
|
314 | 308 |
|
315 | 309 |
while len(new_points) < n: |
316 | 310 |
if len(losses): |
... | ... |
@@ -349,7 +343,7 @@ class LearnerND(BaseLearner): |
349 | 343 |
|
350 | 344 |
self._tell_pending(point_new, simplex) |
351 | 345 |
|
352 |
- return new_points, new_loss_improvements |
|
346 |
+ return new_points[0], new_loss_improvements[0] |
|
353 | 347 |
|
354 | 348 |
def update_losses(self, to_delete: set, to_add: set): |
355 | 349 |
pending_points_unbound = set() # TODO add the points outside the triangulation to this as well |