CobayaSampler / cobaya

Code for Bayesian Analysis
http://cobaya.readthedocs.io/en/latest/
Other
128 stars 127 forks source link

Getdist getMargeStats not working with cobaya output chains #200

Closed louisl3grand closed 3 years ago

louisl3grand commented 3 years ago

Hi,

I am using getdist to analyse the chains after a MCMC run. The plotting script works well, however I can't get the marginalised uncertainties on the parameters.

I am using cobaya 3.1.1 and getdist 1.3.2

Functions like getMean() or getCovMat() are working, but not getMargeStats(). Here is the error I get when I try to obtain getMargeStats on a MCSamples object I just loaded.


/Users/louis/Code/getdist/getdist/chains.py:443: RuntimeWarning: invalid value encountered in true_divide
  corr /= self.var(paramVec)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-0da3e8665e0b> in <module>
      1 samps = loadMCSamples(rootname)
----> 2 samps.getMargeStats()

~/Code/getdist/getdist/mcsamples.py in getMargeStats(self, include_bestfit)
   2153         :return: A :class:`~.types.MargeStats` instance
   2154         """
-> 2155         self._setDensitiesandMarge1D()
   2156         m = types.MargeStats()
   2157         m.hasBestFit = False

~/Code/getdist/getdist/mcsamples.py in _setDensitiesandMarge1D(self, max_frac_twotail, meanlikes)
   2247         for j in range(self.n):
   2248             paramConfid = self.initParamConfidenceData(self.samples[:, j])
-> 2249             self.get1DDensityGridData(j, paramConfid=paramConfid, meanlikes=meanlikes)
   2250             self._setMargeLimits(self.paramNames.names[j], paramConfid, max_frac_twotail)
   2251 

~/Code/getdist/getdist/mcsamples.py in get1DDensityGridData(self, j, paramConfid, meanlikes, **kwargs)
   1451         if smooth_scale_1D <= 0:
   1452             # Set automatically.
-> 1453             bandwidth = self.getAutoBandwidth1D(bins, par, j, mult_bias_correction_order,
   1454                                                 boundary_correction_order) * (binmax - binmin)
   1455             # for low sample numbers with big tails (e.g. from nested), prevent making too wide

~/Code/getdist/getdist/mcsamples.py in getAutoBandwidth1D(self, bins, par, param, mult_bias_correction_order, kernel_order, N_eff)
   1164         """
   1165         if N_eff is None:
-> 1166             N_eff = self._get1DNeff(par, param)
   1167         h = kde.gaussian_kde_bandwidth_binned(bins, Neff=N_eff)
   1168         bin_range = max(par.param_max, par.range_max) - min(par.param_min, par.range_min)

~/Code/getdist/getdist/mcsamples.py in _get1DNeff(self, par, param)
   1142         N_eff = getattr(par, 'N_eff_kde', None)
   1143         if N_eff is None:
-> 1144             par.N_eff_kde = self.getEffectiveSamplesGaussianKDE(param, scale=par.sigma_range)
   1145             N_eff = par.N_eff_kde
   1146         return N_eff

~/Code/getdist/getdist/chains.py in getEffectiveSamplesGaussianKDE(self, paramVec, h, scale, maxoff, min_corr)
    506         # Shouldn't need more than about correlation length
    507         if maxoff is None:
--> 508             maxoff = int(self.getCorrelationLength(d, weight_units=False) * 1.5) + 4
    509         maxoff = min(maxoff, self.numrows // 10)  # can get problems otherwise if weights are all very large
    510         uncorr_len = self.numrows // 2

ValueError: cannot convert float NaN to integer```
cmbant commented 3 years ago

Are there any NaN in the output? Could you give a zip of the files to reproduce? thanks.

louisl3grand commented 3 years ago

Hi Antony,

It seems the chains have no NaN. Here is the zip file: chains.zip

cmbant commented 3 years ago

Thanks. Think it's related to your exponentially tiny values of sigma8, s8h5 etc.

louisl3grand commented 3 years ago

Thanks a lot for your help @cmbant. It seems the error is on my side. The strange values of sigma8 come from the fact that I have set the option WantTransfer: False in in the cobaya inputs for camb. Without setting this option the ouput sigma8 values are correct.

Cheers, Louis