EconForge / interpolation.py

BSD 2-Clause "Simplified" License
123 stars 35 forks source link

FIX: interp extrapolates with closest value on the grid. #33

Closed albop closed 5 years ago

albop commented 5 years ago

This one changes the behaviour of interp. It now extrapolates with a constant equal to the closest value in the interpolation domain.

pkofod commented 5 years ago

It's unclear to me if you can still do linear extrapolation somehow?

albop commented 5 years ago

The temporary fix is the following : interp extrapolates with a constant and will keep it as a default (or only option). mlinterp does it linearly and that will remain the default. I'm starting to get a clear view of how to expose extrapolation options but still don't know the best way to pass the option (I was discussing it on gitter/numba recently). Right now I'm inclined to a type case option system a bit like the one from interpolations.jl . The call would be smthg like 'mlinterp(grid, c, p, Linear ())' the latter argument being used only for dispatch. If you have a better idea I'm open to anything.

Le jeu. 11 oct. 2018 à 22:16, Patrick Kofod Mogensen < notifications@github.com> a écrit :

It's unclear to me if you can still do linear extrapolation somehow?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/EconForge/interpolation.py/pull/33#issuecomment-429103002, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQ5KU_BnMHxDXtub4aB4BrHNyEiOZeLks5uj6cpgaJpZM4XMW5u .

pkofod commented 5 years ago

Okay, thanks for the explanation. I think a type case system could be quite user friendly, but are there many other options than constant and linear? I see polynomial and conic on wikipedia, but extrapolation is of course always tricky/dangerous business :)

albop commented 5 years ago

Yes, for multilinear there aren't that many options but we need at least constant, closest value, linear. Actually, sorry for earlier: what interp does is closest value in the domain (f(b+x)=f(b)), not fill with constant values, I didn't make that clear. There could be different settings on both sides, numpy.interp does that. One could maybe add reflected values (i.e.f(b+x)=f(b-x)) or periodic values (f(b+x)=f(a+x). Then there are more exotic options, like user supplied functions like HARK does with asymptotic convergence to an asymptote.