Hi all, I am kind of new with lmfit, so it may be trivial but despite my best efforts I can’t fix my issue. I tried to reproduce what is shown
here
I use Spyder (Python 3.9) in Anaconda on a Mac and I have defined a model with
def Barrett_model(x, C, T0, T1, eps_cst):
return eps_cst + C*1e4 / ( (T1/2) * np.cosh( T1/(2*x) )/np.sinh( T1/(2*x) ) - T0 )
bmodel = Model(Barrett_model)
I defined the parameters and carried out the fit with
params = bmodel.make_params(C={'value': 6, 'min':1e-10, 'vary':True}, T1={'value': 51.39, 'min':1e-10, 'vary':True}, T0={'value': 11.80, 'min':1e-10, 'vary':True}, eps_cst={'value': 0.1, 'vary':True})
resultB_STO = bmodel.fit(y, params=params, x=x, weights=None, method='leastsq', iter_cb=None, scale_covar=True, verbose=False, fit_kws=None, nan_policy=None, calc_covar=True, max_nfev=None, coerce_farray=True)
So far, so good. I then try to use emcee with (copied and pasted from
here, changing the variables for the parameters and model):
emcee_kws = dict(steps=5000, burn=500, thin=20, is_weighted=False,
progress=False)
emcee_params = resultB_STO.params.copy()
emcee_params.add('__lnsigma', value=np.log(0.1), min=np.log(0.001), max=np.log(2.0))
result_emcee = bmodel.fit(data=data1['epsr_STO'], x=data1['T(K)'], params=emcee_params, method='emcee’, nan_policy='omit', fit_kws=emcee_kws)and I get an error about the emcee version. The full Traceback is :
Cell In[45], line 5
result_emcee = bmodel.fit(data=data1['epsr_STO'], x=data1['T(K)'], params=emcee_params, method='emcee',
File /opt/anaconda3/lib/python3.9/site-packages/lmfit/model.py:1103 in fit
output.fit(data=data, weights=weights)
File /opt/anaconda3/lib/python3.9/site-packages/lmfit/model.py:1467 in fit
_ret = self.minimize(method=self.method)
File /opt/anaconda3/lib/python3.9/site-packages/lmfit/minimizer.py:2345 in minimize
return function(**kwargs)
File /opt/anaconda3/lib/python3.9/site-packages/lmfit/minimizer.py:1279 in emcee
raise NotImplementedError('emcee version 3 is required.')
NotImplementedError: emcee version 3 is required.
However, in the Spyder console, when I check the emcee version I get:
In[46]: emcee.__version__
Out[46]: '3.1.4'
I have read
this post on the mailing list and run the following commands:
import sys, lmfit, numpy, scipy, asteval, emcee, uncertainties
print(f"Python: {sys.version}\n\nlmfit: {lmfit.__version__}, scipy: {scipy.__version__}, numpy: {numpy.__version__}, asteval: {asteval.__version__}, uncertainties: {uncertainties.__version__}, emcee: {emcee.__version__}")
Python: 3.9.13 (main, Oct 13 2022, 16:12:30)
[Clang 12.0.0 ]
It does show that the emcee version is >3 :
lmfit: 1.2.2, scipy: 1.7.1, numpy: 1.23.5, asteval: 0.9.27, uncertainties: 3.1.7, emcee: 3.1.4
When I open a terminal on my Mac and run
(base) me@me-MacBook-Pro ~ % python
Python 3.9.13 (main, Oct 13 2022, 16:12:30)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, lmfit, numpy, scipy, asteval, emcee, uncertainties
print(f"Python: {sys.version}\n\nlmfit: {lmfit.__version__}, scipy: {scipy.__version__}, numpy: {numpy.__version__}, asteval: {asteval.__version__}, uncertainties: {uncertainties.__version__}, emcee: {emcee.__version__}")
/opt/anaconda3/lib/python3.9/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.5
warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}"
>>> print(f"Python: {sys.version}\n\nlmfit: {lmfit.__version__}, scipy: {scipy.__version__}, numpy: {numpy.__version__}, asteval: {asteval.__version__}, uncertainties: {uncertainties.__version__}, emcee: {emcee.__version__}")
Python: 3.9.13 (main, Oct 13 2022, 16:12:30)
[Clang 12.0.0 ]
lmfit: 1.2.2, scipy: 1.7.1, numpy: 1.23.5, asteval: 0.9.27, uncertainties: 3.1.7, emcee: 3.1.4
So the emcee version appears >3. Any idea what is going on and how I can fix it?
Thanks a lot for your help!