UltraNest
UltraNest copied to clipboard
ValueError: weights do not sum to 1 (1)
- UltraNest version: 3.4.4
- Python version: 3.10.4
- Operating System: Archlinux - 5.16.16-arch1-1
Description
After successfully finishing a fit with the BXA tool, ultranest seems to have some error when plotting the final results.
What I Did
I have managed to successfully run BXA with no problems before this, so I am not sure how to resolve the error. Traceback seems to have an issue with ultranest (not BXA), thus posting the error report here.
[ultranest] Explored until L=-8e+06 15..-7707717.39 [-7707718.1475..-7707718.1473]*| it/evals=11280/87298 eff=inf% N=400
[ultranest] Likelihood function evaluations: 87298
[ultranest] Writing samples and results to disk ...
[ultranest] Writing samples and results to disk ... done
[ultranest] logZ = -7.708e+06 +- 0.124
[ultranest] Posterior uncertainty strategy is satisfied (KL: 0.46+-0.06 nat, need <0.50 nat)
[ultranest] Evidency uncertainty strategy is satisfied (dlogz=0.12, need <0.5)
[ultranest] logZ error budget: single: 0.22 bs:0.12 tail:0.01 total:0.12 required:<0.50
[ultranest] done iterating.
logZ = -7707741.617 +- 0.311
single instance: logZ = -7707741.617 +- 0.223
bootstrapped : logZ = -7707741.573 +- 0.311
tail : logZ = +- 0.010
insert order U test : converged: True correlation: inf iterations
kT : 0.1004│ ▁▁▁▁▁▂▂▃▄▄▅▆▆▇▆▅▅▃▃▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ │0.1225 0.1085 +- 0.0026
log(norm) : -6.482│ ▁▁▁▁▁▁▁▁▁▂▃▃▄▅▆▇▇▇▇▇▆▅▅▃▃▂▁▁▁▁▁▁▁▁ ▁▁ │-6.352 -6.420 +- 0.015
kT : 0.1800│▇▆▅▅▃▃▃▂▃▂▂▂▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▁ │0.1949 0.1823 +- 0.0020
log(norm) : -6.093│ ▁ ▁▁▁▁▁ ▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▃▃▄▅▅▆▆▇▇▇▇▇▆│-6.000 -6.016 +- 0.012
kT : 0.600 │▁▂▂▂▂▂▃▄▅▅▆▆▆▇▇▇▆▆▅▅▄▄▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁ │0.885 0.706 +- 0.044
log(norm) : -7.665│ ▁ ▁▁▁▁▁▁▁▁▁▁▁▂▂▃▃▄▅▆▆▇▇▇▇▅▄▂▁▁▁▁ │-7.174 -7.323 +- 0.050
log(norm) : -6.1669│ ▁▁ ▁▁▁▁▁▁▂▂▃▃▄▅▆▆▇▇▇▆▆▅▄▄▂▂▂▁▁▁▁▁▁▁▁▁ │-6.1365 -6.1518 +- 0.0038
Traceback (most recent call last):
File "/home/jpbreuer/Scripts/filament_cxb_bxa_akaike/bxa_cxb_allktfree_034-7_wgalactic_ridge_tight_2nd.py", line 378, in <module>
results = solver.run(resume=True)
File "/home/jpbreuer/.local/lib/python3.10/site-packages/bxa/xspec/solver.py", line 188, in run
self.results = solve(
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/solvecompat.py", line 79, in pymultinest_solve_compat
sampler.plot()
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/integrator.py", line 2755, in plot
self.plot_run()
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/integrator.py", line 2821, in plot_run
runplot(results=self.run_sequence, logplot=True)
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/plot.py", line 269, in runplot
wt_kde = gaussian_kde(resample_equal(-logvol, weights)) # KDE
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/utils.py", line 184, in resample_equal
raise ValueError("weights do not sum to 1 (%g)" % np.sum(weights))
ValueError: weights do not sum to 1 (1)
Edit: Running with different priors for a different fit results in similar errors.
[ultranest] Explored until L=-8e+06 83..-7707715.33 [-7707715.8265..-7707715.8251]*| it/evals=12791/1025647 eff=8.7000% N=400
[ultranest] Likelihood function evaluations: 1025647
[ultranest] Writing samples and results to disk ...
[ultranest] Writing samples and results to disk ... done
[ultranest] logZ = -7.708e+06 +- 0.145
[ultranest] Posterior uncertainty strategy is satisfied (KL: 0.47+-0.04 nat, need <0.50 nat)
[ultranest] Evidency uncertainty strategy is satisfied (dlogz=0.15, need <0.5)
[ultranest] logZ error budget: single: 0.25 bs:0.15 tail:0.01 total:0.15 required:<0.50
[ultranest] done iterating.
logZ = -7707743.059 +- 0.191
single instance: logZ = -7707743.059 +- 0.247
bootstrapped : logZ = -7707743.101 +- 0.191
tail : logZ = +- 0.010
insert order U test : converged: True correlation: inf iterations
kT : 0.0836│ ▁ ▁▁▁▁▁▁▁▁▂▂▄▆▆▆▇▇▇▇▇▅▄▃▂▂▁▁▁▁▁▁▁▁▁ ▁ │0.1186 0.1005 +- 0.0037
log(norm) : -6.505│ ▁ ▁▁▁▁▁▁▁▁▂▂▂▃▄▅▆▇▆▇▆▆▆▅▄▃▃▂▁▁▁▁▁▁▁▁▁ │-6.369 -6.433 +- 0.016
kT : 0.1535│ ▁ ▁▁▁▁▁▁▁▁▂▃▄▆▇▇▇▆▄▄▄▄▄▄▃▃▂▁▁▁▁▁▁▁▁▁▁ │0.1882 0.1704 +- 0.0039
log(norm) : -6.010│ ▁ ▁▁▁▁▁▁▁▂▂▃▄▄▅▆▆▇▇▇▇▇▅▄▃▂▁▁▁▁▁▁ ▁ ▁ │-5.819 -5.916 +- 0.020
kT : 0.500 │▃▂▃▃▃▃▃▄▄▄▅▅▇▆▇▇▇▇▇▆▆▅▄▄▃▂▂▂▁▁▁▁▁▁▁▁▁▁▁│0.800 0.614 +- 0.053
log(norm) : -7.442│ ▁▁▁ ▁▁▁▁▁▁▁▁▂▂▃▃▄▄▅▆▆▇▇▇▇▅▄▃▂▁▁▁▁▁▁ ▁ │-6.931 -7.150 +- 0.058
log(norm) : -6.1331│ ▁▁ ▁▁▁▁▁▁▂▂▃▃▄▅▆▇▇▇▇▆▆▅▅▃▂▂▁▁▁▁▁▁ ▁▁ │-6.1008 -6.1163 +- 0.0038
Traceback (most recent call last):
File "/home/jpbreuer/Scripts/filament_cxb_bxa_akaike/bxa_cxb_allktfree_034-7_wgalactic_ridge.py", line 378, in <module>
results = solver.run(resume=True)
File "/home/jpbreuer/.local/lib/python3.10/site-packages/bxa/xspec/solver.py", line 188, in run
self.results = solve(
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/solvecompat.py", line 79, in pymultinest_solve_compat
sampler.plot()
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/integrator.py", line 2755, in plot
self.plot_run()
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/integrator.py", line 2821, in plot_run
runplot(results=self.run_sequence, logplot=True)
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/plot.py", line 269, in runplot
wt_kde = gaussian_kde(resample_equal(-logvol, weights)) # KDE
File "/home/jpbreuer/.local/lib/python3.10/site-packages/ultranest/utils.py", line 184, in resample_equal
raise ValueError("weights do not sum to 1 (%g)" % np.sum(weights))
ValueError: weights do not sum to 1 (1)
Can you have a look at the run.txt file in chains/?
The actual error occurs when calling sampler.plot_run() (usually from sampler.plot()).
It is complaining about sampler.run_sequence['weights']
I think the issue is that you have such extremely large negative values: logZ = -7707741.617
, and this lead to rounding errors.
Probably something went very wrong in the model setup, and it is a very bad fit. Make some plots / prior predictive checks.
Please reopen if this is still an issue after addressing the extremely large negative log-likelihood issue.