Skip to content
Snippets Groups Projects
Commit 5bd5eadc authored by Gregory Ashton's avatar Gregory Ashton
Browse files

Add in replacement and a warning

parent f571f2f7
No related branches found
No related tags found
1 merge request!642Add function to convert to a LI prior
Pipeline #88598 passed
......@@ -53,8 +53,6 @@ def convert_to_flat_in_component_mass_prior(result, fraction=0.25):
priors = result.priors
posterior = result.posterior
logger.info("Resampling posterior to flat-in-component mass")
priors["chirp_mass"] = Constraint(
priors["chirp_mass"].minimum, priors["chirp_mass"].maximum,
"chirp_mass", latex_label=priors["chirp_mass"].latex_label)
......@@ -69,7 +67,18 @@ def convert_to_flat_in_component_mass_prior(result, fraction=0.25):
latex_label=priors["mass_2"].latex_label)
weights = posterior.mass_1 ** 2 / posterior.chirp_mass
result.posterior = posterior.sample(frac=fraction, weights=weights)
logger.info("Resampling posterior to flat-in-component mass")
effective_sample_size = sum(weights)**2 / sum(weights**2)
n_posterior = len(posterior)
if fraction > effective_sample_size / n_posterior:
logger.warning(
"Sampling posterior of length {} with fraction {}, but "
"effective_sample_size / len(posterior) = {}. This may produce "
"biased results"
.format(n_posterior, fraction, effective_sample_size / n_posterior)
)
result.posterior = posterior.sample(frac=fraction, weights=weights, replacement=True)
result.meta_data["reweighted_to_flat_in_component_mass"] = True
return result
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment