[SciPy-User] splint: bug or expected behaviour?
Dave Hirschfeld
dave.hirschfeld at gmail.com
Tue Feb 15 06:59:30 EST 2011
It appears that splint doesn't work correctly when asked to integrate
a region outside the support of the original function.
Consider the following code:
"""
from scipy import interpolate
from scipy.integrate import quad
y = array([ 0.38608245, 0.33937334, 0.30557594, 0.29031793, 0.27597413,
0.26680583, 0.25012443, 0.24310048, 0.23825924, 0.23260759,
0.22179233, 0.21821583, 0.2164903 , 0.21275566, 0.20813042,
0.20404953, 0.19703265, 0.19649831, 0.19548709, 0.1922062 ,
0.18623453])
#
x = ones(y.size)/4
x[0] /= 2
x = x.cumsum()
tck = interpolate.splrep(x, y, s=0.0001)
"""
splev appears to have no problems extrapolating outside the original support:
print interpolate.splev(0, tck, der=0)
0.412282701045
print interpolate.splev(0.1, tck, der=0)
0.389777686302
print interpolate.splev(0.2, tck, der=0)
0.369853064862
however in the first two cases below the results from splint appear a little
suspect:
print interpolate.splint(0, 0.1, tck)
-0.0096789147401
print interpolate.splint(0, 0.2, tck)
0.0282819198434
print interpolate.splint(0.2, 0.3, tck)
0.0360893890763
and indeed, comparing against quad only the final result where the bounds are
wholly within the original support do they agree:
print quad(lambda v: interpolate.splev(v, tck, der=0), 0, 0.1)[0]
0.040080715787
print quad(lambda v: interpolate.splev(v, tck, der=0), 0, 0.2)[0]
0.0780415503705
print quad(lambda v: interpolate.splev(v, tck, der=0), 0.2, 0.3)[0]
0.0360893890763
Is this a bug in splint or expected behaviour when the bounds are outside the
original support (even though splev has no problems) or am I simply mis-
understanding something obvious?
Thanks,
Dave
More information about the SciPy-User
mailing list