Interpolation problem with interp1d(.)
Hi, Apparently I'm somehow misusing the functionality of interp1d(.) or does following behavior imply a bug in scipy. A minimum snippet (with plots) to demonstrate the problem: In []: from scipy.interpolate import interp1d In []: n= 1000 In []: x, y= randn(n), linspace(0, 1, n) In []: x.sort() In []: plot(x, y, lw= 2) Out[]: [<matplotlib.lines.Line2D object at 0x12E190D0>] In []: f= interp1d(x, y, 'cubic') In []: xi= linspace(x.min(), x.max(), n) In []: plot(xi, f(xi)) Out[]: [<matplotlib.lines.Line2D object at 0x12E20830>] Regards, -eat
On Wed, Aug 29, 2012 at 3:29 PM, eat <e.antero.tammi@gmail.com> wrote:
Hi,
Apparently I'm somehow misusing the functionality of interp1d(.) or does following behavior imply a bug in scipy. A minimum snippet (with plots) to demonstrate the problem: In []: from scipy.interpolate import interp1d In []: n= 1000 In []: x, y= randn(n), linspace(0, 1, n) In []: x.sort() In []: plot(x, y, lw= 2) Out[]: [<matplotlib.lines.Line2D object at 0x12E190D0>]
In []: f= interp1d(x, y, 'cubic') In []: xi= linspace(x.min(), x.max(), n) In []: plot(xi, f(xi)) Out[]: [<matplotlib.lines.Line2D object at 0x12E20830>]
I guess, some x's are too close to each other to fit a cubic interpolation without a lot of overshooting. Reversing x and y looks fine. Using the splines directly and add a small s>0 might also work. Josef
Regards, -eat
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Hi, On Wed, Aug 29, 2012 at 10:46 PM, <josef.pktd@gmail.com> wrote:
On Wed, Aug 29, 2012 at 3:29 PM, eat <e.antero.tammi@gmail.com> wrote:
Hi,
Apparently I'm somehow misusing the functionality of interp1d(.) or does following behavior imply a bug in scipy. A minimum snippet (with plots) to demonstrate the problem: In []: from scipy.interpolate import interp1d In []: n= 1000 In []: x, y= randn(n), linspace(0, 1, n) In []: x.sort() In []: plot(x, y, lw= 2) Out[]: [<matplotlib.lines.Line2D object at 0x12E190D0>]
In []: f= interp1d(x, y, 'cubic') In []: xi= linspace(x.min(), x.max(), n) In []: plot(xi, f(xi)) Out[]: [<matplotlib.lines.Line2D object at 0x12E20830>]
I guess, some x's are too close to each other to fit a cubic interpolation without a lot of overshooting.
Makes sense, although what are too close seems to be quite conservative: In []: d= x[1:]- x[:-1] In []: d.sort() In []: d[:3] Out[]: array([ 2.09893021e-06, 2.36059137e-06, 7.52680662e-06]) Regards, -eat
Reversing x and y looks fine.
Using the splines directly and add a small s>0 might also work.
Josef
Regards, -eat
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
Oops, I forgot to mention that I'm on: In []: sys.version Out[]: '2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]' In []: np.version.version Out[]: '1.6.0' In []: sp.version.version Out[]: '0.9.0' On Wed, Aug 29, 2012 at 10:29 PM, eat <e.antero.tammi@gmail.com> wrote:
Hi,
Apparently I'm somehow misusing the functionality of interp1d(.) or does following behavior imply a bug in scipy. A minimum snippet (with plots) to demonstrate the problem: In []: from scipy.interpolate import interp1d In []: n= 1000 In []: x, y= randn(n), linspace(0, 1, n) In []: x.sort() In []: plot(x, y, lw= 2) Out[]: [<matplotlib.lines.Line2D object at 0x12E190D0>]
In []: f= interp1d(x, y, 'cubic') In []: xi= linspace(x.min(), x.max(), n) In []: plot(xi, f(xi)) Out[]: [<matplotlib.lines.Line2D object at 0x12E20830>]
Regards, -eat
participants (2)
-
eat -
josef.pktd@gmail.com