How to initialize parameters in emcee

36 views
Skip to first unread message

Deepesh S

unread,
Nov 7, 2021, 2:50:51 PM11/7/21
to emcee users
Hello All, 

I am working on physics problem and I am trying to do prior and posterior analysis. I am getting run time errors while executing the code. (attached PDF and notebook). The main reason behind is the proper initialization of the parameters. I have 7 parameters and I have tried trail and error and scipy optimization but both are not providing any correct result and there is no end of trail and error method so what would be the best method to initiate the parameters.

Thanks in advance.

Deepesh 


test -6.ipynb
test -6 - Jupyter Notebook.pdf

Brian Blais

unread,
Nov 8, 2021, 7:46:23 AM11/8/21
to emcee users
One thing I notice is that your functions aren't well defined for certain parameter values.  for example, you have in your A=[lots of stuff] something with (((-c)/(a1))**(1/2)) which means that a1 has to be positive (if c is a positive constant), or you'll end up with imaginary values. figure out what the defined ranges for your parameters are as a first step!

hope this helps,

Brian Blais

Deepesh S

unread,
Nov 8, 2021, 1:38:55 PM11/8/21
to emcee users
Hello Brian, 

Thanks for looking at my code, 

you are right about the imaginary numbers but those are the actual physics formulas and in the code I have only taken those values for which sq root is defined and ignored all of the other values. I have already figured out what is the defined range of my parameters. Only thing I am not able to figure out is how to take initial values. Let me know if you have idea about that.

Thanks 

Deepesh 

Dan Foreman-Mackey

unread,
Nov 9, 2021, 10:52:07 AM11/9/21
to Deepesh S, emcee users
Hi Deepesh,
Brian is exactly right! Try printing out your "X" variable, and you'll see that some of the entries are NaN. This means that your log likelihood will also always be NaN. The issue is not with the initialization, but with the model itself, so you'll want to do some debugging there.
Best,
Dan

--
You received this message because you are subscribed to the Google Groups "emcee users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emcee-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emcee-users/8357a6b3-0777-4cd6-831c-3b8b3e08ae4en%40googlegroups.com.


--
Dan Foreman-Mackey
Associate Research Scientist
Flatiron Institute

Deepesh S

unread,
Nov 9, 2021, 11:06:00 AM11/9/21
to Dan Foreman-Mackey, emcee users
Hello Dan, 

Thanks for looking into this. I printed my "X" and it is giving the below result and none of them are "nan". I have already removed those points that give imaginary values . Still I have the same issues with my emcee curves. Let me know if you still think I am making some mistake in defining "X". 

image.png


Thanks 
Deepesh Shrimali

Dan Foreman-Mackey

unread,
Nov 9, 2021, 11:21:08 AM11/9/21
to Deepesh S, emcee users
Your method definitely doesn't work because this is what I get when I run your notebook!:

Screen Shot 2021-11-09 at 11.19.08 AM.png

Also: I expect that given the units here, you're going to have a lot of numerical issues (your parameters are order 10^5 and you're trying to fit data of order 10^-12) so you might want to also think about the feasibility of what you're doing!


Deepesh S

unread,
Nov 9, 2021, 11:57:41 AM11/9/21
to Dan Foreman-Mackey, emcee users
Yes Dan, 

You are right, I changed my coding after my 1st mail to eliminate the "nan" values from my X, now the code is not producing any "nan" even if we generate 10,000 points. But still the same issue.  Please find the attached code for your reference. 

Regarding the last point about the numerical issues, I understood your concern and it is making sense to me. I need to look more into it, once my code is running perfectly.

Thanks a lot. 

Deepesh 


test -6.ipynb
Reply all
Reply to author
Forward
0 new messages