Closed Alexandra-Wernersson closed 5 years ago
Hi, this is not a fully working example, the variable hc
is undefined. If you want me to test your code, please provide a working example. But you can easily debug this yourself: just print the arguments and the return value of the chiwork
on every call. If it ever returns NaN, then Minuit will stop with all parameters being NaN. There is also a keyword in the Minuit.__init__
to raise an exception if it encounters NaN, see the docs for details.
Your hunch is correct that logs should give trouble if you pass a non-positive value as the argument. It could also be that you divide by zero. Both do not raise an exception when numpy arrays are involved, but in both cases you should get a warning.
PS: Your code would become much more readable if you use the new iminuit.from_array_func interface, which allows you to pass parameters to the objective function as numpy arrays. Then you don't have to spell out all named parameters in your chiwork
function. See the docs for details.
Have added the value of hc now, whenever I add a print(am) in the function all the printed values are just nan's.
Not sure how to use the iminuit.from_array_func if you could spell out and example that would be great.
Thanks for your comment!
Have added the value of hc now, whenever I add a print(am) in the function all the printed values are just nan's.
It is still not a working example. You should try the code you are posting.
NameError: global name 'amssr' is not defined
File "foo.py", line 56, in chiwork
chia=sum((ana-a)**2)+sum((bss*a[betalat]/hc-amssr)**2)
Not sure how to use the iminuit.from_array_func if you could spell out and example that would be great.
See the docs, e.g. the basic tutorial. https://iminuit.readthedocs.io/en/latest/tutorials.html
I assume that this has resolved itself.
Trying to fit some data to a function that I call Ffitr but when running the code below I only get "nan" to all values. The problem lies within the chiaf if you remove if from the return sum the code works. I suspect that it as something to do with the log part of Ffitr but then I think that python should display "invalid value encountered in log". What else could be the reason for minuit settting all parameters to nan?
P.s. sorry that my code is a bit hard to read.