baudren / montepython_public

Public repository for the Monte Python Code
MIT License
65 stars 115 forks source link

ValueError: Contour levels must be increasing #85

Open carlosggarcia opened 7 years ago

carlosggarcia commented 7 years ago

When computing 2d plots I normally find the error ValueError: Contour levels must be increasing, which crashes MontePython leaving me without plots.

I think the cause is that newer versions of matplotlib promoted the previous message from Warning to ValueError, since in analyze.py there is an except Warning and from the matplotlib file /usr/lib64/python2.7/site-packages/matplotlib/contour.p

if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
            if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
                warnings.warn("Contour levels are not increasing")
            else:
                raise ValueError("Contour levels must be increasing")

The solution I have worked out (https://github.com/ardok-m/montepython_zuma/commit/9674a286acade1cd936d6b2b70b6e2f2cbafff85) is adding an except ValueError to handle it. This way I am able to obtain my 2d plots.

brinckmann commented 7 years ago

Hi, Do you find that this only happens when your chains are not converged, or also when they are well converged? I would expect the former. Regards, Thejs

carlosggarcia commented 7 years ago

Hi, I find this error when my chains go to a really small region of the parameter space for some parameters. In fact, trying to make a w_a-w_0 plot I saw that around 95% of my data (nearly 80000 points) fall into a single bin. This is the output of MontePython. I think the chains converged, at least for some parameters, but I might be misunderstanding something.

--> Computing convergence criterium (Gelman-Rubin)
 -> R-1 is 0.131220     for  omega_cdm
           0.002663     for  H0
           0.426214     for  omega_b
           0.339620     for  parameters_smg__2
           0.339667     for  parameters_smg__3
           0.339667     for  w0_smg
           0.000091     for  wa_smg
           0.007193     for  tuning_parameter

Thanks

borisbolliet commented 7 years ago

Hi Ardok,

Your chains did not converge, you need R-1<0.01 for all parameters. It seems your input covariance matrix is inappropriate because R-1 is too small for w_a compared to the other parameters.

The error you get, that you reported in your first message, is generally due to the fact that you ask for contours for parameters that are not varying (maybe wa_smg?). To avoid this error you can write a file 'extra.plot' in which you ask to plot only the varying parameters. Then use the 'info' command with the --extra option, e.g.:

$ Montepython.py info blabla/*.txt --extra extra.plot

I refer to the montepython documentation for further details on this point.

I hope this helps, Boris

carlosggarcia commented 7 years ago

Hi, Thank you for the explanation, I thought one could talk of the convergence in some parameters, although the chain had not "converged" for all of them. I was using an extra.plot file until now but thought it could be convenient to handle the error properly since I found it quite normally for different models I am studying. The 2d plot I get this way leave blank the figures that complain but compute all the others. In fact, this way the w_a row is completely plotted with the only exception of the w_a-w_0 figure.

Thank you all again!