PolyChord / PolyChordLite

Public version of PolyChord: See polychord.co.uk for PolyChordPro
https://polychord.io/
Other
83 stars 26 forks source link

PolyChord crashing while generating live points. #75

Closed Brian-UCD closed 2 years ago

Brian-UCD commented 2 years ago

I've been trying to run PolyChord using my own custom likelihood function, but whenever I run it, python crashes. This is an example of the logs.

Screenshot 2021-08-18 at 11 28 45

From my own investigation, when generating the live points, it looks like the likelihood function is sampled once, and then it crashes with that error. I have also seen this error appear, but I'm not sure if they are related.

Screenshot 2021-08-16 at 18 03 19

If I was to guess, I would think the likelihood function I'm using is too unstable. PolyChord runs perfectly when I use any of the example likelihoods. Any guidance about this error would be greatly appreciated. Thanks.

williamjameshandley commented 2 years ago

Hi @Brian-UCD, it's probable that the issue is occuring due to the fact that nested sampling begins by sampling from the prior, which can result in unusual parameter combinations being tried, and can therefore stress-test code which otherwise appears bug free.

When I'm trying to debug this, I separate out the problem from PolyChord by running:

import numpy as np

def loglikelihood(theta):
    #...

def prior(cube):
    #...

nlive=500
nDims = #...
for _ in range(nlive):
    loglikelihood(prior(np.random.rand(nDims)))

and seeing if that throws any exceptions.

Brian-UCD commented 2 years ago

Thanks for the help. I used this code and my likelihood function was running correctly, its just that as I was not using any derived parameters, I was not returning a tuple from my likelihood function and just the value itself, so it was fixed when I just put a 0 output alongside the loglikelihood.

I.e. originally I had

def loglikelihood(theta): ... return L

def loglikelihood(theta): ... return L, [0]

Now, PolyChord is running perfectly fine. Thanks for the help.