Skip to content

Commit

Permalink
Merge pull request #12 from joezuntz/single_gaussian_fisher_fix
Browse files Browse the repository at this point in the history
Single gaussian fisher fix
  • Loading branch information
joezuntz authored Apr 29, 2022
2 parents 679af03 + 26b6286 commit 4bf3488
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
8 changes: 6 additions & 2 deletions cosmosis/gaussian_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,12 @@ def __init__(self, options):
else:
self.log_det_constant = 0.0

self.likelihood_only = options.get_bool('likelihood_only', 'False')

self.likelihood_only = options.get_bool('likelihood_only', False)

if not self.likelihood_only:
self.chol = sigma


def build_data(self):
"""Sub-classes can over-ride this if they wish, to generate
the data point in a more complex way"""
Expand Down
5 changes: 5 additions & 0 deletions cosmosis/samplers/test/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@


class TestSampler(Sampler):
# The name of this class makes pytest think that it is a
# test to be run, instead of a tool for testing likelhioods.
# This should stop that from happening.
__test__ = False

needs_output = False

def config(self):
Expand Down
37 changes: 36 additions & 1 deletion cosmosis/test/test_gaussian.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from cosmosis.runtime import FunctionModule
from cosmosis.datablock import DataBlock
from cosmosis.gaussian_likelihood import GaussianLikelihood
from cosmosis.gaussian_likelihood import GaussianLikelihood, SingleValueGaussianLikelihood
import numpy as np
import os

Expand Down Expand Up @@ -38,6 +38,41 @@ def build_covariance(self):

assert np.isclose(block["likelihoods", "lll_like"], -3*np.log(0.1)/2)

def test_single_gaussian():

class MySingleLikelihood(SingleValueGaussianLikelihood):
section = "sec"
name = "name"
like_name = "xxx"
mean = 3.0
sigma = 0.1


mod = MySingleLikelihood.as_module("my2")

# no extra config info
mod.setup({"my2":{"include_norm":True, "likelihood_only": False}})

block = DataBlock()

block["sec", "name"] = 4.0
status = mod.execute(block)

# check cholesky correctly calculated
assert np.isclose(mod.data.chol, 0.1)

assert status == 0
assert np.isclose(block["data_vector", "xxx_chi2"], 100)
assert np.isclose(block["data_vector", "xxx_log_det"], 2*np.log(0.1))
assert block["data_vector", "xxx_n"] == 1

assert np.isclose(block["data_vector", "xxx_theory"], 4.0)
assert np.isclose(block["data_vector", "xxx_data"], 3.0)
assert np.isclose(block["data_vector", "xxx_inverse_covariance"], 100.0)
# sim should be within 10 sigma!
assert 3.8 < block["data_vector", "xxx_simulation"] < 4.2

assert np.isclose(block["likelihoods", "xxx_like"], -50.0 - np.log(0.1))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion cosmosis/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.2'
__version__ = '2.0.3'

0 comments on commit 4bf3488

Please sign in to comment.