Skip to content

Commit

Permalink
Fixing requisites for bao generic with different kinds of observables (
Browse files Browse the repository at this point in the history
…#344)

* Correcting requisites for bao generic with different kinds of observables

* Fixing a typo, adding whitespaces

* Adding a simple test for bao.generic with mixed observables and fixing a bug in bao base_class for inversion of covariance matrix with only one observable.

* Updating bao_data's github release to v2.3
  • Loading branch information
Kushallodha committed Jan 9, 2024
1 parent ea587ce commit 62e1ca8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cobaya/likelihoods/base_classes/bao.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class BAO(InstallableLikelihood):
type = "BAO"

install_options = {"github_repository": "CobayaSampler/bao_data",
"github_release": "v2.2"}
"github_release": "v2.3"}

prob_dist_bounds: Optional[Sequence[float]]
measurements_file: Optional[str] = None
Expand Down Expand Up @@ -326,14 +326,14 @@ def initialize(self):
self.cov = np.loadtxt(os.path.join(data_file_path, self.cov_file))
elif self.invcov_file:
invcov = np.loadtxt(os.path.join(data_file_path, self.invcov_file))
self.cov = np.linalg.inv(invcov)
self.cov = np.linalg.inv(np.atleast_2d(invcov))
elif "error" in self.data.columns:
self.cov = np.diag(self.data["error"] ** 2)
else:
raise LoggedError(
self.log, "No errors provided, either as cov, invcov "
"or as the 3rd column in the data file.")
self.invcov = np.linalg.inv(self.cov)
self.invcov = np.linalg.inv(np.atleast_2d(self.cov))
except IOError:
raise LoggedError(
self.log, "Couldn't find (inv)cov file '%s' in folder '%s'. " % (
Expand Down Expand Up @@ -396,8 +396,15 @@ def get_requirements(self):
obs_used_not_implemented, list(theory_reqs))
requisites = {}
if self.has_type:
for obs in self.data["observable"].unique():
requisites.update(theory_reqs[obs])
for observable in self.data["observable"].unique():
for req, req_values in theory_reqs[observable].items():
if req not in requisites.keys():
requisites[req] = req_values
else:
if isinstance(req_values, dict):
for k, v in req_values.items():
if v is not None:
requisites[req][k] = np.unique(np.concatenate((requisites[req][k], v)))
return requisites

def theory_fun(self, z, observable):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cosmo_bao.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ def test_generic_camb(packages_path, skip_not_installed):
body_of_test(packages_path, best_fit, info_likelihood, info_theory,
chi2_generic, skip_not_installed=skip_not_installed)

# Test generic bao class with different kind of observables
def test_generic_mixed_camb(packages_path, skip_not_installed):
like = "bao.sdss_dr12_consensus_bao"
like_rename = "bao_mixed_observables"
chi2_generic = deepcopy(chi2_sdss_dr12_consensus_bao)
chi2_generic.pop(like)
chi2_generic[like_rename] = 5.0
likelihood_defaults = get_component_class(like).get_defaults()
likelihood_defaults.pop("path")
likelihood_defaults["class"] = "bao.generic"
likelihood_defaults['measurements_file'] = 'bao_data/test_bao_mixed_observables_mean.txt'
likelihood_defaults['cov_file'] = 'bao_data/test_bao_mixed_observables_cov.txt'
likelihood_defaults['rs_fid'] = 1.0
info_likelihood = {like_rename: likelihood_defaults}
info_theory = {"camb": None}
body_of_test(packages_path, best_fit, info_likelihood, info_theory,
chi2_generic, skip_not_installed=skip_not_installed)


def test_sdss_dr16_consensus_baoplus_lrg_camb(packages_path, skip_not_installed):
like = "bao.sdss_dr16_baoplus_lrg"
Expand Down

0 comments on commit 62e1ca8

Please sign in to comment.