Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NaNs in Cl fix for PolyChord #231

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
9 changes: 7 additions & 2 deletions cobaya/likelihoods/base_classes/cmblikes.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,13 @@ def exact_chi_sq(self, C, Chat, L):
(np.trace(M) - self.nmaps - np.linalg.slogdet(M)[1]))

def logp(self, **data_params):
cls = self.provider.get_Cl(ell_factor=True)
return self.log_likelihood(cls, **data_params)
Cls = self.provider.get_Cl(ell_factor=True)
for Cl_key, Cl_array in Cls.items():
if Cl_key != 'ell':
if np.any(np.isnan(Cl_array)):
self.log.error("nans in Cls['%s']: returning logzero and carrying on." % Cl_key)
return -np.inf
return self.log_likelihood(Cls, **data_params)

# noinspection PyUnboundLocalVariable
def log_likelihood(self, dls, **data_params):
Expand Down
5 changes: 5 additions & 0 deletions cobaya/likelihoods/base_classes/planck_2018_CamSpec_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def chi_squared(self, CT, CTE, CEE, data_params):

def logp(self, **data_params):
Cls = self.provider.get_Cl(ell_factor=True)
for Cl_key, Cl_array in Cls.items():
if Cl_key != 'ell':
if np.any(np.isnan(Cl_array)):
self.log.error("nans in Cls['%s']: returning logzero and carrying on." % Cl_key)
return -np.inf
return -0.5 * self.chi_squared(Cls.get('tt'), Cls.get('te'), Cls.get('ee'),
data_params)

Expand Down
9 changes: 7 additions & 2 deletions cobaya/likelihoods/base_classes/planck_clik.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,13 @@ def get_requirements(self):

def logp(self, **params_values):
# get Cl's from the theory code
cl = self.provider.get_Cl(units="FIRASmuK2")
return self.log_likelihood(cl, **params_values)
Cls = self.provider.get_Cl(units="FIRASmuK2")
for Cl_key, Cl_array in Cls.items():
if Cl_key != 'ell':
if np.any(np.isnan(Cl_array)):
self.log.error("nans in Cls['%s']: returning logzero and carrying on." % Cl_key)
return -np.inf
return self.log_likelihood(Cls, **params_values)

def log_likelihood(self, cl, **params_values):
# fill with Cl's
Expand Down
5 changes: 5 additions & 0 deletions cobaya/likelihoods/base_classes/planck_pliklite.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,10 @@ def chi_squared(self, c_l_arr, calPlanck=1):

def logp(self, **data_params):
Cls = self.provider.get_Cl(ell_factor=True)
for Cl_key, Cl_array in Cls.items():
if Cl_key != 'ell':
if np.any(np.isnan(Cl_array)):
self.log.error("nans in Cls['%s']: returning logzero and carrying on." % Cl_key)
return -np.inf
return -0.5 * self.get_chi_squared(0, Cls.get('tt'), Cls.get('te'), Cls.get('ee'),
data_params[self.calibration_param])