cogwheel.likelihood.marginalized_distance.MarginalizedDistanceLikelihood

class cogwheel.likelihood.marginalized_distance.MarginalizedDistanceLikelihood(lookup_table, event_data, waveform_generator, par_dic_0, fbin=None, pn_phase_tol=None, spline_degree=3)

Bases: RelativeBinningLikelihood

Modified RelativeBinningLikelihood that uses a likelihood function marginalized semi-analytically over distance. Thus, it removes one dimension from the parameter space.

Parameters:
event_datadata.EventData
waveform_generatorwaveform.WaveformGenerator
par_dic_0dict

Parameters of the reference waveform, should be close to the maximum likelihood waveform.

fbinfloat array

Array with edges of the frequency bins used for relative binning [Hz]. Alternatively, pass pn_phase_tol.

pn_phase_tolfloat

Tolerance in the post-Newtonian phase [rad] used for defining frequency bins. Alternatively, pass fbin.

spline_degreeint

Degree of the spline used to interpolate the ratio between waveform and reference waveform for relative binning.

lookup_tablelikelihood.LookupTable

To compute the marginalized likelihood.

Methods

compute_asd_drift

Estimate local standard deviation of the matched-filter output at the time of the event for each detector.

from_reference_waveform_finder

Instantiate with help from a ReferenceWaveformFinder instance, which provides waveform_generator, event_data and par_dic_0 objects.

get_average_frequency

Return average frequency in Hz.

get_blob

Return dictionary of ancillary information ("blob").

get_init_dict

Return keyword arguments to reproduce the class instance.

get_module_name

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

lnlike

Return log likelihood, marginalized over distance, using relative binning.

lnlike_and_metadata

lnlike_detectors_no_asd_drift

Return an array of length n_detectors with the values of (d|h) - (h|h)/2, no ASD-drift correction applied, using relative binning.

lnlike_fft

Return log likelihood computed on the FFT grid, without using relative binning.

lnlike_no_marginalization

Return log likelihood, not marginalized over distance, using relative binning.

plot_whitened_wf

Plot the whitened strain and waveform model in the time domain in all detectors.

postprocess_samples

Add a column 'd_luminosity' to a DataFrame of samples, with values taken randomly from the conditional posterior.

reinstantiate

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

to_json

Write class instance to json file.

Attributes

asd_drift

Array of length ndetectors with ASD drift-correction.

fbin

Edges of the frequency bins for relative binning [Hz].

par_dic_0

Dictionary with reference waveform parameters.

params

Parameters expected in par_dic for likelihood evaluations.

pn_phase_tol

Tolerance in the post-Newtonian phase [rad] used for defining frequency bins.

spline_degree

Integer between 1 and 5, degree of the spline used to interpolate waveform ratios.

subclass_registry

property asd_drift

Array of length ndetectors with ASD drift-correction.

Values > 1 mean local noise variance is higher than average.

compute_asd_drift(par_dic, tol=0.02, max_tcorr_contiguous_low=16.0, **kwargs)

Estimate local standard deviation of the matched-filter output at the time of the event for each detector.

Note: all harmonic_modes of the approximant are used even if waveform_generator.harmonic_modes is set differently. This is so that asd_drift does not change and one can make apples-to- apples comparisons of the likelihood toggling harmonic modes on and off.

Parameters:
par_dicdict

Waveform parameters, keys should match self.waveform_generator.params.

tolfloat

Stochastic measurement error tolerance, used to decide the number of samples.

max_tcorr_contiguous_lowfloat

Maximum number of contiguous correlation times with values below the average noise level to allow (these are classified as a hole and disregarded in the average).

**kwargs

Passed to safe_std, keys include: expected_high, reject_nearby.

property fbin

Edges of the frequency bins for relative binning [Hz]. Setting this will automatically round them to fall in the FFT array, recompute the splines and summary data, and set ._pn_phase_tol to None to keep logs clean.

classmethod from_reference_waveform_finder(reference_waveform_finder, approximant, fbin=None, pn_phase_tol=0.05, spline_degree=3, **kwargs)

Instantiate with help from a ReferenceWaveformFinder instance, which provides waveform_generator, event_data and par_dic_0 objects.

Parameters:
reference_waveform_finderlikelihood.ReferenceWaveformFinder
approximantstr

Approximant name.

fbin1-d array or None

Array with edges of the frequency bins used for relative binning [Hz]. Alternatively, pass pn_phase_tol.

pn_phase_tolfloat or None

Tolerance in the post-Newtonian phase [rad] used for defining frequency bins. Alternatively, pass fbin.

spline_degreeint

Degree of the spline used to interpolate the ratio between waveform and reference waveform for relative binning.

**kwargs

Keyword arguments, in case a subclass needs them.

Returns:
Instance of cls.
get_average_frequency(par_dic, ref_det_name=None, moment=1.0)

Return average frequency in Hz.

The average frequency is defined as (avg(f^moment))^(1/moment) where avg is the frequency-domain average with weight ~ |h(f)|^2 / PSD(f).

The answer is rounded to nearest Hz to ease reporting.

Parameters:
par_dicdict

Waveform parameters, keys should match self.waveform_generator.params.

ref_det_namestr or None

Name of the detector from which to get the PSD, e.g. ‘H’ for Hanford, or None (default) to combine the PSDs of all detectors.

momentnonzero float

Controls the frequency weights in the average.

get_blob(metadata)

Return dictionary of ancillary information (“blob”). This will be appended to the posterior samples as extra columns.

get_init_dict(**kwargs)

Return keyword arguments to reproduce the class instance.

get_module_name()

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

lnlike(par_dic)

Return log likelihood, marginalized over distance, using relative binning.

lnlike_and_metadata(par_dic)
Parameters:
par_dicdict

Keys must include .params.

Returns:
lnl_marginalizedfloat

Log likelihood, marginalized over distance, using relative binning.

metadatadict

Contains the marginalized lnl, as well as a distance draw and its corresponding (non-marginalized) log-likelihood.

lnlike_detectors_no_asd_drift(par_dic)

Return an array of length n_detectors with the values of (d|h) - (h|h)/2, no ASD-drift correction applied, using relative binning.

Parameters:
par_dicdict

Waveform parameters, keys should match self.params.

lnlike_fft(par_dic)

Return log likelihood computed on the FFT grid, without using relative binning.

Parameters:
par_dicdict

Waveform parameters, keys should match self.waveform_generator.params.

lnlike_no_marginalization(par_dic)

Return log likelihood, not marginalized over distance, using relative binning.

property par_dic_0

Dictionary with reference waveform parameters.

property params

Parameters expected in par_dic for likelihood evaluations.

plot_whitened_wf(par_dic, trng=(-0.7, 0.1), plot_data=True, fig=None, figsize=None, by_m=False, **wf_plot_kwargs)

Plot the whitened strain and waveform model in the time domain in all detectors.

Parameters:
par_dicdict

Waveform parameters, keys should match self.waveform_generator.params.

trng(float, float)

Range of time to plot relative to self.tgps (s).

plot_databool

Whether to include detector data in plot.

figmatplotlib.figure.Figure, optional

None (default) creates a new figure.

figsize(float, float)

Figure width and height in inches, used if fig=None.

**wf_plot_kwargs

Keyword arguments passed to plt.plot() for waveform. Additionally, keyword arguments for the data plot can be passed as a dict data_plot_kwargs.

Returns:
matplotlib.figure.Figure

Figure with plots.

property pn_phase_tol

Tolerance in the post-Newtonian phase [rad] used for defining frequency bins. Setting this will recompute frequency bins such that across each frequency bin the change in the post-Newtonian waveform phase with respect to the fiducial waveform is bounded by pn_phase_tol [rad].

postprocess_samples(samples)

Add a column ‘d_luminosity’ to a DataFrame of samples, with values taken randomly from the conditional posterior. samples needs to have columns for all self.params.

Parameters:
samplespandas.Dataframe

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.

property spline_degree

Integer between 1 and 5, degree of the spline used to interpolate waveform ratios. Editing it will automatically recompute the splines and summary data.

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.