Likelihood Methods
Direct Likelihood Computation
- class bbhx.likelihood.Likelihood(template_gen, data_freqs, data_channels, psd, use_gpu=False)
Bases:
object
Fast Base Likelihood Class for MBHBs
This class computes the graitational wave Likelihood as a direct sum over frequecy bins. It only sums over the frequencies where the MBHB signal exists. Therefore, larger mass waveforms are faster because there are less frequencies. This class computes: \(\mathcal{L}\propto-1/2\langle d-h|d-h\rangle=-1/2\left(\langle d|d\rangle \langle h|h\rangle - 2\langle d|h\rangle\right)\).
This class has GPU capability.
- Parameters:
template_gen (obj) – Waveform generation class that returns a tuple of (list of template arrays, start indices, lengths). See
bbhx.waveform.BBHWaveformFD
for more information on this return type.data_freqs (double xp.ndarray) – Frequencies for the data stream.
data_freqs
should be a numpy (cupy) array if running on the CPU (GPU).data_channels (complex128 xp.ndarray) – Data stream. 2D array of shape:
(3, len(data_freqs))
. It is assumed there are 3 channels.data_channels
should be a numpy (cupy) array if running on the CPU (GPU).psd (double xp.ndarray) – Power Spectral Density in the noise:math:S_n(f). 2D array of shape:
(3, len(data_freqs))
. It is assumed there are 3 channels.psd
should be a numpy (cupy) array if running on the CPU (GPU).use_gpu (bool, optional) – If
True
, use GPU.
- d_d
\(\langle d|d\rangle\) inner product value.
- Type:
double
- data_channels
Data stream. 1D flattened array of shape:
(3, len(data_freqs))
. Notedata_channels
should be multiplied bypsd
before input into this class.- Type:
complex128 np.ndarray
- data_freqs
Frequencies for the data stream (1D).
- Type:
double np.ndarray
- data_stream_length
Length of data.
- Type:
int
- noise_factors
\(\sqrt{\frac{\Delta f}{S_n(f)}}\). 1D flattened array of shape:
(3, len(data_freqs))
.- Type:
double xp.ndarray
- psd
Power Spectral Density in the noise:math:S_n(f). 1D flattened array of shape:
(3, len(data_freqs))
.- Type:
double xp.ndarray
- template_gen
Waveform generation class that returns a tuple of (list of template arrays, start indices, lengths). See
bbhx.waveform.BBHWaveformFD
for more information on this return type.- Type:
obj
- phase_marginalize
If
True
, compute the phase-marginalized log-Likelihood (and snr ifreturn_extracted_snr==True
).- Type:
bool
- return_extracted_snr
Return the snr in addition to the Likeilihood.
- Type:
bool
- property use_gpu: bool
Whether to use a GPU.
- property like_gen
Likelihood for either GPU or CPU.
- property xp
Cupy or Numpy
- get_ll(params, return_extracted_snr=False, phase_marginalize=False, **waveform_kwargs)
Compute the log-Likelihood
- params (double np.ndarray): Parameters for evaluating log-Likelihood.
params.shape=(num_params,)
if 1D orparams.shape=(num_params, num_bin_all)
if 2D for more than one binary.- return_extracted_snr (bool, optional): If
True
, return \(\langle d|h\rangle\ / \sqrt{\langle h|h\rangle}\) as a second entry of the return array. This produces a return array of
xp.array([log likelihood, snr]).T
. IfFalse
, just return the log-Likelihood array.- phase_marginalize (bool, optional): If
True
, compute the phase-marginalized log-Likelihood (and snr if
return_extracted_snr==True
).- **waveform_kwargs (dict, optional): Keyword arguments for waveform
generator.
- Returns:
log-Likelihoods or
np.array([log-Likelihoods, snr]).T
- Return type:
np.ndarray
Heterodyned Likelihood Computation
- class bbhx.likelihood.HeterodynedLikelihood(template_gen, data_freqs, data_channels, reference_template_params, length_f_het, template_gen_kwargs={}, reference_gen_kwargs={}, sens_mat=None, use_gpu=False)
Bases:
object
Compute the Heterodyned log-Likelihood
Heterdyning involves separating the fast and slow evolutions when comparing signals. This involves comparing a reference template to the data stream and determining various quantities at the full frequency resolution of the data stream. Then, during online computation, the log-Likelihood is determined by computing a new waveform on a sparse frequency grid and comparing it to the reference waveform on the same sparse grid. The practical aspect is the computation of a smaller number of frequency points which lowers the required memory and increases the speed of the computation. More information on the general method can be found in arXiv:2109.02728. We implement the method as described in arXiv:1806.08792.
This class also works with higher order harmonic modes, but it has not been tested extensivally. It only does a direct summation over the modes rather than heterodyning per mode. So, it is less reliable, but in practice it produces a solid posterior distribution.
This class has GPU capabilities.
- Parameters:
template_gen (obj) – Waveform generation class that returns a tuple of (list of template arrays, start indices, lengths). See
bbhx.waveform.BBHWaveformFD
for more information on this return type.data_freqs (double xp.ndarray) – Frequencies for the data stream.
data_freqs
should be a numpy (cupy) array if running on the CPU (GPU).data_channels (complex128 xp.ndarray) – Data stream. 2D array of shape:
(3, len(data_freqs))
. It is assumed there are 3 channels.data_channels
should be a numpy (cupy) array if running on the CPU (GPU).reference_template_params (np.ndarray) – Parameters for the reference template for
template_gen
.template_gen_kwargs (dict, optional) – Keywords arguments for generating the template with
template_gen
. It will automatically add/changedirect
andcompress
keyword arguments toTrue
. The keyword argumentsqueeze
is automatically set toTrue
for the initial setup and then automatically set toFalse
for online computations. If you so choose (not recomended), you can change these kwargs for online running using the**waveform_kwargs
setup in theself.get_ll
method. However, if you include in this adjustmentdirect
,compress
, orsqueeze
will still automatically be overwritten. (Default:{}
)reference_gen_kwargs (dict, optional) – Keywords arguments for generating the reference template with
template_gen
. It will automatically add/changefill
,compress
, andsqueeze
keyword arguments toTrue
. These waveforms can be produced without interpolation withdirect = True
. Iflength
keyword argument is given anddirect=False
, the waveform will be interpolated. Iflength
anddirect
are not given, it will interpolate the signal withlength=8096
. (Default:{}
)sens_mat (SensitivityMatrix, optional) –
SensitivityMatrix
object representing the AET channels. IfNone
, defaults to class:AET1SensitivityMatrix. (default:None
)use_gpu (bool, optional) – If
True
, use GPU.
- reference_d_d
\(\langle d|d\rangle\) inner product value.
- Type:
double
- reference_h_h
\(\langle h|h\rangle\) inner product value for the reference template.
- Type:
double
- reference_d_h
\(\langle d|h\rangle\) inner product value for the reference template.
- Type:
double
- reference_ll
log-Likelihood value for the reference template.
- Type:
double
- hdyn_d_h
Heterodyned \(\langle d|h\rangle\) inner product values for the test templates.
- Type:
complex128 xp.ndarray
- hdyn_h_h
Heterodyned \(\langle d|h\rangle\) inner product values for the test templates.
- Type:
complex128 xp.ndarray
- h0_sparse
Array with sparse waveform for reference parameters.
- Type:
xp.ndarray
- h_sparse
Array with sparse waveform for test parameters.
- Type:
xp.ndarray
- d
Data stream. 1D flattened array of shape:
(3, len(data_freqs))
.- Type:
complex128 xp.ndarray
- data_stream_length
Length of data.
- Type:
int
- data_constants
Flattened array container holding all heterodyning constants needed: A0, A1, B0, B1.
- Type:
xp.ndarray
- f_dense
Frequencies for the data stream (1D).
- Type:
xp.ndarray
- freqs
Frequencies for sparse arrays.
- Type:
xp.ndarray
- f_m
Frequency of mid-point in each sparse bin.
- Type:
xp.ndarray
- length_f_het
Length of sparse array.
- Type:
int
- psd
\(\sqrt{\frac{\Delta f}{S_n(f)}}\). 1D flattened array of shape:
(3, len(data_freqs))
.- Type:
double xp.ndarray
- return_extracted_snr
Return the snr in addition to the Likeilihood.
- Type:
bool
- phase_marginalize
If
True
, compute the phase-marginalized log-Likelihood (and snr ifreturn_extracted_snr==True
).- Type:
bool
- property use_gpu: bool
Whether to use a GPU.
- property sens_mat
Sensitivity Matrix
- property like_gen
C function on GPU/CPU
- property xp
Numpy or Cupy
- property citation
Citations for this class
- init_heterodyne_info(reference_template_params, template_gen_kwargs={}, reference_gen_kwargs={})
Prepare all information for Heterdyning
- Parameters:
reference_template_params (np.ndarray) – Parameters for the reference template for
template_gen
.template_gen_kwargs (dict, optional) – Keywords arguments for generating the template with
template_gen
. It will automatically add/changedirect
andcompress
keyword arguments toTrue
. The keyword argumentsqueeze
is automatically set toTrue
for the initial setup and then automatically set toFalse
for online computations. If you so choose (not recomended), you can change these kwargs for online running using the**waveform_kwargs
setup in theself.get_ll
method. However, if you include in this adjustmentdirect
,compress
, orsqueeze
will still automatically be overwritten. (Default:{}
)reference_gen_kwargs (dict, optional) – Keywords arguments for generating the reference template with
template_gen
. It will automatically add/changefill
,compress
, andsqueeze
keyword arguments toTrue
. These waveforms can be produced without interpolation withdirect = True
. Iflength
keyword argument is given anddirect=False
, the waveform will be interpolated. Iflength
anddirect
are not given, it will interpolate the signal withlength=8096
. (Default:{}
)
- get_ll(params, return_extracted_snr=False, phase_marginalize=False, **waveform_kwargs)
Compute the log-Likelihood
- params (double np.ndarray): Parameters for evaluating log-Likelihood.
params.shape=(num_params,)
if 1D orparams.shape=(num_params, num_bin_all)
if 2D for more than one binary.- return_extracted_snr (bool, optional): If
True
, return \(\langle d|h\rangle\ / \sqrt{\langle h|h\rangle}\) as a second entry of the return array. This produces a return array of
xp.array([log likelihood, snr]).T
. IfFalse
, just return the log-Likelihood array.- phase_marginalize (bool, optional): If
True
, compute the phase-marginalized log-Likelihood (and snr if
return_extracted_snr==True
).- **waveform_kwargs (dict, optional): Keyword arguments for waveform
generator. Some may be overwritten. See the main class docstring.
- Returns:
log-Likelihoods or
np.array([log-Likelihoods, snr]).T
- Return type:
np.ndarray