dfm/emcee

I am getting error Runtime error

Deepeshshrimali opened this issue · 11 comments

[

General information:

  • emcee version: 3.1.1
  • platform: jupyter notebook
  • installation method (pip/conda/source/other?): pip

Problem description: I am getting below error when I am trying to run Emcee in my program.
RuntimeWarning: invalid value encountered in double_scalars
lnpdiff = f + nlp - state.log_prob[j]

Expected behavior:

It should produce curve with proper prior and posterior analysis

Actual behavior:

Prior and posterior is not working. I am getting just initial values only

What have you tried so far?:

I have tried everything possible. I checked the prior values, log functions, initial values but I am not sure how to resolve the issue. I have attached the code. Please help me out with any possible solution

Minimal example:

import emcee

# sample code goes here...
[test -6 - Jupyter Notebook.pdf](https://github.com/dfm/emcee/files/7490751/test.-6.-.Jupyter.Notebook.pdf)

dfm commented

Please post sample code following the principles here: https://stackoverflow.com/help/minimal-reproducible-example
Otherwise there's nothing we can do to help!

dfm commented

There are two issues with your code:

  1. You need a sum in your likelihood function return np.sum(H)
  2. Your initial parameters need to all be within your prior bounds. If you start with the coordinates right on the prior boundary, then add Gaussian noise, you're not going to get valid initial samples. Try setting initial closer to the center of your prior range, or initialize differently somehow.

There are two issues with your code:

  1. You need a sum in your likelihood function return np.sum(H)
  2. Your initial parameters need to all be within your prior bounds. If you start with the coordinates right on the prior boundary, then add Gaussian noise, you're not going to get valid initial samples. Try setting initial closer to the center of your prior range, or initialize differently somehow.

Thanks for looking at my code, I tried both the issues which you mentioned and re run the code. I am still having same issue, by changing the initial value, initial value in emcee curve changes but plot remain same and still I am getting below error
image

dfm commented

Then you didn't fix your initialization, because that's what it means!

Then you didn't fix your initialization, because that's what it means!

I fixed my initialization by using the scipy. optimize (see below), now I am using only these values to initialize not any random values , but still the problem remains the same
image

dfm commented

#409 (comment)

👆

All your initial samples need to be within bounds and there's no guarantee that scipy will return valid parameters (depending on how you initialize it and implement bounds). Your screenshot doesn't provide enough information for me to give suggestions, so all I can say is that you should double-check your initialization. Similarly, you must provide some randomization of the initial values - they can't all be at the same position or your ensemble will never move.

#409 (comment)

👆

All your initial samples need to be within bounds and there's no guarantee that scipy will return valid parameters (depending on how you initialize it and implement bounds). Your screenshot doesn't provide enough information for me to give suggestions, so all I can say is that you should double-check your initialization. Similarly, you must provide some randomization of the initial values - they can't all be at the same position or your ensemble will never move.

Thanks for all your suggestions, when I am checking my initials samples provided by the scipy they are in the bound of the prior values defined so it means it is giving correct initial values, but I am not sure what do you mean by randomization of the initial values??

dfm commented

Thanks for all your suggestions, when I am checking my initials samples provided by the scipy they are in the bound of the prior values defined so it means it is giving correct initial values

I'm sorry, but this this is definitely not true, because you're getting that runtime warning on the initial proposal! In your minimal example from before, it was very easy to get rid of that warning by choosing sensible starting parameters. If you really believe that there is an emcee bug, please try to make a new minimal example that reproduces the issue, but in the meantime, I'm going to close this issue because there's not much else I can do here. Feel free to reopen once you've isolated the issue.

I am not sure what do you mean by randomization of the initial values

The walkers always move along vectors connecting them to another walker. So if all the walkers start on top of each other they'll never move since the vectors are all identically zero. I normally enforce this (in my work and in all the tutorials) by scatting the walkers randomly near their starting point, but if you have a different procedure for making sure that they are starting at different locations then that is fine!

dfm commented

PS. Conceptual issues and questions about modeling are better addressed to the mailing list that you can find here: https://groups.google.com/forum/#!forum/emcee-users So that might be a better place to re-raise this once you've isolated the issue more clearly.

Thanks for all your suggestions, when I am checking my initials samples provided by the scipy they are in the bound of the prior values defined so it means it is giving correct initial values

I'm sorry, but this this is definitely not true, because you're getting that runtime warning on the initial proposal! In your minimal example from before, it was very easy to get rid of that warning by choosing sensible starting parameters. If you really believe that there is an emcee bug, please try to make a new minimal example that reproduces the issue, but in the meantime, I'm going to close this issue because there's not much else I can do here. Feel free to reopen once you've isolated the issue.

I am not sure what do you mean by randomization of the initial values

The walkers always move along vectors connecting them to another walker. So if all the walkers start on top of each other they'll never move since the vectors are all identically zero. I normally enforce this (in my work and in all the tutorials) by scatting the walkers randomly near their starting point, but if you have a different procedure for making sure that they are starting at different locations then that is fine!

Yes you were right, my scipy was taking the values outside the prior range so it is not trustable method. The minimal example which I provided is working fine now and it is producing very good emcee curve. But the actual code , which I am working still not working. I clearly understand the problem is initialization and I have 7 parameters. I am not sure what is the best method to initialize, I have tried trail and error and scipy minimize but both are not working. and there is no end of trail and error method
image

image