Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALSimulation 6.2.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALSimNRHybSurUtilities.h
Go to the documentation of this file.
1/* Copyright (C) 2018 Vijay Varma
2 * Utility functions that are useful for evaluating NRHybrid surrogates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with with program; see the file COPYING. If not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 */
19
20/**
21 * \author Vijay Varma
22 *
23 * \file
24 *
25 * \brief Utilities needed for aligned-spin NR-hybrid surrogate models.
26 *
27 * Called from:
28 * LALSimIMRNRHybSur3dq8.h
29 */
30
31#include <gsl/gsl_vector.h>
32#include <gsl/gsl_matrix.h>
33
34#include <lal/LALSimIMR.h>
35#ifdef LAL_HDF5_ENABLED
36#include <lal/H5FileIO.h>
37#endif
38
39//*************************************************************************/
40//************************* struct definitions ****************************/
41//*************************************************************************/
42
43/**
44 * Data used in a single GPR fit.
45 *
46 * We follow sklearn closely. We use the kernel given in
47 * Eq.(S3) of arxiv:1809.09125 :
48 * \f[
49 * K(x, x') = \sigma_k^2 exp(-1/2 \sum_i^D (x^{i} - x'^{i})^2/\sigma_i^2)
50 * \f]
51 * where D is the dimension of the model.
52 *
53 * Note that Eq.(S3) also includes the WhiteKernel, which has a noise
54 * parameter, but we don't need that here since we only need to evaluate \f$
55 * K_{x* x} \f$ when evaluating the fits (See the mean value in Eq.(S2) of same
56 * paper). The other term we need is alpha = \f$ K_{x x}^{-1} {\bf f}\f$, which
57 * involves the WhiteKernel, but is precomputed offline. alpha is a vector of
58 * size N, where N is the number of cases in the training data set.
59 */
60typedef struct tagGPRHyperParams {
61 REAL8 constant_value; /**< \f$ \sigma_k^2 \f$ in kernel. */
62 REAL8 y_train_mean; /**< Mean value before GPR fit, usually zero. */
63 gsl_vector *length_scale; /**< \f$ \sigma_i \f$ in kernel. */
64 gsl_vector *alpha; /**< Precomputed \f$ K_{x x}^{-1} {\bf f}\f$. */
66
67/**
68 * Data used in a single NRHybSur fit.
69 *
70 * Described in supplemental materials of arxiv:1809.09125.
71 * We first subtract a linear fit to the data. Then we subtract the mean of
72 * the resulting values. Then we normalize by dividing by the standard
73 * deviation of the resulting values. Finally, we construct a GPR fit for the
74 * resulting values. Below, D = dimension of the model.
75 */
76typedef struct tagNRHybSurFitData {
77 REAL8 data_mean; /**< Mean of data after linear fit. */
78 REAL8 data_std; /**< Standard deviation after removing mean. */
79 REAL8 lin_intercept; /**< Constant intercept from linear fit. */
80 gsl_vector *lin_coef; /**< Linear coefs from linear fit, size=D. */
81 GPRHyperParams *hyperparams; /**< Hyperparameters from GPR fit. */
83
84/**
85 * NRHybSur data for a single waveform data piece.
86 */
87typedef struct tagDataPiece {
88 int n_nodes; /**< Number of empirical nodes. */
89 NRHybSurFitData **fit_data; /**< NRHybSurFitData at each empirical node. */
90 gsl_matrix *ei_basis; /**< Empirical interpolation matrix. */
91} DataPiece;
92
93/**
94 * NRHybSur data pieces of a single mode.
95 *
96 * The different data pieces are described in Sec.VI.B of arxiv:1812.07865.
97 * For (2,2) mode we model the amplitude \f$ A_{22} \f$ and phase residual
98 * \f$ \phi^{res}_{22} \f$ defined in Eq.(44) of arxiv:1812.07865.
99 * For all other modes we model the real and imaginary parts of the coorbital
100 * frame strain, defined in Eq.(39) of arxiv:1812.07865.
101 * Only the required data pieces for a given mode will be loaded.
102 */
103typedef struct tagModeDataPieces {
104 UINT4 ell; /**< Mode \f$ \ell \f$ value. */
105 UINT4 m; /**< Mode m value. */
106 DataPiece *ampl_data_piece; /**< Amplitude data piece. */
107 DataPiece *phase_res_data_piece; /**< Phase residual data piece. */
108 DataPiece *coorb_re_data_piece;/**< Coorbital frame real part data piece. */
109 DataPiece *coorb_im_data_piece;/**< Coorbital frame imag part data piece. */
111
112/**
113 * NRHybSur surrogate data for all modes, to be loaded from a h5 file.
114 */
115typedef struct tagNRHybSurData {
116 UINT4 setup; /**< Indicates if NRHybSur has been initialized */
117 UINT4 num_modes_modeled; /**< Number of modeled modes. */
118 int phaseAlignIdx; /**< Alignment index for phase data piece. */
119 REAL8 params_dim; /**< Dimensions of the model. */
120 gsl_vector *domain; /**< Common time samples for the surrogate. */
121 gsl_vector *TaylorT3_factor_without_eta; /**< Precomputed quantity for use
122 in evaluating the 0PN TaylorT3 phase contribution. */
123 gsl_matrix_long *mode_list; /**< List of modeled modes, first element is
124 always (2,2). */
125 gsl_matrix *x_train; /**< Training set parameters, needed for GPR fits. */
126 ModeDataPieces **mode_data_pieces; /**< Data pieces of all modes, same
127 order as mode_list. */
129
130/**
131 * NRHybSur evaluated data for a single mode
132 *
133 * For the (2,2) mode only the amplitude is stored in this struct. The phase
134 * is computed separately as it is needed for all modes to transform from the
135 * coorbital frame to the inertial frame.
136 * For all other modes the real and imaginary parts of the strain in the
137 * coorbital frame are stored.
138 * Only the required data pieces for a given mode will be evaluated.
139 */
140typedef struct tagEvaluatedDataPieces {
141 UINT4 ell; /**< Mode \f$ \ell \f$ value. */
142 UINT4 m; /**< Mode m value. */
143 gsl_vector *ampl_eval; /**< Amplitude data piece evaluation. */
144 gsl_vector *coorb_re_eval; /**< Coorbital frame real part evaluation. */
145 gsl_vector *coorb_im_eval; /**< Coorbital frame imag part evaluation. */
147
148
149#ifdef LAL_HDF5_ENABLED
150//*************************************************************************/
151//************************* function declarations *************************/
152//*************************************************************************/
153
154int ReadHDF5DoubleDataset(
155 REAL8 *param,
156 LALH5File *sub,
157 const char *name
158);
159
160int ReadHDF5IntDataset(
161 int *param,
162 LALH5File *sub,
163 const char *name
164);
165
166int NRHybSur_Init(
169 );
170#endif
171
173 const NRHybSurFitData *fit_data,
174 const gsl_vector *fit_params,
175 const gsl_matrix *x_train,
176 gsl_vector *dummy_worker
177);
178
180 gsl_vector **phi_22,
181 gsl_vector **output_times,
182 const REAL8 eta,
183 const gsl_vector *fit_params,
184 const REAL8 omegaM_22_min,
185 const REAL8 deltaTOverM,
186 const REAL8 phiRef,
187 const REAL8 omegaM_22_ref,
188 gsl_vector *dummy_dp,
189 const gsl_matrix *x_train,
190 gsl_vector *dummy_worker,
191 const NRHybSurData *NR_hybsur_data
192);
193
195 EvaluatedDataPieces **this_mode_eval_dp,
196 const UINT4 ell,
197 const UINT4 m,
198 const ModeDataPieces *data_pieces,
199 const gsl_vector *output_times,
200 const gsl_vector *fit_params,
201 gsl_vector *dummy_dp,
202 const gsl_matrix *x_train,
203 gsl_vector *dummy_worker,
204 const NRHybSurData *NR_hybsur_data
205);
206
208 gsl_vector *phi_22,
209 EvaluatedDataPieces **evaluated_mode_dps,
210 const UINT4 num_modes_incl
211);
212
215 REAL8 m1,
216 REAL8 m2,
217 REAL8 chi1z,
218 REAL8 chi2z,
219 UINT4 max_ell
220);
221
223 LALValue *ModeArray,
224 const NRHybSurData *NR_hybsur_data
225 );
226
228 UINT4 *num_modes_incl,
229 UINT4 *max_ell,
230 LALValue *ModeArray,
231 const NRHybSurData *NR_hybsur_data
232 );
struct tagLALH5File LALH5File
const char * name
int NRHybSur_check_mode_array(UINT4 *num_modes_incl, UINT4 *max_ell, LALValue *ModeArray, const NRHybSurData *NR_hybsur_data)
Sanity checks on ModeArray.
void NRHybSur_set_default_modes(LALValue *ModeArray, const NRHybSurData *NR_hybsur_data)
Activates all modes of an NRHybSur model.
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.
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.
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 fr...
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.
void NRHybSur_DestroyEvaluatedDataPieces(gsl_vector *phi_22, EvaluatedDataPieces **evaluated_mode_dps, const UINT4 num_modes_incl)
Destroy phi_22 and an EvaluatedDataPieces structure.
sigmaKerr data[0]
double REAL8
uint32_t UINT4
static const INT4 m
NRHybSur data for a single waveform data piece.
int n_nodes
Number of empirical nodes.
NRHybSurFitData ** fit_data
NRHybSurFitData at each empirical node.
gsl_matrix * ei_basis
Empirical interpolation matrix.
NRHybSur evaluated data for a single mode.
gsl_vector * coorb_re_eval
Coorbital frame real part evaluation.
gsl_vector * ampl_eval
Amplitude data piece evaluation.
gsl_vector * coorb_im_eval
Coorbital frame imag part evaluation.
Data used in a single GPR fit.
REAL8 constant_value
in kernel.
gsl_vector * alpha
Precomputed .
gsl_vector * length_scale
in kernel.
REAL8 y_train_mean
Mean value before GPR fit, usually zero.
NRHybSur data pieces of a single mode.
DataPiece * phase_res_data_piece
Phase residual data piece.
UINT4 m
Mode m value.
DataPiece * ampl_data_piece
Amplitude data piece.
UINT4 ell
Mode value.
DataPiece * coorb_im_data_piece
Coorbital frame imag part data piece.
DataPiece * coorb_re_data_piece
Coorbital frame real part data piece.
NRHybSur surrogate data for all modes, to be loaded from a h5 file.
ModeDataPieces ** mode_data_pieces
Data pieces of all modes, same order as mode_list.
gsl_vector * domain
Common time samples for the surrogate.
gsl_vector * TaylorT3_factor_without_eta
Precomputed quantity for use in evaluating the 0PN TaylorT3 phase contribution.
REAL8 params_dim
Dimensions of the model.
UINT4 setup
Indicates if NRHybSur has been initialized.
gsl_matrix * x_train
Training set parameters, needed for GPR fits.
int phaseAlignIdx
Alignment index for phase data piece.
UINT4 num_modes_modeled
Number of modeled modes.
gsl_matrix_long * mode_list
List of modeled modes, first element is always (2,2).
Data used in a single NRHybSur fit.
REAL8 data_std
Standard deviation after removing mean.
REAL8 data_mean
Mean of data after linear fit.
GPRHyperParams * hyperparams
Hyperparameters from GPR fit.
gsl_vector * lin_coef
Linear coefs from linear fit, size=D.
REAL8 lin_intercept
Constant intercept from linear fit.
double deltaT
Definition: unicorn.c:24