Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify boundary behavior for SciPy's interp1d

I'm trying to set the behavior at the boundaries for SciPy's interp1d function, which according to the documentation should be possible:

Behavior at the boundary can be specified at instantiation time.

But I have not found any further information on this. The interp1d documentation does not mention it all.

So: How can I define the behavior?

Side-curiosity: What is the default boundary behavior it uses?



Edit: Examples (Assuming data points between x=0 and x=n and cubic interpolation)

I know of at least three types of boundary behavior that I would like to be able to specify:

flat: I could demand the function to flat out, in other words derivations to be zero.

f'(0)  = f'(n)  = 0
f''(0) = f''(n) = 0

cyclic: Something among the lines of

f'(0)  = f'(n)
f''(0) = f''(n)

Thus the beginning and end have same "slope".


manual: Or I could manually provide the values for the derivatives...

f'(0)  = ...
f'(n)  = ...
f''(0) = ...
f''(n) = ...

Although probably not for all four of them at the same time.

like image 262
neo post modern Avatar asked Apr 16 '15 22:04

neo post modern


People also ask

What is interpolate interp1d?

Interpolate a 1-D function. x and y are arrays of values used to approximate some function f: y = f(x) . This class returns a function whose call method uses interpolation to find the value of new points. Parameters x(N,) array_like. A 1-D array of real values.

How does Scipy interp1d work?

The interp1d class in the scipy. interpolate is a convenient method to create a function based on fixed data points, which can be evaluated anywhere within the domain defined by the given data using linear interpolation. By using the above data, let us create a interpolate function and draw a new interpolated graph.

What is Scipy interpolate in Python?

Interpolation is a technique of constructing data points between given data points. The scipy. interpolate is a module in Python SciPy consisting of classes, spline functions, and univariate and multivariate interpolation classes. Interpolation is done in many ways some of them are : 1-D Interpolation.


Video Answer


1 Answers

I believe that sentence in the documentation is badly phrased, just ignore it.

The interp1d function, at present, does not allow to specify the boundary behaviour,

  • For linear interpolation, we simply don't have a choice about it.
  • For higher order interpolation interp1d uses the spline constructor scipy.interpolate.splmake with the default parameter kind='smoothest', so again no choice on the boundary behaviour there.

On the other hand, you might want to have a look at scipy.interpolate.PiecewisePolynomial which represents the curve with piecewise polynomials and has the ability to specify the derivatives (although for all knots and not only at the boundaries).

like image 145
rth Avatar answered Sep 30 '22 12:09

rth