Search code examples
pythonminimize

Finding the correlation for a function minimization


I need to minimize a function in Python and then find the correlation between its variable (let's say f(x,y)). I tried using scipy.optimize.minimize with

res = minimize (f,x0,method='nelder-mead',options={'xtol': 1e-8, 'disp': True})

and it is minimized but I can't get the correlation between x,y. There is a way to do this using this package? Or there is another better way? (i do not need to do a fit on some points, I need just to find the minimum of the function)


Solution

  • to find the minimum point of a function f, within the domain x0, you can simply use scipy.optimize.fmin. setting the disp arg in this function will return the convergence message. if you are after the regression between x0 and f, then use scipy scipy.stats.linregress. if you want to calculate the correlation between the solution of the scipy.optimize.minimize function and the original f, then you can use scipy.signal.correlate