AttributeError: 'MinimizerResult' object has no attribute 'uvars'

169 views
Skip to first unread message

sam mahdi

unread,
Aug 14, 2023, 2:44:47 PM8/14/23
to lmfit-py
I'm trying to get the uncertainty outputs from my fits, but uvars is not working. I can see the uncertainty in .params

>>>min.params
<Parameter 'x', value=5.278888659532299e-09 +/- 1.18e-12, bounds=[0:inf]>

And I can get the value of my solution

>>>min.params['x'].value
5.278888659532299e-09

But I am unable to get my uncertainty associated here. In the docs it says these are stored in uvars, but when attempting to get them out of the MinimizerResult object it doesn't work. I thought maybe I misunderstood the docs wrong and it was in fact in params, but trying that doesn't work either. 

>>>min.uvars
AttributeError: 'MinimizerResult' object has no attribute 'uvars'
>>>min.params['x'].uvars
AttributeError: 'Parameter' object has no attribute 'uvars'

Frederix96

unread,
Aug 14, 2023, 2:53:19 PM8/14/23
to lmfi...@googlegroups.com

Hi Sam Mahdi,

You should be able to find the uncertainty you are looking for from (writing in your naming):

min.params['x'].stderr

as you can read up here as copied from the documentation on https://lmfit.github.io/lmfit-py/parameters.html

Cheers,

Frederic
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/25d0c76d-877d-4b98-84cd-a3b5de107d49n%40googlegroups.com.

Matt Newville

unread,
Aug 14, 2023, 3:11:51 PM8/14/23
to lmfi...@googlegroups.com
Hi Sam,

Oh, it looks like `params.uvars` are automatically created when using Model, but not when using minimize.   We should probably fix that!
Can you raise a Github Issue for this?   I don't expect to have time to look at this for several days.  In the meantime, you can do 

    result = minimize(....)
    if result.covar is not None:
        uvars = result.params.create_uvars(result.covar) 



--
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 view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/25d0c76d-877d-4b98-84cd-a3b5de107d49n%40googlegroups.com.


--
--Matt Newville <newville at cars.uchicago.edu630-327-7411

sam mahdi

unread,
Aug 15, 2023, 8:41:32 PM8/15/23
to lmfit-py
Didn't want to open up another thread, so I'll post this other issue here as well with trying to extract outputs from the minimizer. Trying to print the status (method is least squares), I get an error
>>>min.status
AttributeError: 'MinimizerResult' object has no attribute 'status'

Also thank you Fredrick, I was able to get my error using the stderr in the params. 
Reply all
Reply to author
Forward
0 new messages