cogwheel.posterior.Posterior

class cogwheel.posterior.Posterior(prior, likelihood)

Bases: JSONMixin

Class that instantiates a prior and a likelihood and provides methods for sampling the posterior distribution.

Parameter space folding is implemented; this means that some (“folded”) dimensions are sampled over half their original range, and a map to the other half of the range is defined by reflecting or shifting about the midpoint. The folded posterior distribution is defined as the sum of the original posterior over all 2**n_folds mapped points. This is intended to reduce the number of modes in the posterior.

Parameters:
priorprior.Prior

Provides coordinate transformations, prior, and foldable parameters.

likelihoodlikelihood.RelativeBinningLikelihood

Provides likelihood computation.

Methods

from_event

Instantiate a Posterior class from the strain data.

get_eventdir

Return directory name in which the Posterior instance should be saved, of the form '{parentdir}/{prior_name}/{eventname}/'.

get_init_dict

Return dictionary with keyword arguments to __init__.

get_module_name

Name of the module that defines the instance's class.

lnposterior

Natural logarithm of the posterior probability density in the space of sampled parameters (does not apply folding).

lnposterior_pardic_and_metadata

Return log posterior, standard parameters and extra metadata.

refine_reference_waveform

Reset relative-binning reference waveform, using differential evolution to find a good fit.

reinstantiate

Return a new instance of the class, possibly updating init_kwargs.

standard_lnposterior

Natural logarithm of the posterior probability density in the space of standard parameters.

to_json

Write class instance to json file.

Attributes

subclass_registry

classmethod from_event(event, mchirp_guess, approximant, prior_class, likelihood_class=None, prior_kwargs=None, likelihood_kwargs=None, ref_wf_finder_kwargs=None)

Instantiate a Posterior class from the strain data. Automatically find a good fit solution for relative binning.

Parameters:
eventdata.EventData, str

EventData, or string with event name, or path to npz file with EventData instance.

mchirp_guessfloat

Approximate chirp mass (Msun).

approximantstr

Approximant name.

prior_classstr, class

Key from gw_prior.prior_registry, or subclass of prior.Prior.

likelihood_class

subclass of likelihood.RelativeBinningLikelihood

prior_kwargsdict,

Keyword arguments for prior_class constructor.

likelihood_kwargsdict

Keyword arguments for likelihood_class constructor.

ref_wf_finder_kwargsdict

Keyword arguments for ReferenceWaveformFinder.from_event constructor, including:

  • time_range

  • mchirp_range

  • f_ref

Returns:
Instance of Posterior.
get_eventdir(parentdir)

Return directory name in which the Posterior instance should be saved, of the form ‘{parentdir}/{prior_name}/{eventname}/’.

get_init_dict(**kwargs)

Return dictionary with keyword arguments to __init__.

Only works if the class stores its init parameters as attributes with the same names. Otherwise, the subclass should override this method.

Parameters:
**kwargs

Allows to manually override some keys. The remaining ones will be read from the instance’s attributes. All keywords must be in the __init__ signature. It’s mostly here to facilitate overriding by subclasses.

get_module_name()

Name of the module that defines the instance’s class.

lnposterior(*args, **kwargs)

Natural logarithm of the posterior probability density in the space of sampled parameters (does not apply folding).

lnposterior_pardic_and_metadata(*args, **kwargs)

Return log posterior, standard parameters and extra metadata.

Parameters:
*args, **kwargs

Sampled parameters.

Returns:
lnposteriorfloat

Natural logarithm of the posterior probability density in the space of sampled parameters (does not apply folding).

standard_par_dicdict

Standard parameters.

metadataobject

Used to compute ancillary information about samples. This will vary depending on the likelihood implementation.

refine_reference_waveform(rng=None, params=None)

Reset relative-binning reference waveform, using differential evolution to find a good fit. It is guaranteed that the new waveform will have at least as good a fit as the current one. The likelihood maximization uses folded sampled parameters.

Parameters:
rng{int, numpy.random.Generator, numpy.random.RandomState}

Passed to scipy.optimize.differential_evolution

paramslist of str, optional

Which parameters to maximize over. If provided, must be keys from self.prior.sampled_params.

reinstantiate(**new_init_kwargs)

Return a new instance of the class, possibly updating init_kwargs.

Values not passed will be taken from the current instance.

standard_lnposterior(*standard_parameters_, **standard_parameters)

Natural logarithm of the posterior probability density in the space of standard parameters.

to_json(dirname, basename=None, *, dir_permissions=493, file_permissions=420, overwrite=False)

Write class instance to json file.

It can then be loaded with read_json.