I have some data from the lab to analyze. Until now it was a problem which was dependend on one variable. Therefore I found a solution (http://kitchingroup.cheme.cmu.edu/blog/category/interpolation/):
# use splines to fit and interpolate data
from scipy.interpolate import interp1d
from scipy.optimize import fmin
import numpy as np
x = np.array([ 0, 1, 2, 3, 4 ])
y = np.array([ 0., 0.308, 0.55, 0.546, 0.44 ])
# create the interpolating function
f = interp1d(x, y, kind='cubic', bounds_error=False)
# to find the maximum, we minimize the negative of the function. We
# cannot just multiply f by -1, so we create a new function here.
f2 = interp1d(x, -y, kind='cubic')
xmax = fmin(f2, 2.5)
[...]
It figured out that my problem is dependend on at least two parameters. So I tried to apply "interp2d" for a multidimensional problem. But in fact I did not understand how do that exactly.
I have a matrix of data for testing which is like:
| 2.00 | 2.50 | 3.00 | 3.50 | ...
--------------------------------------
5.00 | 0.0 | 60.0 | 10.0 | 0.00
10.0 | 0.0 | 100.0| 70.0 | 30.0
25.0 | 10.0 | 40.0 | 50.0 | 10.0
50.0 | 15.0 | 30.0 | 10.0 | 0.0
...
I read this post "Scipy interpolation on a numpy array" which was quite interesting for me. It's now possible for me to interpolate data like in the example. But I don't know how to apply a function like "minimize" from scipy. There is an example (http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize) but the use a analytical function instead of an interpolated dataset like in the 1D example above.
res = minimize(func, x0, method='Nelder-Mead')
When I tried to use interp2d to do it the same way I got into trouble because of the shape of the array. Maybe it is the key to solve the problem to use it?
Maybe someone can explain to me how to use such a 2D interpolation and how to find the maximum.
Regards, Alex