Skip to content

Commit

Permalink
Merge pull request #99 from joezuntz/pipeline-from-function
Browse files Browse the repository at this point in the history
Bug fixes to from_likelihood_function
  • Loading branch information
joezuntz authored Sep 1, 2023
2 parents bd8bf60 + 207172b commit b811ed0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cosmosis/runtime/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1409,18 +1409,19 @@ def execute(block, config):
else:
return 1

if derived is None:
like = p
else:
if isinstance(p, tuple):
like = p[0]
extra = p[1]

if not isinstance(extra, dict):
raise ValueError("The extra output from the likelihood function must be a dictionary")
if not isinstance(extra, dict):
raise ValueError("The extra output from the likelihood function must be a dictionary")

for key, value in extra.items():
block['derived', key] = value
else:
like = p

block['likelihoods', 'a_like'] = like
for key, value in extra.items():
block['derived', key] = value

return 0

Expand All @@ -1446,10 +1447,10 @@ def execute(block, config):
"params": parameters
}

priors = [{
"params": priors

}]
if priors is not None:
priors = [{
"params": priors
}]

pipeline = cls(config, values = values, modules=[mod], priors=priors)
return pipeline
Expand Down
6 changes: 6 additions & 0 deletions cosmosis/test/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ def log_like(p):
assert r.like == 0.0
assert r.extra[0] == 0.0

# version without priors or derived params extracted
pipeline = LikelihoodPipeline.from_likelihood_function(log_like, param_ranges)
r = pipeline.run_results([0,0,0,0])
assert r.like == 0.0
assert len(r.extra) == 0



if __name__ == '__main__':
Expand Down

0 comments on commit b811ed0

Please sign in to comment.