本文整理汇总了Python中scipy.interpolate.make_interp_spline函数的典型用法代码示例。如果您正苦于以下问题:Python make_interp_spline函数的具体用法?Python make_interp_spline怎么用?Python make_interp_spline使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_interp_spline函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sliced_input
def test_sliced_input(self):
# cython code chokes on non C contiguous arrays
xx = np.linspace(-1, 1, 100)
x = xx[::5]
y = xx[::5]
make_interp_spline(x, y, k=1)
示例2: test_quadratic_deriv
def test_quadratic_deriv(self):
der = [(1, 8.)] # order, value: f'(x) = 8.
# derivative at right-hand edge
b = make_interp_spline(self.xx, self.yy, k=2, bc_type=(None, der))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
assert_allclose(b(self.xx[-1], 1), der[0][1], atol=1e-14, rtol=1e-14)
# derivative at left-hand edge
b = make_interp_spline(self.xx, self.yy, k=2, bc_type=(der, None))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
assert_allclose(b(self.xx[0], 1), der[0][1], atol=1e-14, rtol=1e-14)
示例3: test_cubic_deriv
def test_cubic_deriv(self):
k = 3
# first derivatives at left & right edges:
der_l, der_r = [(1, 3.)], [(1, 4.)]
b = make_interp_spline(self.xx, self.yy, k, bc_type=(der_l, der_r))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
assert_allclose([b(self.xx[0], 1), b(self.xx[-1], 1)],
[der_l[0][1], der_r[0][1]], atol=1e-14, rtol=1e-14)
# 'natural' cubic spline, zero out 2nd derivatives at the boundaries
der_l, der_r = [(2, 0)], [(2, 0)]
b = make_interp_spline(self.xx, self.yy, k, bc_type=(der_l, der_r))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
示例4: test_shapes
def test_shapes(self):
np.random.seed(1234)
k, n = 3, 22
x = np.sort(np.random.random(size=n))
y = np.random.random(size=(n, 5, 6, 7))
b = make_interp_spline(x, y, k)
assert_equal(b.c.shape, (n, 5, 6, 7))
# now throw in some derivatives
d_l = [(1, np.random.random((5, 6, 7)))]
d_r = [(1, np.random.random((5, 6, 7)))]
b = make_interp_spline(x, y, k, bc_type=(d_l, d_r))
assert_equal(b.c.shape, (n + k - 1, 5, 6, 7))
示例5: test_complex
def test_complex(self):
k = 3
xx = self.xx
yy = self.yy + 1.j*self.yy
# first derivatives at left & right edges:
der_l, der_r = [(1, 3.j)], [(1, 4.+2.j)]
b = make_interp_spline(xx, yy, k, bc_type=(der_l, der_r))
assert_allclose(b(xx), yy, atol=1e-14, rtol=1e-14)
assert_allclose([b(xx[0], 1), b(xx[-1], 1)],
[der_l[0][1], der_r[0][1]], atol=1e-14, rtol=1e-14)
# also test zero and first order
for k in (0, 1):
b = make_interp_spline(xx, yy, k=k)
assert_allclose(b(xx), yy, atol=1e-14, rtol=1e-14)
示例6: test_int_xy
def test_int_xy(self):
x = np.arange(10).astype(np.int_)
y = np.arange(10).astype(np.int_)
# cython chokes on "buffer type mismatch" (construction) or
# "no matching signature found" (evaluation)
for k in (0, 1, 2, 3):
b = make_interp_spline(x, y, k=k)
b(x)
示例7: test_multiple_rhs
def test_multiple_rhs(self):
yy = np.c_[np.sin(self.xx), np.cos(self.xx)]
der_l = [(1, [1., 2.])]
der_r = [(1, [3., 4.])]
b = make_interp_spline(self.xx, yy, k=3, bc_type=(der_l, der_r))
assert_allclose(b(self.xx), yy, atol=1e-14, rtol=1e-14)
assert_allclose(b(self.xx[0], 1), der_l[0][1], atol=1e-14, rtol=1e-14)
assert_allclose(b(self.xx[-1], 1), der_r[0][1], atol=1e-14, rtol=1e-14)
示例8: test_full_matrix
def test_full_matrix(self):
np.random.seed(1234)
k, n = 3, 7
x = np.sort(np.random.random(size=n))
y = np.random.random(size=n)
t = _not_a_knot(x, k)
b = make_interp_spline(x, y, k, t)
cf = make_interp_full_matr(x, y, t, k)
assert_allclose(b.c, cf, atol=1e-14, rtol=1e-14)
示例9: test_integrate_ppoly
def test_integrate_ppoly(self):
# test .integrate method to be consistent with PPoly.integrate
x = [0, 1, 2, 3, 4]
b = make_interp_spline(x, x)
b.extrapolate = 'periodic'
p = PPoly.from_spline(b)
for x0, x1 in [(-5, 0.5), (0.5, 5), (-4, 13)]:
assert_allclose(b.integrate(x0, x1),
p.integrate(x0, x1))
示例10: test_minimum_points_and_deriv
def test_minimum_points_and_deriv(self):
# interpolation of f(x) = x**3 between 0 and 1. f'(x) = 3 * xx**2 and
# f'(0) = 0, f'(1) = 3.
k = 3
x = [0., 1.]
y = [0., 1.]
b = make_interp_spline(x, y, k, bc_type=([(1, 0.)], [(1, 3.)]))
xx = np.linspace(0., 1.)
yy = xx**3
assert_allclose(b(xx), yy, atol=1e-14, rtol=1e-14)
示例11: test_quintic_derivs
def test_quintic_derivs(self):
k, n = 5, 7
x = np.arange(n).astype(np.float_)
y = np.sin(x)
der_l = [(1, -12.), (2, 1)]
der_r = [(1, 8.), (2, 3.)]
b = make_interp_spline(x, y, k=k, bc_type=(der_l, der_r))
assert_allclose(b(x), y, atol=1e-14, rtol=1e-14)
assert_allclose([b(x[0], 1), b(x[0], 2)],
[val for (nu, val) in der_l])
assert_allclose([b(x[-1], 1), b(x[-1], 2)],
[val for (nu, val) in der_r])
示例12: setup_method
def setup_method(self):
xx = np.linspace(0, 4.*np.pi, 41)
yy = np.cos(xx)
b = make_interp_spline(xx, yy)
self.tck = (b.t, b.c, b.k)
self.xx, self.yy, self.b = xx, yy, b
self.xnew = np.linspace(0, 4.*np.pi, 21)
c2 = np.c_[b.c, b.c, b.c]
self.c2 = np.dstack((c2, c2))
self.b2 = BSpline(b.t, self.c2, b.k)
示例13: test_cubic_deriv_unstable
def test_cubic_deriv_unstable(self):
# 1st and 2nd derivative at x[0], no derivative information at x[-1]
# The problem is not that it fails [who would use this anyway],
# the problem is that it fails *silently*, and I've no idea
# how to detect this sort of instability.
# In this particular case: it's OK for len(t) < 20, goes haywire
# at larger `len(t)`.
k = 3
t = _augknt(self.xx, k)
der_l = [(1, 3.), (2, 4.)]
b = make_interp_spline(self.xx, self.yy, k, t, bc_type=(der_l, None))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
示例14: test_deriv_spec
def test_deriv_spec(self):
# If one of the derivatives is omitted, the spline definition is
# incomplete.
x = y = [1.0, 2, 3, 4, 5, 6]
with assert_raises(ValueError):
make_interp_spline(x, y, bc_type=([(1, 0.)], None))
with assert_raises(ValueError):
make_interp_spline(x, y, bc_type=(1, 0.))
with assert_raises(ValueError):
make_interp_spline(x, y, bc_type=[(1, 0.)])
with assert_raises(ValueError):
make_interp_spline(x, y, bc_type=42)
# CubicSpline expects`bc_type=(left_pair, right_pair)`, while
# here we expect `bc_type=(iterable, iterable)`.
l, r = (1, 0.0), (1, 0.0)
with assert_raises(ValueError):
make_interp_spline(x, y, bc_type=(l, r))
示例15: test_knots_not_data_sites
def test_knots_not_data_sites(self):
# Knots need not coincide with the data sites.
# use a quadratic spline, knots are at data averages,
# two additional constraints are zero 2nd derivs at edges
k = 2
t = np.r_[(self.xx[0],)*(k+1),
(self.xx[1:] + self.xx[:-1]) / 2.,
(self.xx[-1],)*(k+1)]
b = make_interp_spline(self.xx, self.yy, k, t,
bc_type=([(2, 0)], [(2, 0)]))
assert_allclose(b(self.xx), self.yy, atol=1e-14, rtol=1e-14)
assert_allclose([b(self.xx[0], 2), b(self.xx[-1], 2)], [0., 0.],
atol=1e-14)