Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cubic Interpolation on lower bound #1060

Open
alanlujan91 opened this issue Aug 19, 2021 · 2 comments
Open

Cubic Interpolation on lower bound #1060

alanlujan91 opened this issue Aug 19, 2021 · 2 comments

Comments

@alanlujan91
Copy link
Member

This is related to issue #971.

An issue with CubicInterp is that it previously did not work as expected for the lower bound of the range where the interpolation is defined. As an example:

from HARK.interpolation import CubicInterp
import numpy as np
f = lambda x: x**2
df = lambda x: 2*x
x = np.linspace(-1,1,5)
y = f(x)
dy = df(x)
interp = CubicInterp(x,y,dy)
interp(x)

Out[1]: array([ nan, 0.25, 0.  , 0.25, 1.  ])

Clearly, the first element should be 1.. This is fixed when you set lower_extrap=True.

interp = CubicInterp(x,y,dy, lower_extrap=True)
interp(x)

Out[2]: array([1.  , 0.25, 0.  , 0.25, 1.  ])

However, x=-1 is not extrapolation, as it is one of the data points given, so it should return a value without setting lower_extrap=True.

A previous attempt to resolving this was the following line in `CubicInterp':

#972

...
y[x == self.x_list.min()] = self.y_list.min()
...

but this only works for a particular set of cases. A better solution is

#1008

...
y[x == self.x_list[0]] = self.y_list[0]
... 

interp = CubicInterp(x,y,dy)
interp(x)

Out[2]: array([1.  , 0.25, 0.  , 0.25, 1.  ])

which explicitly plugs in the lower bound. At some point, this correction was overwritten again, so HARK code is back to #972.

Evidently, #972 does not break any tests, as it creeped back in without notice. The way I realized this is back on HARK is because it created a conflict on #1011.

@mnwhite
Copy link
Contributor

mnwhite commented Aug 19, 2021 via email

@llorracc
Copy link
Collaborator

Well, it needs to be fixed one way or another (I wasted a fair amount of time running it down a few months ago).

My preference would be just to substituting the scipy version universally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants