[Scipy-tickets] [SciPy] #864: Documentation for scipy.interpolate FITPACK interface is misleading (wrong?)

SciPy scipy-tickets@scipy....
Mon Feb 2 14:34:15 CST 2009


#864: Documentation for scipy.interpolate FITPACK interface is misleading
(wrong?)
-------------------------------+--------------------------------------------
 Reporter:  oanjao             |       Owner:  somebody                                                                       
     Type:  defect             |      Status:  new                                                                            
 Priority:  normal             |   Milestone:                                                                                 
Component:  scipy.interpolate  |     Version:  0.6.0                                                                          
 Severity:  normal             |    Keywords:  interpolate, univariatespline, InterpolatedUnivariateSpline,LSQUnivariateSpline
-------------------------------+--------------------------------------------
 The documentation for class scipy.interpolate.UnivariateSpline is
 misleading, and maybe completely wrong.  UnivariateSpline behaves in ways
 that are unpredictable.  Depending on the data passed to the constructor,
 different types of objects are returned without warning, which behave
 differently.  For example, the following code causes SciPy to create an
 object of type <class 'scipy.interpolate.fitpack2.LSQUnivariateSpline'>.

 x = arange(-1., 1.1, 0.2)
 y = pow(x,2)
 y_interp = UnivariateSpline(x,y, k=1)

 LSQUnivariateSpline contains a first-order fit (straight line) to the
 entire data set (a parabola) which is useless.  However, if I pass in a
 different data set, UnivariateSpline(x,y,k=1) returns an object of type
 <class 'scipy.interpolate.fitpack2.UnivariateSpline'> which behaves
 differently! For example:

 x = arange(0.1, 1.1, 0.1)
 y = -1./x
 y_interp = UnivariateSpline(x,y, k=1)

 Despite the fact that I am asking for k=1, in this case I get a crude fit
 consisting of multiple straight line segments.  Now, one more variation to
 get an object of type
 <class'scipy.interpolate.fitpack2.InterpolatedUnivariateSpline'>:

 x = arange(0.1, 1.1, 0.1)
 y = -1./x
 x[0] = x[1]
 y_interp = UnivariateSpline(x,y, k=1)

 This object seems to do straight-line interpolation between the data
 points (much like interp1d()) The number of spline coefficients equals the
 number of data points fitted by the spline.  For k=2, it does quadratic
 interpolation.  The docs string says "Interpolated univariate spline
 approximation. Identical to UnivariateSpline with less error checking"
 which can't be right!

 The behavior of the FITPACK classes in scipy.interpolate is much more
 complex than the docs would lead one to believe, leading to misleading
 results.  The docs should definitely be updated, and perhaps a warning
 should be added when UnivariateSpline() returns a different type of
 object.  It might also be good to offer the user the option of receiving
 data about the quality of the fit, like the numerical integration routines
 return data to the user.

 NOTE: I am working with SciPy 0.6.0, but based on the changelogs and
 online docs for 0.7.0, this problem persists.

-- 
Ticket URL: <http://scipy.org/scipy/scipy/ticket/864>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list