def test_add_points(self): itp1 = WaryInterpolator(domain=[0, 5]) itp1.add_points([0, 4, 2], [10, 30, 20]) itp2 = WaryInterpolator(points=(0, 2, 4), values=(10, 20, 30), domain=[0, 5]) np.testing.assert_array_equal(itp1.points, itp2.points) np.testing.assert_array_equal(itp1.values, itp2.values) itp1.add_point(4, 40) itp2.add_point(4, 40) np.testing.assert_array_equal(itp1.points, itp2.points) np.testing.assert_array_equal(itp1.values, itp2.values)
def test_precision(self): itp_x2 = WaryInterpolator(points=(0, 1, 2), values=(0, 1, 4), precision=0.01, domain=(0, 5)) self.assertRaises(InsufficientPrecisionError, itp_x2, 0.5) xs = np.array([0.485, 0.495, 0.505, 0.515]) itp_x2.add_points(xs, xs**2) self.assertAlmostEqual(itp_x2(0.5), (0.495**2 + 0.505**2)/2)
def test_interpolate(self): itp = WaryInterpolator(if_higher='extrapolate', if_lower='raise', domain=(0, 5)) self.assertRaises(InsufficientPrecisionError, itp, 0) itp.add_points([0, 2, 4], [10, 20, 30]) self.assertEqual(itp(0), 10) self.assertAlmostEqual(itp(1), 15) self.assertAlmostEqual(itp(5), 35) self.assertRaises(OutsideDomainError, itp, -5)
def __init__(self, statistic, **kwargs): self.statistic = statistic for k, v in kwargs.items(): setattr(self, k, v) self.cl = self.confidence_level self.log = logging.getLogger(self.__class__.__name__) if self.wrap_interpolator: self.log.debug("Initializing interpolators") if self.fixed_lower_limit is None: self.low_limit_interpolator = WaryInterpolator(precision=10**(-self.precision_digits), domain=self.interpolator_log_domain) if self.fixed_upper_limit is None: self.high_limit_interpolator = WaryInterpolator(precision=10**(-self.precision_digits), domain=self.interpolator_log_domain) # "Joints" of the interpolator must have better precision than required of the interpolator results self.precision_digits += 1 # Dictionary holding "horizontal" intervals: interval on statistic for each precision and hypothesis. self.cached_intervals = {}