WARNING:Too few points to create valid contours in EMCEE

429 views
Skip to first unread message

Savin Beniwal

unread,
Jan 31, 2019, 3:06:08 AM1/31/19
to lmfit-py
Hi all,
I'm trying to estimate cosmological parameters using 31 data points of H(z) with the help of emcee. During running this code it shows me many warning as attached to this post. I'm trying to figure it out since last 15 hours but didn't able to fix it.


 ---------------------------------------------CONSOLE OUTPUT-------------------------------------------------------

runfile('/Users/savinbeniwal/.spyder-py3/Varun.py', wdir='/Users/savinbeniwal/.spyder-py3')
/Users/savinbeniwal/.spyder-py3/Varun.py:45: RuntimeWarning: invalid value encountered in sqrt
  model=a*(pow(((b*(1+x)*(1+x)*(1+x))+c+(d*(1+x))+(e*(1+x)*(1+x))),0.5))
/Users/savinbeniwal/.spyder-py3/Varun.py:45: RuntimeWarning: invalid value encountered in sqrt
  model=a*(pow(((b*(1+x)*(1+x)*(1+x))+c+(d*(1+x))+(e*(1+x)*(1+x))),0.5))
/Users/savinbeniwal/.spyder-py3/Varun.py:45: RuntimeWarning: invalid value encountered in sqrt
  model=a*(pow(((b*(1+x)*(1+x)*(1+x))+c+(d*(1+x))+(e*(1+x)*(1+x))),0.5))
/anaconda3/lib/python3.7/site-packages/numpy/core/fromnumeric.py:83: RuntimeWarning: invalid value encountered in reduce
  return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
/anaconda3/lib/python3.7/site-packages/emcee/ensemble.py:335: RuntimeWarning: invalid value encountered in subtract
  lnpdiff = (self.dim - 1.) * np.log(zz) + newlnprob - lnprob0
/anaconda3/lib/python3.7/site-packages/emcee/ensemble.py:336: RuntimeWarning: invalid value encountered in greater
  accept = (lnpdiff > np.log(self._random.rand(len(lnpdiff))))
MCMC result:
    a = -1369.897898955319 +9.501022759650368e-07 -9.764751212060219e-07 
    b = 2322.439710467216 +9.767845767783001e-07 -9.76704541244544e-07 
    c = -1807.4469253751058 +1.0577514331089333e-06 -9.440225312573602e-07 
    d = -2355.596065465344 +9.409864105691668e-07 -1.0935755199170671e-06 
    e = -1693.461209709863 +9.281980055675376e-07 -9.818447779252892e-07 

Mean acceptance fraction=0.0000
 ---------------------------------------------CONSOLE OUTPUT-------------------------------------------------------

But expected results are --->
a~68, 
b~0.3, 
c~0.7,
d~0,
e~0

Please help me. I'm attaching my data file, python code 
Thank you for your reply in advance!!!

With Regards!!!


Hubble_data_31.txt
Varun.py

Renee Otten

unread,
Jan 31, 2019, 8:11:52 AM1/31/19
to lmfi...@googlegroups.com
hi Savin, 


I don’t really understand why you post this question on the lmfit mailing-list; as far as I can tell from your code you actually don’t use the package… If you actually do try to use lmfit, please post code here that shows your efforts.

Having said that, the RuntimeWarnings you get are probably the issue: it’s in your likelihood function, where a combination of variables gives you something that the “sqrt” function doesn’t like.

Good luck, 
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/f2feb519-2949-40ad-8ba7-a4ce6666b13a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<Hubble_data_31.txt><Varun.py>

Matt Newville

unread,
Jan 31, 2019, 9:47:39 AM1/31/19
to lmfit-py
On Thu, Jan 31, 2019 at 2:06 AM Savin Beniwal <darshanb...@gmail.com> wrote:
Hi all,
I'm trying to estimate cosmological parameters using 31 data points of H(z) with the help of emcee. During running this code it shows me many warning as attached to this post. I'm trying to figure it out since last 15 hours but didn't able to fix it.


In your modelig function you have: 

         model=a*(power(((b*(1+x)*(1+x)*(1+x))+c+(d*(1+x))+(e*(1+x)*(1+x))),0.5))

First, reability always counts. Try

        x1 = (x+1)
        model = a*sqrt(b*x1**3 +c + d*x1 + e*x1**2)

Second, neither power() not sqrt() are going to handle negative values well -- they will return Nan, which could easily be the invalid values being complained about.   You will probably need to ensure that the argument to sqrt() is positive.


--Matt

Savin Beniwal

unread,
Jan 31, 2019, 11:03:58 AM1/31/19
to lmfit-py
Thank you, Renee and Matt, for your quick response.
I followed first instruction of Matt. But still facing the same problem.  Even I'm trying to figure out how the arguments of power are becoming negative. But still, I'm clueless. I put arguments in abs, then It gives me no error but gives me same wrong values of parameters. Yeah, this abs technique is completely meaningless for my problem. But I don't know what should I do?

Thanks again!!! 

Matt Newville

unread,
Jan 31, 2019, 3:42:55 PM1/31/19
to lmfit-py
/

On Thu, Jan 31, 2019 at 10:04 AM Savin Beniwal <darshanb...@gmail.com> wrote:
Thank you, Renee and Matt, for your quick response.
I followed first instruction of Matt. But still facing the same problem.  Even I'm trying to figure out how the arguments of power are becoming negative. But still, I'm clueless. I put arguments in abs, then It gives me no error but gives me same wrong values of parameters. Yeah, this abs technique is completely meaningless for my problem. But I don't know what should I do?


Er,  well if `b`, `c`, `d`, or `e` is negative then the argument to `sqrt()` could be negative, right?  Is anything preventing emcee from trying negative values for these parameters? 


Savin Beniwal

unread,
Feb 1, 2019, 12:32:20 AM2/1/19
to lmfit-py
Hi Matt!!
You are absolutely correct, if a,b,c,d,e are negative then arguments of sqrt becomes negative. But in emcee code, I already set prior range for each parameter i.e.  if 50.0 < a < 100 and 0.0 < b < 0.4 and 0.50< c < 1.0 and 0<d<1.0 and -1.0< e < 1.0.
Means during emcee executing the parameters should lie between their range. I may think given this range arguments becomes positive. Am I correct with this statement, Matt?
But I don't know why final results show me the values of each parameter outside from their prior range? I.e. a = -1369.897898955319 means final values should be between these prior ranges.


With Regards!!!

Savin Beniwal

unread,
Feb 3, 2019, 3:06:42 AM2/3/19
to lmfit-py
Hi all
I figure out that what's wrong with this?
My optimisation values of each parameter are outside from their prior range. So there is no accepted point to construct a Markov chain, which gives me values far away from expected values.

Thank you, Matt and Renee!!!!
Reply all
Reply to author
Forward
0 new messages