Skip to content

Dynesty failing due to `idxs` not behaving as expected

In !208 (merged), @colm.talbot you added this line

idxs = [np.unique(np.where(self.result.samples[ii] == out.samples)[0])
                for ii in range(len(out.logl))]

Firstly, if you look at which this produces, it is a little strange, e.g. here is the sample output:

>>> print(idxs)
...
 array([1983]),
 array([1984]),
 array([1984]),
 array([1984]),
 ...]

This can be easily solved by a np.array(idxs) call.

Second, in a certain case I'm getting an IndexError: only integers, slices (:), ellipsis (), numpy.newaxis (None) and integer or boolean arrays are valid indices message. This is caused by the call

self.result.log_likelihood_evaluations = out.logl[idxs]

The issue is that the idxs previously calculated appear to have multiple matches, e.g., it looks like this

>>> print(idxs)
...
 array([12674]),
 array([5276, 12675]),
 array([5276, 12675]),
 array([12676]),
 array([12676]),
 ...]

It seems the call self.result.samples[ii] == out.samples is finding more than one match. Perhaps this is because the posterior is so narrow it has reached computer precision and samples are being repeated, I'm not sure.

I'm not sure how to solve this at the moment, or if it will be a problem beyond my singular case. I'm afraid it isn't possible to make a simpler minimum working example out of it at the moment.