cmbant/getdist

ValueError: 'list' argument must have no negative elements

Closed this issue · 3 comments

I am getting the following error for the shell

# Export the results to GetDist
from getdist.mcsamples import loadMCSamples
# Notice loadMCSamples requires a *full path*
import os

gd_sample = loadMCSamples(os.path.abspath(info_from_yaml["output"]))
# Analyze and plot
mean = gd_sample.getMeans()[:2]
covmat = gd_sample.getCovMat().matrix[:2, :2]
print("Mean:")
print(mean)
print("Covariance matrix:")
print(covmat)
# %matplotlib inline  # uncomment if running from the Jupyter notebook
import getdist.plots as gdplt

gdplot = gdplt.get_subplot_plotter()
gdplot.triangle_plot(gd_sample, ["H0", "Omega_m"], filled=True)

Even the mean and covariance are not real numbers. And the list doesn't have negative values, I checked by opening the .1.txt file. Even the getdist-gui is giving the same error. The quick start example worked fine.

Mean:
[nan nan]
Covariance matrix:
[[nan nan]
 [nan nan]]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [41], in <cell line: 18>()
     15 import getdist.plots as gdplt
     17 gdplot = gdplt.get_subplot_plotter()
---> 18 gdplot.triangle_plot(gd_sample, ["H0", "Omega_m"], filled=True)

File ~/anaconda3/lib/python3.9/site-packages/getdist/plots.py:2432, in GetDistPlotter.triangle_plot(self, roots, params, legend_labels, plot_3d_with_param, filled, shaded, contour_args, contour_colors, contour_ls, contour_lws, line_args, label_order, legend_ncol, legend_loc, title_limit, upper_roots, upper_kwargs, upper_label_right, diag1d_kwargs, markers, marker_args, param_limits, **kwargs)
   2430 marker = self._get_marker(markers, i, param.name)
   2431 self._inner_ticks(ax, False)
-> 2432 xlim = self.plot_1d(roots1d, param, marker=marker, do_xlabel=i == plot_col - 1,
   2433                     no_label_no_numbers=self.settings.no_triangle_axis_labels, title_limit=title_limit,
   2434                     label_right=True, no_zero=True, no_ylabel=True, no_ytick=True, line_args=line_args,
   2435                     lims=param_limits.get(param.name), ax=ax, _ret_range=True, **diag1d_kwargs)
   2436 lims[i] = xlim
   2437 if i > 0:

File ~/anaconda3/lib/python3.9/site-packages/getdist/plots.py:1591, in GetDistPlotter.plot_1d(self, roots, param, marker, marker_color, label_right, title_limit, no_ylabel, no_ytick, no_zero, normalized, param_renames, ax, **kwargs)
   1589 if not root_param:
   1590     continue
-> 1591 bounds = self.add_1d(root, root_param, i, normalized=normalized, title_limit=title_limit if not i else 0,
   1592                      ax=ax, **line_args[i])
   1593 xmin, xmax = self._update_limit(bounds, (xmin, xmax))
   1594 if bounds is not None and not plotparam:

File ~/anaconda3/lib/python3.9/site-packages/getdist/plots.py:972, in GetDistPlotter.add_1d(self, root, param, plotno, normalized, ax, title_limit, **kwargs)
    970         density.normalize(by='max')
    971 else:
--> 972     density = self.sample_analyser.get_density(root, param, likes=self.settings.plot_meanlikes)
    973     if density is None:
    974         return None

File ~/anaconda3/lib/python3.9/site-packages/getdist/plots.py:588, in MCSampleAnalysis.get_density(self, root, param, likes)
    586 density = rootdata.get(key)
    587 if density is None:
--> 588     density = samples.get1DDensityGridData(name, meanlikes=likes)
    589     if density is None:
    590         return None

File ~/anaconda3/lib/python3.9/site-packages/getdist/mcsamples.py:1442, in MCSamples.get1DDensityGridData(self, j, paramConfid, meanlikes, **kwargs)
   1439 width = paramrange / (num_bins - 1)
   1441 bin_indices, fine_width, binmin, binmax = self._binSamples(self.samples[:, j], par, fine_bins)
-> 1442 bins = np.bincount(bin_indices, weights=self.weights, minlength=fine_bins)
   1444 if meanlikes:
   1445     if self.shade_likes_is_mean_loglikes:

File <__array_function__ internals>:5, in bincount(*args, **kwargs)

ValueError: 'list' argument must have no negative elements

image

Look like you have a problem in your chains, e.g. NaNs.

@cmbant I opened the .1.txt and it was fine with normal numbers, there were no NaNs. I re-ran the notebook and this time the plots worked without any problem for some reason.

@cmbant how to print the standard deviation of $H_0$? In the COVMAT matrix, I don't think it is present. From the graph we can get an idea of how large $\sigma$ is but is there anything like gd_sample.getSigma() similar to gd_sample.getMeans()?

Edit: I found it https://getdist.readthedocs.io/en/latest/mcsamples.html?highlight=standard%20deviation#getdist.mcsamples.MCSamples.std . Sorry for asking.