Thank you for the speedy response Matt.
I have read that link, and the strange thing is that I only get the
nan values when I use model.eval() or model.fit(). If I simply
evaluate the function I get finite values as I expect (see below).
I'll attach the code.
What my function does is a convolution of a theoretical spectrum by
some Lorentzians and this covolved spectrum is fitted to an
experimental one.
When I use numpy.curvefit, this is fitted without problems. When I try
to use lmfit I run into the issue I mentioned above. My function is
composed of a few functions which call my Lorentzian function (maybe
this causes a problem?).
Here is some of the code.
def CauchyDist(x,Gamma): #Gamma is the full width
b = Gamma/2.0 #Half width
m = np.max(x) - (np.max(x)-np.min(x))/2.0 #Location of the mean
(in the middle of the x array)
return np.pi**-1 * (abs(b)/((x-m)**2.0+b**2.0))
def TotalConvolutionFunction5(Energy,x0,x1,x2,x3,x4,debye,hole):
#Remove the atom background from the FDMNES output
Chi = (xanes-Atom)/Atom
#Apply the convolutions
Chi = DebyeWaller(imfp5Conv(Chi,E,hole,x0,x1,x2,x3,x4),E,debye)
#The function imfp5Conv performs the convolutions.
#Interpolation function for spectrum
f = scipy.interpolate.interp1d(E,Chi,kind = 'cubic')
return f(Energy)
#Trying to use lmfit to explore some different fitting methods
model = lmfit.Model(TotalConvolutionFunction5)
params5 = model.make_params(x0=poptConv5[0],
x1=poptConv5[1],
x2=5.,
x3=poptConv5[3],
x4=poptConv5[4],
debyeWallerFactor=poptConv5[5],
Gamma_hole=poptConv5[6])
test = model.eval(Energy=E[E<MaxEnFit],
params = params5)
print(np.isnan(TotalConvolutionFunction5(E[E<MaxEnFit],*poptConv5)))
print(np.isnan(test))
Here is the output
RuntimeWarning: invalid value encountered in divide return np.pi**-1 *
(abs(b)/((x-m)**2.0+b**2.0)) (This is the line from the CauchyDist
function)
[False False... ... ...False False]
[ True True... ... ...True True True]
I am truly confused. What do you think?
> To view this discussion on the web visit
https://groups.google.com/d/msgid/lmfit-py/MN6PR11MB821986B3C06416CE09B0334496112%40MN6PR11MB8219.namprd11.prod.outlook.com.