Diagnostics
- lisatools.diagnostic.inner_product(sig1, sig2, dt=None, df=None, f_arr=None, psd='LISASens', psd_args=(), psd_kwargs={}, normalize=False, complex=False)[source]
Compute the inner product between two signals weighted by a psd.
The inner product between time series \(a(t)\) and \(b(t)\) is
\[\langle a | b \rangle = 2\int_{f_\text{min}}^{f_\text{max}} \frac{\tilde{a}(f)^*\tilde{b}(f) + \tilde{a}(f)\tilde{b}(f)^*}{S_n(f)} df\ \ ,\]where \(\tilde{a}(f)\) is the Fourier transform of \(a(t)\) and \(S_n(f)\) is the one-sided Power Spectral Density of the noise.
The inner product can be left complex using the
complex
kwarg.GPU Capability: Pass CuPy arrays rather than NumPy arrays.
- Parameters:
sig1 (
ndarray
|list
|DataResidualArray
) – First signal to use for the inner product. Can be time-domain or frequency-domain. Must be 1Dnp.ndarray
, list of 1Dnp.ndarray``s, or 2D ``np.ndarray
across channels with shape(nchannels, data length)
.sig2 (
ndarray
|list
|DataResidualArray
) – Second signal to use for the inner product. Can be time-domain or frequency-domain. Must be 1Dnp.ndarray
, list of 1Dnp.ndarray``s, or 2D ``np.ndarray
across channels with shape(nchannels, data length)
.dt (
Optional
[float
], default:None
) – Time step in seconds. If provided, assumes time-domain signals.df (
Optional
[float
], default:None
) – Constant frequency spacing. This will assume a frequency domain signal with constant frequency spacing.f_arr (
Optional
[float
], default:None
) – Array of specific frequencies at which the signal is given.psd (
Union
[str
,None
,ndarray
,SensitivityMatrix
], default:'LISASens'
) – Indicator of what psd to use. If astr
, this will be passed as thesens_fn
kwarg toget_sensitivity()
. IfNone
, it will be an array of ones. Or, you can pass a 1Dnp.ndarray
of psd values that must be the same length as the frequency domain signals.psd_args (
Optional
[tuple
], default:()
) – Arguments to pass to the psd function iftype(psd) == str
.psd_kwargs (
Optional
[dict
], default:{}
) – Keyword arguments to pass to the psd function iftype(psd) == str
.normalize (
Union
[bool
,str
,None
], default:False
) – Normalize the inner product. IfTrue
, it will normalize the square root of the product of individual signal inner products. You can also pass"sig1"
or"sig2"
to normalize with respect to one signal.complex (
Optional
[bool
], default:False
) – IfTrue
, return the complex value of the inner product rather than just its real-valued part.
- Return type:
- Returns:
Inner product value.
- lisatools.diagnostic.residual_source_likelihood_term(data_res_arr, **kwargs)[source]
Calculate the source term in the Likelihood for a data residual (d - h).
The source term in the likelihood is given by,
\[\log{\mathcal{L}}_\text{src} = -\frac{1}{2}\langle \vec{d} - \vec{h} | \vec{d} - \vec{h}\rangle.\]- Parameters:
data_res_arr (
DataResidualArray
) – Data residual.**kwargs (
dict
) – Keyword arguments to pass toinner_product()
.
- Return type:
- Returns:
Source term Likelihood value.
- lisatools.diagnostic.noise_likelihood_term(psd)[source]
Calculate the noise term in the Likelihood.
The noise term in the likelihood is given by,
\[\log{\mathcal{L}}_n = -\sum \log{\vec{S}_n}.\]- Parameters:
psd (
SensitivityMatrix
) – Sensitivity information.- Return type:
- Returns:
Noise term Likelihood value.
- lisatools.diagnostic.residual_full_source_and_noise_likelihood(data_res_arr, psd, **kwargs)[source]
Calculate the full Likelihood including noise and source terms.
The noise term is calculated with
noise_likelihood_term()
.The source term is calcualted with
residual_source_likelihood_term()
.- Parameters:
data_res_arr (
DataResidualArray
) – Data residual.psd (
UnionType
[str
,None
,ndarray
,SensitivityMatrix
]) – Sensitivity information.**kwargs (
dict
) – Keyword arguments to pass toinner_product()
.
- Return type:
- Returns:
Full Likelihood value.
- lisatools.diagnostic.data_signal_source_likelihood_term(data_arr, sig_arr, **kwargs)[source]
Calculate the source term in the Likelihood for separate signal and data.
The source term in the likelihood is given by,
\[\log{\mathcal{L}}_\text{src} = -\frac{1}{2}\left(\langle \vec{d} | \vec{d}\rangle + \langle \vec{h} | \vec{h}\rangle - 2\langle \vec{d} | \vec{h}\rangle \right)\ \ .\]- Parameters:
data_arr (
DataResidualArray
) – Data.sig_arr (
DataResidualArray
) – Signal.**kwargs (
dict
) – Keyword arguments to pass toinner_product()
.
- Return type:
- Returns:
Source term Likelihood value.
- lisatools.diagnostic.data_signal_full_source_and_noise_likelihood(data_arr, sig_arr, psd, **kwargs)[source]
Calculate the full Likelihood including noise and source terms.
Here, the signal is treated separate from the data.
The noise term is calculated with
noise_likelihood_term()
.The source term is calcualted with
data_signal_source_likelihood_term()
.- Parameters:
data_arr (
DataResidualArray
) – Data.sig_arr (
DataResidualArray
) – Signal.psd (
UnionType
[str
,None
,ndarray
,SensitivityMatrix
]) – Sensitivity information.**kwargs (
dict
) – Keyword arguments to pass toinner_product()
.
- Return type:
- Returns:
Full Likelihood value.
- lisatools.diagnostic.snr(sig1, *args, data=None, **kwargs)[source]
Compute the snr between two signals weighted by a psd.
The signal-to-noise ratio of a signal is \(\sqrt{\langle a|a\rangle}\).
This will be the optimal SNR if
data==None
. If a data array is given, it will be the observed SNR: \(\langle d|a\rangle/\sqrt{\langle a|a\rangle}\).GPU Capability: Pass CuPy arrays rather than NumPy arrays.
- Parameters:
sig1 (
ndarray
|list
|DataResidualArray
) – Signal to use as the templatefor the SNR. Can be time-domain or frequency-domain. Must be 1Dnp.ndarray
, list of 1Dnp.ndarray``s, or 2D ``np.ndarray
across channels with shape(nchannels, data length)
.*args (
Any
) – Arguments to pass toinner_product()
.data (
Union
[ndarray
,list
,DataResidualArray
,None
], default:None
) – Data becomes thesig2
argument toinner_product()
.**kwargs (
Any
) – Keyword arguments to pass toinner_product()
.
- Return type:
- Returns:
Optimal or detected SNR value (depending on
data
kwarg).
- lisatools.diagnostic.h_var_p_eps(step, waveform_model, params, index, parameter_transforms=None, waveform_args=(), waveform_kwargs={})[source]
Calculate the waveform with a perturbation step of the variable V[i]
- Parameters:
waveform_model (
callable
) – Callable function to the waveform generator with signature(*params, **waveform_kwargs)
.params (
ndarray
|list
) – Source parameters that are over derivatives (not in fill dict of parameter transforms)step (
float
) – Absolute step size for variable of interest.index (
int
) – Index to parameter of interest.parameter_transforms (
Optional
[TransformContainer
], default:None
) – TransformContainer object to transform from the derivative parameter basis to the waveform parameter basis. This class can also fill in fixed parameters where the derivatives are not being taken.waveform_args (
Optional
[tuple
], default:()
) – args (beyond parameters) for the waveform generator.waveform_kwargs (
Optional
[dict
], default:{}
) – kwargs for the waveform generation.
- Return type:
ndarray
- Returns:
Perturbation to the waveform in the given parameter. Will always be 2D array with shape
(num channels, data length)
- lisatools.diagnostic.dh_dlambda(eps, *args, more_accurate=True, **kwargs)[source]
Derivative of the waveform
Calculate the derivative of the waveform with precision of order (step^4) with respect to the variable V in the i direction.
- Parameters:
eps (
float
) – Absolute derivative step size for variable of interest.*args (
tuple
) – Arguments passed toh_var_p_eps()
.more_accurate (
Optional
[bool
], default:True
) – IfTrue
, run a more accurate derivate requiring 2x more waveform generations.**kwargs (
dict
) – Keyword arguments passed toh_var_p_eps()
.
- Return type:
ndarray
- Returns:
Numerical derivative of the waveform with respect to a varibale of interest. Will be 2D array with shape
(num channels, data length)
.
- lisatools.diagnostic.info_matrix(eps, waveform_model, params, deriv_inds=None, inner_product_kwargs={}, return_derivs=False, **kwargs)[source]
Calculate Information Matrix.
This calculates the information matrix for a given waveform model at a given set of parameters. The inverse of the information matrix gives the covariance matrix.
This is also referred to as the Fisher information matrix, but @MichaelKatz has chosen to leave out the name because of this.
The info matrix is given by:
\[M_{ij} = \langle h_i | h_j \rangle \text{ with } h_i = \frac{\partial h}{\partial \lambda_i}.\]- Parameters:
eps (
float
|ndarray
) – Absolute derivative step size for variable of interest. Can be provided as afloat
value that applies to all variables or an array, one for each parameter being evaluated in the information matrix.waveform_model (
callable
) – Callable function to the waveform generator with signature(*params, **waveform_kwargs)
.params (
ndarray
|list
) – Source parameters.deriv_inds (
Union
[ndarray
,list
,None
], default:None
) – Subset of parameters of interest for which to calculate the information matrix, by index. IfNone
, it will benp.arange(len(params))
.inner_product_kwargs (
Optional
[dict
], default:{}
) – Keyword arguments for the inner product function.return_derivs (
Optional
[bool
], default:False
) – IfTrue
, also returns computed numerical derivatives.**kwargs (
dict
) – Keyword arguments passed todh_dlambda()
.
- Return type:
- Returns:
If
not return_derivs
, this will be the information matrix as a numpy array. Ifreturn_derivs is True
, it will be a tuple with the first entry as the information matrix and the second entry as the partial derivatives.
- lisatools.diagnostic.covariance(*info_mat_args, info_mat=None, diagonalize=False, return_info_mat=False, precision=False, **info_mat_kwargs)[source]
Calculate covariance matrix for a set of EMRI parameters, computing the information matrix if not supplied.
- Parameters:
*info_mat_args (
tuple
) – Set of arguments to pass toinfo_matrix()
. Not required ifinfo_mat
is notNone
.info_mat (
Optional
[ndarray
], default:None
) – Pre-computed information matrix. If supplied, this matrix will be inverted.diagonalize (
Optional
[bool
], default:False
) – IfTrue
, diagonalizes the covariance matrix.return_info_mat (
Optional
[bool
], default:False
) – IfTrue
, also returns the computed information matrix.precision (
Optional
[bool
], default:False
) – IfTrue
, uses 500-dps precision to compute the information matrix inverse (requires mpmath). This is typically a good idea as the information matrix can be highly ill-conditioned.**info_mat_kwargs (
dict
) – Keyword arguments to pass toinfo_matrix()
.
- Return type:
ndarray
|list
- Returns:
Covariance matrix. If
return_info_mat is True
. A list will be returned with the covariance as the first entry and the information matrix as the second entry. Ifreturn_derivs is True
(keyword argument toinfo_matrix()
), then another entry will be added to the list for the derivatives.
- lisatools.diagnostic.plot_covariance_corner(params, cov, nsamp=25000, fig=None, **kwargs)[source]
Construct a corner plot for a given covariance matrix.
The corner module is required for this.
- Parameters:
params (
ndarray
) – The set of parameters used for the event (the mean vector of the covariance matrix).cov (
ndarray
) – Covariance matrix from which to construct the corner plot.nsamp (
Optional
[int
], default:25000
) – Number of samples to draw from the multivariate distribution.fig (
Optional
[Figure
], default:None
) – Matplotlibplt.Figure
object. Use this if passing an existing corner plot figure.**kwargs (
dict
) – Keyword arguments for the corner plot - see the module documentation for more info.
- Return type:
- Returns:
The corner plot figure.
- lisatools.diagnostic.plot_covariance_contour(params, cov, horizontal_index, vertical_index, nsamp=25000, ax=None, **kwargs)[source]
Construct a contour plot for a given covariance matrix on a single axis object.
The corner module is required for this.
- Parameters:
params (
ndarray
) – The set of parameters used for the event (the mean vector of the covariance matrix).cov (
ndarray
) – Covariance matrix from which to construct the corner plot.horizontal_index (
int
) – Parameter index to plot along the horizontal axis of the contour plot.vertical_index (
int
) – Parameter index to plot along the vertical axis of the contour plot.nsamp (
Optional
[int
], default:25000
) – Number of samples to draw from the multivariate distribution.fig – Matplotlib
plt.Figure
object. Use this if passing an existing corner plot figure.**kwargs (
dict
) – Keyword arguments for the corner plot - see the module documentation for more info.
- Return type:
- Returns:
If
ax
is provided, the return will be that ax object. If it is not provided, then a Matplotlib Figure and Axes obejct is created and returned as a tuple:(plt.Figure, plt.Axes)
.
- lisatools.diagnostic.get_eigeninfo(arr, high_precision=False)[source]
Performs eigenvalue decomposition and returns the eigenvalues and right-eigenvectors for the supplied fisher/covariance matrix.
- Parameters:
- Returns:
,k] corresponds to evals[k].
- Return type:
Tuple containing Eigenvalues and right-Eigenvectors for the supplied array, constructed such that evects[
- lisatools.diagnostic.cutler_vallisneri_bias(waveform_model_true, waveform_model_approx, params, eps, input_diagnostics=None, info_mat=None, deriv_inds=None, return_derivs=False, return_cov=False, parameter_transforms=None, waveform_true_args=(), waveform_true_kwargs={}, waveform_approx_args=(), waveform_approx_kwargs={}, inner_product_kwargs={})[source]
Calculate the Cutler-Vallisneri bias.
# TODO: add basic math
- Parameters:
waveform_model_true (
callable
) – Callable function to the true waveform generator with signature(*params, **waveform_kwargs)
.waveform_model_approx (
callable
) – Callable function to the approximate waveform generator with signature(*params, **waveform_kwargs)
.params (
ndarray
) – Source parameters.eps (
float
|ndarray
) – Absolute derivative step size. Seeinfo_matrix()
.input_diagnostics (
Optional
[dict
], default:None
) – Dictionary including the diagnostic information if it is precomputed. Dictionary must include keys"cov"
(covariance matrix, output ofcovariance()
),"h_true"
(the true waveform), and"dh"
(derivatives of the waveforms, list of outputs fromdh_dlambda()
).info_mat (
Optional
[ndarray
], default:None
) – Pre-computed information matrix. If supplied, this matrix will be inverted to find the covariance.deriv_inds (
Union
[ndarray
,list
,None
], default:None
) – Subset of parameters of interest. Seeinfo_matrix()
.return_derivs (
Optional
[bool
], default:False
) – IfTrue
, also returns computed numerical derivatives.return_cov (
Optional
[bool
], default:False
) – IfTrue
, also returns computed covariance matrix.parameter_transforms (
Optional
[TransformContainer
], default:None
) –TransformContainer object. See
info_matrix()
.waveform_true_args (
Optional
[tuple
], default:()
) – Arguments for the true waveform generator.waveform_true_kwargs (
Optional
[dict
], default:{}
) – Keyword arguments for the true waveform generator.waveform_approx_args (
Optional
[tuple
], default:()
) – Arguments for the approximate waveform generator.waveform_approx_kwargs (
Optional
[dict
], default:{}
) – Keyword arguments for the approximate waveform generator.inner_product_kwargs (
Optional
[dict
], default:{}
) – Keyword arguments for the inner product function.
- Return type:
- Returns:
List of return information. By default, it is
[systematic error, bias]
. Ifreturn_derivs
orreturn_cov
areTrue
, they will be added to the list with derivs added before covs.
- lisatools.diagnostic.scale_to_snr(target_snr, sig, *snr_args, return_orig_snr=False, **snr_kwargs)[source]
Calculate the SNR and scale a signal.
- Parameters:
target_snr (
float
) – Desired SNR value for the injected signal.sig (
ndarray
|list
) – Signal to adjust. A copy will be made. Can be time-domain or frequency-domain. Must be 1Dnp.ndarray
, list of 1Dnp.ndarray``s, or 2D ``np.ndarray
across channels with shape(nchannels, data length)
.return_orig_snr (
Optional
[bool
], default:False
) – IfTrue
, return the original SNR in addition to the adjusted data.
- Return type:
- Returns:
Returns the copied input signal adjusted to the target SNR. If
return_orig_snr is True
, the original SNR is added as the second entry of a tuple with the adjusted signal (as the first entry in the tuple).