I have a 2D regular grid of parameters that at each point have a model for a 1D model and I would like to interpolate that 1D model array to any point of parameters space (not just the grid nodes).
For 1D grid of 1 parameter (say A
) with grid values a
I can do the trick using interpolate.RectBivariateSpline, which generates a function that I can call at any given value of A
.
ex:
from scipy import interpolate
ip = interpolate.RectBivariateSpline(a, x, model, s = 0)
new_model = ip([aa], [x])
where a
is the 1D "grid" or array of values for the parameter A, x
is the 1D array of discrete pixels at which the model is expressed f(x) = model(x)
, and aa
is the new value of A at which I want to interpolate.
For the 2D case one solution would be to compute at each pixel of x (each x_i) the interpolation of the 2 parameters using RectBivariateSpline or another method, (like slicing a 3D volume in 2D planes) but that seems cumbersome and does not account for correlation between pixels on the model.
The solution here Multivariate spline interpolation in python/scipy? does not quite apply to my case as I need a complete array to be returned and I need to evaluate at different points on different moments.
From the solutions on scipy interpolation: Both LinearNDinterp
and NearestNDInterp might work, but I don't know how to do a similar thing as with RectBivariateSpline, i.e. feed it the 2D (or nD) parameters grid, the pixels array for the model and the model values, and then get back a interpolated model for the same pixels but different parameter values grid(a1, a2, ... an; x) -> model(A1', A2', ... An'; x)
The solution might be here: Interpolation in vector-valued multi-variate function but I don't know how to reinterpret it to my case...
Ultimately what I would like to do is have the function f(A1, A2, ... An; x)
(or something equivalent) and with some Montecarlo explore in a finer grid the parameters space when comparing the model with data.
Thanks in advance!