Utilities needed for aligned-spin NR-hybrid surrogate models. More...
Prototypes | |
int | ReadHDF5DoubleDataset (REAL8 *param, LALH5File *sub, const char *name) |
Reads a REAL8 value from a H5 file/group. More... | |
int | ReadHDF5IntDataset (int *param, LALH5File *sub, const char *name) |
Reads an INT8 value from a H5 file/group. More... | |
static int | NRHybSur_LoadDataPiece (DataPiece **data_piece, LALH5File *file, const char *sub_grp_name) |
Loads a single waveform data piece from a H5 file. More... | |
static int | NRHybSur_LoadSingleModeData (ModeDataPieces **mode_data_pieces, LALH5File *file, const int mode_idx, const gsl_matrix_long *mode_list) |
Loads all data pieces of a single waveform mode. More... | |
int | NRHybSur_Init (NRHybSurData *NR_hybsur_data, LALH5File *file) |
Initialize a NRHybSurData structure from an open H5 file. More... | |
static REAL8 | kernel (const gsl_vector *x1, const gsl_vector *x2, const GPRHyperParams *hyperparams, gsl_vector *dummy_worker) |
The GPR Kernel evaluated at a single pair of points. More... | |
static REAL8 | gp_predict (const gsl_vector *xst, const GPRHyperParams *hyperparams, const gsl_matrix *x_train, gsl_vector *dummy_worker) |
Evaluate a GPR fit. More... | |
REAL8 | NRHybSur_eval_fit (const NRHybSurFitData *fit_data, const gsl_vector *fit_params, const gsl_matrix *x_train, gsl_vector *dummy_worker) |
Evaluate a NRHybSur fit. More... | |
static int | NRHybSur_eval_data_piece (gsl_vector **result, const gsl_vector *fit_params, const DataPiece *data_piece, const gsl_matrix *x_train, gsl_vector *dummy_worker) |
Evaluate a single NRHybSur waveform data piece. More... | |
static gsl_vector * | spline_array_interp (const gsl_vector *xout, const gsl_vector *x, const gsl_vector *y) |
Do cubic spline interpolation using a gsl_interp_cspline. More... | |
static REAL8 | compute_omega_22 (const gsl_vector *times, const gsl_vector *phi_22, const int idx) |
Computes omega_22 by forward differences. More... | |
static int | search_omega_22 (int *omega_idx, const gsl_vector *times, const gsl_vector *phi_22, const REAL8 omegaM_22_val) |
Finds closest index such that omegaM_22[index] = omegaM_22_val. More... | |
static int | NRHybSur_eval_phase_22_sparse (gsl_vector **phi_22_sparse, const REAL8 eta, const gsl_vector *fit_params, gsl_vector *dummy_dp, const gsl_matrix *x_train, gsl_vector *dummy_worker, const NRHybSurData *NR_hybsur_data) |
Evaluate the phase of the (2,2) mode on the sprase surrogate domain. More... | |
static int | NRHybSur_upsample_phi_22 (gsl_vector **phi_22_dense, gsl_vector **times_dense, const REAL8 deltaTOverM, const REAL8 omegaM_22_min, const gsl_vector *phi_22_sparse, const gsl_vector *domain) |
Upsamples sparse \( \phi_{22} \) such that time step size is deltaTOverM, and initial frequency is roughly omegaM_22_min. More... | |
int | NRHybSur_eval_phase_22 (gsl_vector **phi_22, gsl_vector **output_times, const REAL8 eta, const gsl_vector *fit_params, const REAL8 omegaM_22_min, const REAL8 deltaTOverM, const REAL8 phiRef, const REAL8 omegaM_22_ref, gsl_vector *dummy_dp, const gsl_matrix *x_train, gsl_vector *dummy_worker, const NRHybSurData *NR_hybsur_data) |
Evaluate the phase of the (2,2) mode. More... | |
int | NRHybSur_eval_mode_data_pieces (EvaluatedDataPieces **this_mode_eval_dp, const UINT4 ell, const UINT4 m, const ModeDataPieces *data_pieces, const gsl_vector *output_times, const gsl_vector *fit_params, gsl_vector *dummy_dp, const gsl_matrix *x_train, gsl_vector *dummy_worker, const NRHybSurData *NR_hybsur_data) |
Evaluate waveform data pieces of a single mode. More... | |
void | NRHybSur_DestroyEvaluatedDataPieces (gsl_vector *phi_22, EvaluatedDataPieces **evaluated_mode_dps, const UINT4 num_modes_incl) |
Destroy phi_22 and an EvaluatedDataPieces structure. More... | |
int | NRHybSur_sanity_check_sample_rate (REAL8 deltaT, REAL8 m1, REAL8 m2, REAL8 chi1z, REAL8 chi2z, UINT4 max_ell) |
Sanity check (warning only, not error) that the sample rate is high enough to capture the ringdown frequencies, by ensuring Nyquist frequency is greater than the QNM frequency of the (max_ell,max_ell,0) mode, where max_ell is the maximum ell index among the included modes. More... | |
void | NRHybSur_set_default_modes (LALValue *ModeArray, const NRHybSurData *NR_hybsur_data) |
Activates all modes of an NRHybSur model. More... | |
int | NRHybSur_check_mode_array (UINT4 *num_modes_incl, UINT4 *max_ell, LALValue *ModeArray, const NRHybSurData *NR_hybsur_data) |
Sanity checks on ModeArray. More... | |
Utilities needed for aligned-spin NR-hybrid surrogate models.
Called from: LALSimIMRNRHybSur3dq8.h
Definition in file LALSimNRHybSurUtilities.c.
Go to the source code of this file.
Reads a REAL8 value from a H5 file/group.
param | Output: REAL8 value from H5 file/group. |
sub | H5 file or group. |
name | Name of REAL8 dataset within file/group. |
Definition at line 68 of file LALSimNRHybSurUtilities.c.
Reads an INT8 value from a H5 file/group.
param | Output: int value from H5 file/group. |
sub | H5 file or group. |
name | Name of int dataset within file/group. |
Definition at line 92 of file LALSimNRHybSurUtilities.c.
|
static |
Loads a single waveform data piece from a H5 file.
data_piece | Output: Waveform data piece. *data_piece should be NULL. Space will be allocated. |
file | Opened HDF5 file. |
sub_grp_name | H5 group name. |
Definition at line 122 of file LALSimNRHybSurUtilities.c.
|
static |
Loads all data pieces of a single waveform mode.
mode_data_pieces | Output: Waveform data pieces of a given mode. Space will be allocated to **mode_data_pieces. |
file | Opened HDF5 file. |
mode_idx | Index corresponding to the mode. |
mode_list | List of all modes. |
Definition at line 249 of file LALSimNRHybSurUtilities.c.
int NRHybSur_Init | ( | NRHybSurData * | NR_hybsur_data, |
LALH5File * | file | ||
) |
Initialize a NRHybSurData structure from an open H5 file.
This will typically only be called once. For example from NRHybSur3dq8_Init_LALDATA.
The HDF5 file should have the following structure:
NR_hybsur_data | Output: Struct to save surrogate data. |
file | Opened HDF5 file. |
Definition at line 403 of file LALSimNRHybSurUtilities.c.
|
static |
The GPR Kernel evaluated at a single pair of points.
We follow sklearn closely. We use the kernel given in Eq.(S3) of arxiv:1809.09125 :
\[ K(x, x') = \sigma_k^2 exp(-1/2 \sum_i^D (x^{i} - x'^{i})^2/\sigma_i^2) \]
where D is the dimension of the model.
Note that Eq.(S3) also includes the WhiteKernel, which has a noise parameter, but we don't need that here since we only need to evaluate \( K_{x* x} \) when evaluating the fits (See the mean value in Eq.(S2) of same paper). The other term we need is alpha = \( K_{x x}^{-1} {\bf f}\), which involves the WhiteKernel, but is precomputed offline. alpha is a vector of size N, where N is the number of cases in the training data set.
x1 | Parameter space point 1. |
x2 | Parameter space point 2. |
hyperparams | GPR hyperparameters. |
dummy_worker | Dummy worker array for computations. |
Definition at line 520 of file LALSimNRHybSurUtilities.c.
|
static |
Evaluate a GPR fit.
See Eq.(S2) of arxiv:1809.09125.
xst | Point \( x_* \) where fit will be evaluated. |
hyperparams | Hyperparams for the GPR kernel. |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
Definition at line 548 of file LALSimNRHybSurUtilities.c.
REAL8 NRHybSur_eval_fit | ( | const NRHybSurFitData * | fit_data, |
const gsl_vector * | fit_params, | ||
const gsl_matrix * | x_train, | ||
gsl_vector * | dummy_worker | ||
) |
Evaluate a NRHybSur fit.
fit_data | Data for fit. |
fit_params | Parameter space point to evaluate the fit at. size=D, the dimension of the model. |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
Definition at line 581 of file LALSimNRHybSurUtilities.c.
|
static |
Evaluate a single NRHybSur waveform data piece.
result | Output: Should have already been assigned space. |
fit_params | Parameter space point to evaluate the fit at. size=D, the dimension of the model. |
data_piece | The waveform data piece to evaluate |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
Definition at line 611 of file LALSimNRHybSurUtilities.c.
|
static |
Do cubic spline interpolation using a gsl_interp_cspline.
Results differ slightly from scipy.interpolate.InterpolatedUnivariateSpline due to different boundary conditions.
gwsurrogate by default will use gsl_interp_cspline, and results should agree exactly. However, gwsurrogate also has the option to use scipy interpolation, in which case the waveform values at the start and end can be slightly different. gwsurrogate will only use the scipy interpolation if for some reasong the gsl build fails.
xout | The vector of points onto which we want to interpolate. |
x | The x values of the data to interpolate. |
y | The y values of the data to interpolate. |
Definition at line 650 of file LALSimNRHybSurUtilities.c.
|
static |
Computes omega_22 by forward differences.
times | Time array. |
phi_22 | Phase of (2,2) mode. |
idx | Index to compute omega_22 at. |
Definition at line 674 of file LALSimNRHybSurUtilities.c.
|
static |
Finds closest index such that omegaM_22[index] = omegaM_22_val.
omega_idx | Output: closest index such that omegaM_22[index] = omegaM_22_val. |
times | Time array. |
phi_22 | Phase of (2,2) mode. |
omegaM_22_val | Desired frequency of (2,2) mode. |
Definition at line 694 of file LALSimNRHybSurUtilities.c.
|
static |
Evaluate the phase of the (2,2) mode on the sprase surrogate domain.
The surrogate actually models the phase residual \( \phi^{res}_{22} \) defined in Eq.(44) of arxiv:1812.07865. Here we first evaluate that and then add the 0PN TaylorT3 phase to get the (2,2) mode phase.
phi_22_sparse | Output: (2,2) mode phase on sparse domain. |
eta | Symmetric mass ratio. |
fit_params | Parameter space point to evaluate the fit at. size=D, the dimension of the model. |
dummy_dp | Dummy vector to store phase evaluation. |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
NR_hybsur_data | Loaded surrogate data. |
Definition at line 740 of file LALSimNRHybSurUtilities.c.
|
static |
Upsamples sparse \( \phi_{22} \) such that time step size is deltaTOverM, and initial frequency is roughly omegaM_22_min.
The initial frequency will be refined later on.
phi_22_dense | Output: Densely sampled (2,2) mode phase. |
times_dense | Output: Dense time array. |
deltaTOverM | Time step in M. |
omegaM_22_min | Start frequency of (2,2) mode in rad/M. |
phi_22_sparse | (2,2) mode phase on sparse domain. |
domain | Sparse surrogate domain. |
Definition at line 794 of file LALSimNRHybSurUtilities.c.
int NRHybSur_eval_phase_22 | ( | gsl_vector ** | phi_22, |
gsl_vector ** | output_times, | ||
const REAL8 | eta, | ||
const gsl_vector * | fit_params, | ||
const REAL8 | omegaM_22_min, | ||
const REAL8 | deltaTOverM, | ||
const REAL8 | phiRef, | ||
const REAL8 | omegaM_22_ref, | ||
gsl_vector * | dummy_dp, | ||
const gsl_matrix * | x_train, | ||
gsl_vector * | dummy_worker, | ||
const NRHybSurData * | NR_hybsur_data | ||
) |
Evaluate the phase of the (2,2) mode.
The surrogate actually models the phase residual \( \phi^{res}_{22} \) defined in Eq.(44) of arxiv:1812.07865. Here we first evaluate that and then add the 0PN TaylorT3 phase to get the (2,2) mode phase.
Sets the orbital phase to phiRef at the reference frequency omegaM_22_ref. The orbital phase is obtained as phi_22/2, so this leaves a pi ambiguity. But the surrogate data is already aligned such that the heavier BH is on the +ve x-axis at t=-1000M. See Sec.VI.A.4 of arxiv:1812.07865, the resolves the pi ambiguity. This means that the after the realignment, the orbital phase at reference frequency omegaM_22_ref is phiRef, or the heavier BH is at azimuthal angle = phiRef from the +ve x-axis.
Only uses data at (2,2) mode frequencies >= omegaM_22_min. This determines the start time. The start time, along with the step size deltaTOverM, is used to determine the output_times. Uses cubic spline interpolation to interpolate from the surrogate's time array to output_times.
phi_22 | Output: (2,2) mode phase. |
output_times | Output: Time array. |
eta | Symmetric mass ratio. |
fit_params | Parameter space point to evaluate the fit at. size=D, the dimension of the model. |
omegaM_22_min | Start frequency of (2,2) mode in rad/M. |
deltaTOverM | Time step in M. |
phiRef | Orbital phase at reference frequency. |
omegaM_22_ref | Reference freq of (2,2) mode in rad/M. |
dummy_dp | Dummy vector to store phase evaluation. |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
NR_hybsur_data | Loaded surrogate data. |
Definition at line 887 of file LALSimNRHybSurUtilities.c.
int NRHybSur_eval_mode_data_pieces | ( | EvaluatedDataPieces ** | this_mode_eval_dp, |
const UINT4 | ell, | ||
const UINT4 | m, | ||
const ModeDataPieces * | data_pieces, | ||
const gsl_vector * | output_times, | ||
const gsl_vector * | fit_params, | ||
gsl_vector * | dummy_dp, | ||
const gsl_matrix * | x_train, | ||
gsl_vector * | dummy_worker, | ||
const NRHybSurData * | NR_hybsur_data | ||
) |
Evaluate waveform data pieces of a single mode.
For (2,2) mode we model the amplitude and phase, but the phase is evaluated using NRHybSur_eval_phase_22, since it is required for all modes to transform from the coorbital frame to the inertial frame. For all other modes we evaluate the real and imaginary parts of the coorbital frame strain, defined in Eq.(39) of arxiv:1812.07865.
Only the required data pieces for a given mode will be evaluated.
this_mode_eval_dp | Output: evaluated waveform data pieces of a single mode. |
ell | \(\ell\) index of mode. |
m | m index of mode. |
data_pieces | Surrogate data pieces of this mode. |
output_times | Time vector to evaluate at. |
fit_params | Parameter space point to evaluate the fit at. size=D, the dimension of the model. |
dummy_dp | Dummy vector to store phase evaluation. |
x_train | Training set points. |
dummy_worker | Dummy worker array for computations. |
NR_hybsur_data | Loaded surrogate data. |
Definition at line 978 of file LALSimNRHybSurUtilities.c.
void NRHybSur_DestroyEvaluatedDataPieces | ( | gsl_vector * | phi_22, |
EvaluatedDataPieces ** | evaluated_mode_dps, | ||
const UINT4 | num_modes_incl | ||
) |
Destroy phi_22 and an EvaluatedDataPieces structure.
Free all associated memory.
phi_22 | \(\phi_{22}\) data piece. |
evaluated_mode_dps | All other data pieces. |
num_modes_incl | Number of models included. |
Definition at line 1056 of file LALSimNRHybSurUtilities.c.
int NRHybSur_sanity_check_sample_rate | ( | REAL8 | deltaT, |
REAL8 | m1, | ||
REAL8 | m2, | ||
REAL8 | chi1z, | ||
REAL8 | chi2z, | ||
UINT4 | max_ell | ||
) |
Sanity check (warning only, not error) that the sample rate is high enough to capture the ringdown frequencies, by ensuring Nyquist frequency is greater than the QNM frequency of the (max_ell,max_ell,0) mode, where max_ell is the maximum ell index among the included modes.
deltaT | Sampling interval (s). |
m1 | Mass of Bh1 (kg). |
m2 | Mass of Bh2 (kg). |
chi1z | Dimensionless spin of Bh1. |
chi2z | Dimensionless spin of Bh2. |
max_ell | Max ell index included. |
Definition at line 1101 of file LALSimNRHybSurUtilities.c.
void NRHybSur_set_default_modes | ( | LALValue * | ModeArray, |
const NRHybSurData * | NR_hybsur_data | ||
) |
Activates all modes of an NRHybSur model.
For NRHybSur3dq8 that is \( \ell \leq 4, m \geq 0 \), and (5,5), but not (4,1) or (4,0).
ModeArray | Output: Container for modes. |
NR_hybsur_data | Loaded surrogate data. |
Definition at line 1151 of file LALSimNRHybSurUtilities.c.
int NRHybSur_check_mode_array | ( | UINT4 * | num_modes_incl, |
UINT4 * | max_ell, | ||
LALValue * | ModeArray, | ||
const NRHybSurData * | NR_hybsur_data | ||
) |
Sanity checks on ModeArray.
Will raise an error if an unavailable mode is requested. Note that we only look for m>=0 modes in ModeArray, and will ignore m<0 modes even if present. The m<0 modes automatically get added when evaluting the waveform.
num_modes_incl | Output: Number of modes to include. |
max_ell | Output: Max ell index included. |
ModeArray | Container for modes. |
NR_hybsur_data | Loaded surrogate data. |
Definition at line 1175 of file LALSimNRHybSurUtilities.c.