[SciPy-User] scipy.interpolate UnivariateSpline | Results depend on bbox

Alexander Riess rie.uoa at googlemail.com
Tue Jun 28 10:26:10 EDT 2011


Hello,

I did some experiments with UnivariateSpline on Win XP 64 bit with
Python 2.6 and wondered, that the results depend on bbox.

Firstly I defined a time grid and created some function values f(t)

t0 = 0.0
te = 1.0
n  = 11

t = np.linspace(t0,te,n)
print "t = ",t
d = t
print "d = exp(t) = ",d

Output

t =  [ 0.   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9  1. ]
d = exp(t) =  [ 0.   0.1  0.2  0.3  0.4  0.5  0.6  0.7  0.8  0.9  1. ]

Secondly I tried to reproduce the initial used data on the same time
grid and wondered, that it depends on the specified bbox.

for i in np.linspace(0,1,21):
    UsLaBox = UnivariateSpline( t,  d, k=1, bbox = [ t[0]-i, t[-1]+i ], s = 0)
    print "ERROR for bbox", "t = [", t[0], ",", t[-1], "]", "-/+
%0.2f" % i, " ", abs(d - UsLaBox(t)).max()
    print d - UsLaBox(t)

Output:

ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.00   0.0
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.05   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00  -2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.10   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.15   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.20   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.25   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.30   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.35   0.0
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.40   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   1.11022302e-16   1.11022302e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.45   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -2.22044605e-16  -2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.50   3.33066907388e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   3.33066907e-16   2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.55   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.60   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   1.11022302e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.65   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16  -2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.70   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16   0.00000000e+00]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.75   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -1.11022302e-16  -2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.80   1.11022302463e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   1.11022302e-16   1.11022302e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.85   0.0
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.90   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   2.22044605e-16   1.11022302e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 0.95   2.22044604925e-16
[  0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00  -2.22044605e-16  -2.22044605e-16]
ERROR for bbox t = [ 0.0 , 1.0 ] -/+ 1.00   0.0
[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]

I expected to get 0.0 in all cases, as I used s = 0 and the tested
time grid is the same as in UnivariateSpline. It is remarkable that
the error only occur at the last 2 indexes of the interpolation array.

I hope somebody can help me because I want to know whether this is a
bug or not?

Kind regards

Alex



More information about the SciPy-User mailing list