I am trying to fit the data using a physical model. The code snippet is included here:
from scipy.optimize import fmin as simplex
def chi2(p1,x,y_r):
chisq = 0.0
for i in range (len(x)):
real_f=(np.abs(gamma(tret_m,alpha_m)[i])*(p1[0]*sin(p1[1]*x[i]+p1[2]))+ \
p1[3]*np.abs((gamma(tret_m,alpha_m)[i]))**2
if (300>p1[3]>250 and 65>p1[0]>60):#constraining parameters
chisq += (real_f-y_r[i])**2
else:
chisq=1.0e15
return (chisq)
popt = simplex(chi2, guess1, args=(x,obs),ftol=1.0e-6,maxiter=1000000, maxfun=1000000)
The parameters produced at output are same as that provided as initial guesses (passed as guess1)! The output shows this (apart from list of parameters):
Optimization terminated successfully.
Current function value: 1000000000000000.000000
Iterations: 19
Function evaluations: 170
Any clue through which I can make this function run till the function value converges?
EDIT:
1. gamma(tret,alpha) is a function I have defined elsewhere. I am passing tret_m and alpha_m as parameters to gamma (these parameters have been initialized with numerical values). gamma function returns an array of size 1X600.
2. x is a 1X600 array extracted from a file.