I m using a least square minimization in order to fit a lot of parameters, but, the results are little surprising, i think it could be due to minimization. Indeed, when i modify the initialization terms, the results are different...
In a first time i try to adjust the initial values of parameters with the command "xtol" which specify the error desired in the approximate solution, but the results are not better, so i would like to know if it is possible to specify bounds for each parameters. This last solution could be more accurate couldn it?
Moreover terms i need to fit are parameters of a series perhaps there is a best way to deal this problem than i have done by writing the 2 orders...
def residual_V2will2(vars, XA, YA, x0, y0, A2, donnees):
aI = vars[0]
aII = vars[1]
modeleV2 = ma.masked_invalid(np.sqrt((XA-x0)**2 + (YA-y0)**2)**(1/2)*aI/(2*G)*((Kappa - 1/2. + \
1)*np.sin(np.arctan(((YA-y0)/(XA-x0)))/2) + \
1/2.*np.sin(np.arctan(((YA-y0)/(XA-x0)))*(-3/2.))) + np.sqrt((XA-x0)**2 + \
(YA-y0)**2)*aII/(2*G)*((Kappa - 2)*np.sin(np.arctan(((YA-y0)/(XA-x0)))) + \
np.sin(np.arctan(((YA-y0)/(XA-x0)))*(-1))) + A2)
return (donnees-modeleV2)
from scipy.optimize import leastsq
vars = [KI, A2, x0, y0]
out_V_west = sco.leastsq(residual_V2west, vars, args=(XAvect, YAvect, Vmvect))
print out_V_west
So if i follow you i must have something like that :
def residual_V2west(vars, XA, YA, donnees):
KI = vars[0]
A2 = vars[1]
x0 = vars[2]
y0 = vars[3]
modeleV2 = ...
penalization = abs(2.-modeleV2)*10000
return (donnees-modeleV2 - penalization)
But dont seem better :( although i try to play with values of penalization...