Closed shan1525 closed 2 years ago
try:
u = np.random.uniform(size=len(param_names))
params = my_prior_transform(u)
print("params", params) # look whether the parameters are reasonable
l = my_likelihood(params)
print("likelihood:", l)
do this for several times until you hit the nan. Then figure out why this happens.
Thank you so much @JohannesBuchner for your prompt reply. I will try your suggestion and see what happens. I will update about it. I truly appreciate your help.
Dear @JohannesBuchner , Thanks for the earlier suggestion. It helped me to check the parameter values where the likelihood is giving nan. So , I realised that one of the parameters which I set to be negative is going positive, and for the positive value of that parameter , the likelihood is coming nan. To be more clear to you I set priors for params[3] to be [-6,0] , which I did like this
params[3] = cube[3] 5.999-6 ###is it right to write like this?
But it is coming positive in some cases see here params [ 0.46020096 2.83666804 1.89530621 1.5965133 0.74369123 148.30793771 -18.61855001].(the bold one is positive)
likelihood: nan
Have I wrongly given the priors ? I can't comprehend why is this going positive, where I have set this to negative.
Please, help me through this. I really appreciate your help.
With the best regards,
shan.
Update:
When I set the priors to be like this :
params[3] = cube[3] 6-6
I get a different error where the likelihood is not nan but this kind of error pops up,
[ultranest] Explored until L=-7e+02
[ultranest] Likelihood function evaluations: 400
Traceback (most recent call last):
File "ultra_nest.py", line 169, in
Please help.
Have I wrongly given the priors ?
Yes
I can't comprehend why is this going positive, where I have set this to negative.
cube contains values between 0 and 1. Just mentally place these values in, then you will see what values params can yield.
I get a different error where the likelihood is not nan but this kind of error pops up,
Using the code I posted above, have a look at several likelihood values of random points. Perhaps they are all equal?
Here are instructions on how to format code on github to be easily readable: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax
Here are instructions on how to format code on github to be easily readable.
I am really sorry. I didn't write in this manner and made my query difficult to read. I will keep this in mind while raising an issue. And thanks for helping me with your suggestions.
regarding the assertion error.
I will check manually about the likelihoods. Thanks for your help.
with the best regards, shan.
Dear @JohannesBuchner ,
I played around with the params. And checked manually with your code . The likelihood is not coming nan. But I am getting new kind of assertion error like this
[ultranest] Explored until L=-3e+03
[ultranest] Likelihood function evaluations: 400 Traceback (most recent call last): File "ultra_nest.py", line 169, inresult = sampler.run() File "/home/shanno/.local/lib/python3.6/site-packages/ultranest/integrator.py", line 2184, in run region_class=region_class, File "/home/shanno/.local/lib/python3.6/site-packages/ultranest/integrator.py", line 2536, in run_iter self._update_results(main_iterator, saved_logl, saved_nodeids) File "/home/shanno/.local/lib/python3.6/site-packages/ultranest/integrator.py", line 2634, in _update_results main_iterator, mpi_comm=self.comm if self.use_mpi else None) File "/home/shanno/.local/lib/python3.6/site-packages/ultranest/netiter.py", line 910, in combine_results assert np.isclose(w.sum() - 1, 0), w.sum() AssertionError: nan
If you don't mind. Can you please , tell me what could be the problem? I am sorry for bothering you with these naive questions.
regard, shan.
Huh, I have not seen this before. Not sure how w
can end up having NaNs here https://github.com/JohannesBuchner/UltraNest/blob/master/ultranest/netiter.py#L910
Dear @JohannesBuchner ,
I found out the solution to my problem. As it was mentioned in #5 , I averted the nan
errors by defining my log_likelihood
as :
def log_likelihood(params):
Om0, w, wa, CC, h, rd, M = params
ll = lnlike(Om0, w, wa, CC, h, rd, M)
if np.isnan(ll):
return -1e300
else:
return ll
I think that numpy.sqrt()
was creating the assertion error trouble , because I was getting the following errors before the assertion error :
[ultranest] Sampling 400 live points from prior ... /home/shanno/Desktop/New_work/cosmo.py:405: RuntimeWarning: invalid value encountered in sqrt return np.sqrt(a+b*(1.+z)*3.+c(1.+z)*4) /home/shanno/Desktop/New_work/cosmo.py:101: IntegrationWarning: The occurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated. return self.D_H()quad(self.invhub, 0, z1)[0] /home/shanno/.local/lib/python3.6/site-packages/numpy/lib/function_base.py:2192: RuntimeWarning: invalid value encountered in ? (vectorized) outputs = ufunc(*inputs) .
I am very grateful of you for your invaluable suggestions regarding the queries. Thank you so much for your fast and prompt replies. It helped me a lot to understand the problem. I am closing the issue now as it has been resolved.
With the best regards, shan.
Description
Dear @JohannesBuchner ,
I hope you are healthy and doing good. I am using your amazing program to marginalize my model parameters through the chi^2 of observed and theory parameters.
What I Did
firstly, I defined one of the chi^2 as
and some other chi2 . Then I calculated the total chi^2. after that I defined the priors as this,
and then I defined the loglike like this
where
lnlike = -0.5*chi2(Om0, w, wa, CC, h, rd, M)
Then I run it with the commandBut I get the assertion error, where the log likelihood is coming to be nan for some combinations of the parameter space. The error is like this,
I think this may be the problem where I give the priors in my_prior_transform. I may have wrongly given the priors for (-6,0). Please, guide me through this. That will be very helpful to me. Thanks in advance. Please, don't mind if the question is too trivial. I am still learning.
With the best regards, shan.