Skip to content

Commit

Permalink
ENH allow all kinds of covariances (#104)
Browse files Browse the repository at this point in the history
* ENH allow all kinds of covariances

* TST remove outdated tests
  • Loading branch information
beckermr authored Apr 2, 2020
1 parent 264aa3d commit 25d7162
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 38 deletions.
7 changes: 1 addition & 6 deletions firecrown/ccl/likelihoods/gaussian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import scipy.linalg
import sacc

from ..core import LogLike

Expand Down Expand Up @@ -42,10 +41,6 @@ def read(self, sacc_data, sources, statistics):
A dictionary mapping statistics to their objects. These statistics do
not have to have been rendered.
"""
if not isinstance(sacc_data.covariance, sacc.covariance.FullCovariance):
raise RuntimeError(
"Currently, the SACC covariance must be a 'FullCovariance'. "
"This may change in a future firecrown release.")
_sd = sacc_data.copy()
inds = []
for stat in self.data_vector:
Expand All @@ -58,7 +53,7 @@ def read(self, sacc_data, sources, statistics):
cov = np.zeros((len(inds), len(inds)))
for new_i, old_i in enumerate(inds):
for new_j, old_j in enumerate(inds):
cov[new_i, new_j] = _sd.covariance.covmat[old_i, old_j]
cov[new_i, new_j] = _sd.covariance.dense[old_i, old_j]
self.cov = cov
self.cholesky = scipy.linalg.cholesky(self.cov, lower=True)

Expand Down
7 changes: 1 addition & 6 deletions firecrown/ccl/likelihoods/tdist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import numpy as np
import scipy.linalg
import sacc

from ..core import LogLike

Expand Down Expand Up @@ -50,10 +49,6 @@ def read(self, sacc_data, sources, statistics):
A dictionary mapping statistics to their objects. These statistics do
not have to have been rendered.
"""
if not isinstance(sacc_data.covariance, sacc.covariance.FullCovariance):
raise RuntimeError(
"Currently, the SACC covariance must be a 'FullCovariance'. "
"This may change in a future firecrown release.")
_sd = sacc_data.copy()
inds = []
for stat in self.data_vector:
Expand All @@ -66,7 +61,7 @@ def read(self, sacc_data, sources, statistics):
cov = np.zeros((len(inds), len(inds)))
for new_i, old_i in enumerate(inds):
for new_j, old_j in enumerate(inds):
cov[new_i, new_j] = _sd.covariance.covmat[old_i, old_j]
cov[new_i, new_j] = _sd.covariance.dense[old_i, old_j]
self.cov = cov
self.cholesky = scipy.linalg.cholesky(self.cov, lower=True)

Expand Down
13 changes: 0 additions & 13 deletions firecrown/ccl/likelihoods/tests/test_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

from ..gaussian import ConstGaussianLogLike

Expand Down Expand Up @@ -34,15 +33,3 @@ def test_likelihood_gaussian_subset(likelihood_test_data):
cov = likelihood_test_data['cov'][0:4, 0:4]
loglike = -0.5 * np.dot(delta, np.dot(np.linalg.inv(cov), delta))
assert np.allclose(loglike, ll.compute(data, theory))


def test_likelihood_gaussian_raises(likelihood_test_data):
ll = ConstGaussianLogLike(data_vector=["stat_src0_src0", "stat_src0_src1"])
sd = likelihood_test_data['sacc_data'].copy()
sd.covariance = 10
with pytest.raises(RuntimeError) as e:
ll.read(
sd,
likelihood_test_data['sources'],
likelihood_test_data['statistics'])
assert 'FullCovariance' in str(e)
13 changes: 0 additions & 13 deletions firecrown/ccl/likelihoods/tests/test_tdist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
import pytest

from ..tdist import TdistLogLike

Expand Down Expand Up @@ -42,15 +41,3 @@ def test_likelihood_tdist_subset(likelihood_test_data):
chi2 = np.dot(delta, np.dot(np.linalg.inv(cov), delta))
loglike = -0.5 * nu * np.log(1.0 + chi2 / (nu - 1.0))
assert np.allclose(loglike, ll.compute(data, theory))


def test_likelihood_tdist_raises(likelihood_test_data):
ll = TdistLogLike(data_vector=["stat_src0_src0", "stat_src0_src1"], nu=10)
sd = likelihood_test_data['sacc_data'].copy()
sd.covariance = 10
with pytest.raises(RuntimeError) as e:
ll.read(
sd,
likelihood_test_data['sources'],
likelihood_test_data['statistics'])
assert 'FullCovariance' in str(e)

0 comments on commit 25d7162

Please sign in to comment.