@@ -345,7 +345,7 @@ def bounds_are_done(self):
345
345
(p in self .pending_points or p in self ._stack ) for p in self ._bounds_points
346
346
)
347
347
348
- def data_on_grid (self , n = None ):
348
+ def interpolated_on_grid (self , n = None ):
349
349
"""Get the interpolated data on a grid.
350
350
351
351
Parameters
@@ -356,11 +356,11 @@ def data_on_grid(self, n=None):
356
356
357
357
Returns
358
358
-------
359
- xs : 1D numpy.ndarray, optional
360
- ys : 1D numpy.ndarray, optional
361
- data_on_grid : 2D numpy.ndarray
359
+ xs : 1D numpy.ndarray
360
+ ys : 1D numpy.ndarray
361
+ interpolated_on_grid : 2D numpy.ndarray
362
362
"""
363
- ip = self .ip ( )
363
+ ip = self .interpolate ( scaled = True )
364
364
if n is None :
365
365
# Calculate how many grid points are needed.
366
366
# factor from A=√3/4 * a² (equilateral triangle)
@@ -390,7 +390,8 @@ def _data_interp(self):
390
390
if self .pending_points :
391
391
points = list (self .pending_points )
392
392
if self .bounds_are_done :
393
- values = self .ip ()(self ._scale (points ))
393
+ ip = self .interpolate ()
394
+ values = ip (self ._scale (points ))
394
395
else :
395
396
# Without the bounds the interpolation cannot be done properly,
396
397
# so we just set everything to zero.
@@ -415,15 +416,33 @@ def data_combined(self):
415
416
return {tuple (k ): v for k , v in zip (points , values )}
416
417
417
418
def ip (self ):
419
+ """Deprecated, use `self.interpolate()`"""
420
+ return self .interpolate (scaled = True )
421
+
422
+ def interpolate (self , * , scaled = True ):
418
423
"""A `scipy.interpolate.LinearNDInterpolator` instance
419
- containing the learner's data."""
420
- if self ._ip is None :
424
+ containing the learner's data.
425
+
426
+ Parameters
427
+ ----------
428
+ scaled : bool
429
+ True if all points are inside the unit-square [(-0.5, 0.5), (-0.5, 0.5)].
430
+
431
+ Returns
432
+ -------
433
+ interpolate : `scipy.interpolate.LinearNDInterpolator`
434
+ """
435
+ if scaled :
436
+ if self ._ip is None :
437
+ points , values = self ._data_in_bounds ()
438
+ points = self ._scale (points )
439
+ self ._ip = interpolate .LinearNDInterpolator (points , values )
440
+ return self ._ip
441
+ else :
421
442
points , values = self ._data_in_bounds ()
422
- points = self ._scale (points )
423
- self ._ip = interpolate .LinearNDInterpolator (points , values )
424
- return self ._ip
443
+ return interpolate .LinearNDInterpolator (points , values )
425
444
426
- def ip_combined (self ):
445
+ def _interpolate_combined (self ):
427
446
"""A `scipy.interpolate.LinearNDInterpolator` instance
428
447
containing the learner's data *and* interpolated data of
429
448
the `pending_points`."""
@@ -460,7 +479,7 @@ def _fill_stack(self, stack_till=1):
460
479
raise ValueError ("too few points..." )
461
480
462
481
# Interpolate
463
- ip = self .ip_combined ()
482
+ ip = self ._interpolate_combined ()
464
483
465
484
losses = self .loss_per_triangle (ip )
466
485
@@ -528,7 +547,7 @@ def ask(self, n, tell_pending=True):
528
547
def loss (self , real = True ):
529
548
if not self .bounds_are_done :
530
549
return np .inf
531
- ip = self .ip () if real else self .ip_combined ()
550
+ ip = self .interpolate () if real else self ._interpolate_combined ()
532
551
losses = self .loss_per_triangle (ip )
533
552
return losses .max ()
534
553
@@ -573,7 +592,7 @@ def plot(self, n=None, tri_alpha=0):
573
592
lbrt = x [0 ], y [0 ], x [1 ], y [1 ]
574
593
575
594
if len (self .data ) >= 4 :
576
- ip = self .ip ()
595
+ ip = self .interpolate ()
577
596
x , y , z = self .data_on_grid (n )
578
597
579
598
if self .vdim > 1 :
0 commit comments