Emcee with gaussian prior gives NaN

I’ve been using emcee to sampel my parameter, at first my prior were all uniform

def logprior_BAO(theta): A, B, C, D, epsilon, rd = theta if A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5 and 146.96<=rd<=147.58:     return 0.0 return -np.inf 

and it work perfectly fine. then, I change the rd prior to Gaussian,

def logprior_BAO(theta): A, B, C, D, epsilon, rd = theta #flat priors  if not A > 0 and B > 0 and C > 0 and D > 0 and epsilon > -5:     return -np.inf #gaussian prior rd mu = 147.27 sigma = 0.31 return np.log(1.0/(np.sqrt(2*np.pi)*sigma))-0.5*(rd-mu)**2/sigma**2 

and the program gives me this error

ValueError                                Traceback (most recent call last) <ipython-input-9-b9ee20e97036> in <module>       3 move = emcee.moves.StretchMove(a=a_parameter)       4 sampler = emcee.EnsembleSampler(nwalker, ndims, logposterior,args=argslist, moves=move) ----> 5 sampler.run_mcmc(initial, nsteps, progress=True)  ~\anaconda3\lib\site-packages\emcee\ensemble.py in run_mcmc(self, initial_state, nsteps, **kwargs)     382      383         results = None --> 384         for results in self.sample(initial_state, iterations=nsteps, **kwargs):     385             pass     386   ~\anaconda3\lib\site-packages\emcee\ensemble.py in sample(self, initial_state, log_prob0, rstate0, blobs0, iterations, tune, skip_initial_state_check, thin_by, thin, store, progress)     283             state.blobs = blobs0     284         if state.log_prob is None: --> 285             state.log_prob, state.blobs = self.compute_log_prob(state.coords)     286         if np.shape(state.log_prob) != (self.nwalkers,):     287             raise ValueError("incompatible input dimensions")  ~\anaconda3\lib\site-packages\emcee\ensemble.py in compute_log_prob(self, coords)     454         # Check for log_prob returning NaN.     455         if np.any(np.isnan(log_prob)): --> 456             raise ValueError("Probability function returned NaN")     457      458         return log_prob, blob  ValueError: Probability function returned NaN 

Could anybody tell me why this is happening, and how to fix it? I will appreciate your answer, thanks

Asked on July 16, 2020 in Python.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.