Maintenance will be performed on git.ligo.org, chat.ligo.org, containers.ligo.org, and docs.ligo.org on Tuesday 22nd September 2020 starting at approximately 9am MST.It is expected to take around 15 minutes and there will be a short period of downtime towards the end of the maintenance window. Please address any comments, questions, or concerns to computing-help@igwn.org.

Commit e0a0e0a9 authored by Gregory Ashton's avatar Gregory Ashton

Merge branch 'fix-combined-bayes-factors' into 'master'

Fix combine runs

See merge request !566
parents b311146d 9021c207
Pipeline #72304 passed with stages
in 7 minutes and 49 seconds
......@@ -1363,21 +1363,41 @@ class ResultList(list):
return result
def _combine_nested_sampled_runs(self, result):
"""
Combine multiple nested sampling runs.
Currently this keeps posterior samples from each run in proportion with
the evidence for each individual run
Parameters
----------
result: bilby.core.result.Result
The result object to put the new samples in.
Returns
-------
posteriors: list
A list of pandas DataFrames containing the reduced sample set from
each run.
result: bilby.core.result.Result
The result object with the combined evidences.
"""
self.check_nested_samples()
log_evidences = np.array([res.log_evidence for res in self])
result.log_evidence = logsumexp(log_evidences, b=1. / len(self))
if result.use_ratio:
result.log_bayes_factor = result.log_evidence
result.log_evidence = result.log_evidence + result.log_noise_evidence
log_bayes_factors = np.array([res.log_bayes_factor for res in self])
result.log_bayes_factor = logsumexp(log_bayes_factors, b=1. / len(self))
result.log_evidence = result.log_bayes_factor + result.log_noise_evidence
result_weights = np.exp(log_bayes_factors - np.max(log_bayes_factors))
else:
result.log_bayes_factor = result.log_evidence - result.log_noise_evidence
log_evidences = np.array([res.log_evidence for res in self])
result.log_evidence = logsumexp(log_evidences, b=1. / len(self))
result_weights = np.exp(log_evidences - np.max(log_evidences))
log_errs = [res.log_evidence_err for res in self if np.isfinite(res.log_evidence_err)]
if len(log_errs) > 0:
result.log_evidence_err = logsumexp(2 * np.array(log_errs), b=1. / len(self))
else:
result.log_evidence_err = np.nan
result_weights = np.exp(log_evidences - np.max(log_evidences))
posteriors = []
posteriors = list()
for res, frac in zip(self, result_weights):
selected_samples = (np.random.uniform(size=len(res.posterior)) < frac)
posteriors.append(res.posterior[selected_samples])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment