Do you know why lmfit.minimize function gives me stderr "none" after data fitting??

1,070 views
Skip to first unread message

김국태

unread,
Aug 8, 2018, 4:04:09 AM8/8/18
to lmfit-py
Hello

I'm trying to get the best fitted parameters from my data using C extended function.
I was able to get the result by using lmfit.minimize() function, but  stderr's not calculated
they keep giving me "None" as a stderr (result is in the Presentation.pdf, please do not care the numbers.)

attatched "modulecreat.c " is a c script I used to make a module "subfunc" that will be imported in the "pythonFit.py" script.

for example, in my "pythonFit.py" I can call my wrapped C function from the module..

'''
import subfunc
subfunc.modle(x,parameters...)

'''

Can you help me to know why they give me "None" as a stderr??
I want to get the errors and covariaces between parameters.

Regards,

kooktaeKim.
modulecreate.c
pythonFit.py
Presentation.pdf

김국태

unread,
Aug 8, 2018, 4:57:55 AM8/8/18
to lmfit-py
be addvised, in the "pythonFit.py" the fitting method is now differential evolution, and I already tried leastsquared. 


2018년 8월 8일 수요일 오후 5시 4분 9초 UTC+9, 김국태 님의 말:

Renee Otten

unread,
Aug 8, 2018, 9:26:02 AM8/8/18
to lmfi...@googlegroups.com
First off, the only method that will can give you uncertainties is “leastsq” not to be confused here with “least_squares”. I am not sure which one you refer to when you say “I already tried least squared”, so please try that again first.

I didn’t look at the actual functions and code, but from the fitting results it appears that several of the parameters are close to or at their maximum values. That is typically not good and might result in “leastsq” not being able to calculate the covariance matrix that is used to estimate the uncertainties (if that’s the problem results.errorbars will be False). So you could try to increase the upper bounds for these parameters and try again. 

Renee 



-- 
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To post to this group, send email to lmfi...@googlegroups.com.
Visit this group at https://groups.google.com/group/lmfit-py.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/6bb6b0df-a55b-4bf9-a0ca-91aac752dac3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

김국태

unread,
Aug 8, 2018, 10:07:19 AM8/8/18
to lmfit-py
Thank you for responding me!

1) Yes I already aware of that fact, and I meant "leastsq" that is default algorithm for the lmfit.minimize() function.

2) After reading some documents on minimize function, I've already tried removing bounds for the parameters and got the same result.

Regards, kooktae kim.

2018년 8월 8일 수요일 오후 5시 4분 9초 UTC+9, 김국태 님의 말:
Hello

김국태

unread,
Aug 8, 2018, 10:30:54 AM8/8/18
to lmfit-py
Whait I just found is that if I don't let the parameter rms0 to change, the stderr is calculated well.
Does that mean parameter rms0 don't affect any practical effect on the fitting??

Regards,
kooktaeKim


2018년 8월 8일 수요일 오후 5시 4분 9초 UTC+9, 김국태 님의 말:
Hello

Matt Newville

unread,
Aug 8, 2018, 8:37:18 PM8/8/18
to lmfit-py
Hi KooTae,

On Wed, Aug 8, 2018 at 9:30 AM 김국태 <wksd...@naver.com> wrote:
Whait I just found is that if I don't let the parameter rms0 to change, the stderr is calculated well.
Does that mean parameter rms0 don't affect any practical effect on the fitting??

Yes, that is what Renee meant. A parameter that does not affect the fit or is at one of its bounds will usually make it impossible to calculate the uncertainties.

You might investigate if any of the other parameter values make it so that rms0 is unnecessary in the fit.  Like maybe that layer is very thin or otherwise not contributing?

BTW, it's great to see someone using lmfit for X-ray reflectivity (and on Co-Pt multilayers!?), but I haven't looked in detail into your C code to follow all of the calculation or guess where something might be going wrong.

--Matt

Andrew Nelson

unread,
Aug 8, 2018, 9:25:27 PM8/8/18
to lmfit-py
It may be useful to use a program like refnx (conda install -c conda-forge refnx/pip install refnx), or refl1d, these are both excellent packages for analysing XRR+NR data.

Disclaimer - I develop refnx.

김국태

unread,
Aug 8, 2018, 11:23:21 PM8/8/18
to lmfit-py
Ah ok I think I should check the code algoritm and model again!

I'm really appriciate for all you guys helps, advices and recomendation on software..!!  

Regards,
kooktae Kim

2018년 8월 8일 수요일 오후 5시 4분 9초 UTC+9, 김국태 님의 말:
Hello
Reply all
Reply to author
Forward
0 new messages