Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInferenceAnalyticLikelihood.c
Go to the documentation of this file.
1/*
2 * LALInferenceLikelihood.c: Bayesian Followup likelihood functions
3 *
4 * Copyright (C) 2009 Ilya Mandel, Vivien Raymond, Christian Roever,
5 * Marc van der Sluys and John Veitch, Will M. Farr, Salvatore Vitale
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with with program; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23#include <complex.h>
24#include <lal/LALInferenceLikelihood.h>
25#include <lal/LALInferencePrior.h>
26#include <lal/LALInference.h>
27#include <lal/DetResponse.h>
28#include <lal/TimeDelay.h>
29#include <lal/TimeSeries.h>
30#include <lal/Units.h>
31#include <lal/Sequence.h>
32#include <lal/FrequencySeries.h>
33#include <lal/TimeFreqFFT.h>
34#include <gsl/gsl_sf_bessel.h>
35#include <gsl/gsl_sf_bessel.h>
36#include <gsl/gsl_sf_dawson.h>
37#include <gsl/gsl_sf_erf.h>
38#include <gsl/gsl_complex_math.h>
39#include <lal/LALInferenceTemplate.h>
40
41/* Scaling used for the burst analytic likelihood parameters */
42// sqrt(bCM)/(scaling) is the sigma
43 static const REAL8 burst_scaling[9] = {
44 0.1,
45 1.0,
46 1.0,
47 100.0,
48 10.0/M_PI,
49 10.0/M_PI,
50 10.0/M_PI,
51 10.0/M_PI,
52 10.0};
53
54/* burst covariance matrix used in analyic likelihoods */
55/* Unimodal should give evidence -21.3,bimodal -25.9 */
56static const REAL8 bCM[9][9] = {{0.0118334553095770112635110,0.0101244893662672322265372,0.0164254129963652163726184,0.0112088766770308614906249,0.0148945067729633826014712,0.0176503111361420127189970,0.0122199881064022214394171,0.0139749282535349579614792,0.0},
57{0.0101244893662672322265372,0.0223414853900214364912369,0.0223978018917797665199299,0.0155692879011910430275822,0.0201008529429579502201264,0.0229538138342478409414937,0.0180642089428136622120125,0.0155199853453866446623133,0.0},
58{0.0164254129963652163726184,0.0223978018917797665199299,0.0372071319249132337336761,0.0269434973389567240797948,0.0277259617613290071380661,0.0321217958436038619751685,0.0325568864053485881870920,0.0283379829772117813879717,0.0},
59{0.0112088766770308614906249,0.0155692879011910430275822,0.0269434973389567240797948,0.0219637138989302732605680,0.0202889296069694510804560,0.0225846698886396080041550,0.0238719578697630489816373,0.0197015389277761104880327,0.0},
60{0.0148945067729633826014712,0.0201008529429579502201264,0.0277259617613290071380661,0.0202889296069694510804560,0.0310842562371710651181189,0.0334804433939082934923448,0.0233839662218643419555608,0.0266660912253427265228289,0.0},
61{0.0176503111361420127189970,0.0229538138342478409414937,0.0321217958436038619751685,0.0225846698886396080041550,0.0334804433939082934923448,0.0380576501276081793911921,0.0264526579842353157245860,0.0312117893830374908137326,0.0},
62{0.0122199881064022214394171,0.0180642089428136622120125,0.0325568864053485881870920,0.0238719578697630489816373,0.0233839662218643419555608,0.0264526579842353157245860,0.0305112248863869672810267,0.0256577816309597056543268,0.0},
63{0.0139749282535349579614792,0.0155199853453866446623133,0.0283379829772117813879717,0.0197015389277761104880327,0.0266660912253427265228289,0.0312117893830374908137326,0.0256577816309597056543268,0.0308105179275282164974570,0.0},
64{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.121}
65};
66
67const char *LALInferenceAnalyticNamesCBC[] = {"mass1","mass2","costheta_jn","phase","polarisation","rightascension","declination","logdistance","time","a_spin1","a_spin2","tilt_spin1", "tilt_spin2", "phi12", "phi_jl"};
68
70{
71 16.0, 7.0, 0.0, LAL_PI, LAL_PI, LAL_PI, 0.0, 4.0, 0.0, 0.5, 0.5, LAL_PI/2.0, LAL_PI/2.0, LAL_PI, LAL_PI
72};
73
74/* Scaling used for the CBC analytic likelihood parameters */
75const REAL8 scaling[15] = {
76 1.0,
77 1.0,
78 /*20.0/M_PI, */ 20.0,
79 10.0/M_PI,
80 20.0/M_PI,
81 10.0/M_PI,
82 10.0/M_PI,
83 /*0.1,*/ 10.0,
84 10.0,
85 10.0,
86 10.0,
87 20.0/M_PI,
88 20.0/M_PI,
89 10.0/M_PI,
90 10.0/M_PI};
91
92/* Covariance matrix for use in analytic likelihoods */
93const REAL8 CM[15][15] = {{0.045991865933182365, -0.005489748382557155, -0.01025067223674548, 0.0020087713726603213, -0.0032648855847982987, -0.0034218261781145264, -0.0037173401838545774, -0.007694897715679858, 0.005260905282822458, 0.0013607957548231718, 0.001970785895702776, 0.006708452591621081, -0.005107684668720825, 0.004402554308030673, -0.00334987648531921},
94 {-0.005489748382557152, 0.05478640427684032, -0.004786202916836846, -0.007930397407501268, -0.0005945107515129139, 0.004858466255616657, -0.011667819871670204, 0.003169780190169035, 0.006761345004654851, -0.0037599761532668475, 0.005571796842520162, -0.0071098291510566895, -0.004477773540640284, -0.011250694688474672, 0.007465228985669282},
95 {-0.01025067223674548, -0.004786202916836844, 0.044324704403674524, -0.0010572820723801645, -0.009885693540838514, -0.0048321205972943464, -0.004576186966267275, 0.0025107211483955676, -0.010126911913571181, 0.01153595152487264, 0.005773054728678472, 0.005286558230422045, -0.0055438798694137734, 0.0044772210361854765, -0.00620416958073918},
96 {0.0020087713726603213, -0.007930397407501268, -0.0010572820723801636, 0.029861342087731065, -0.007803477134405363, -0.0011466944120756021, 0.009925736654597632, -0.0007664415942207051, -0.0057593957402320385, -0.00027248233573270216, 0.003885350572544307, 0.00022362281488693097, 0.006609741178005571, -0.003292722856107429, -0.005873218251875897},
97 {-0.0032648855847982987, -0.0005945107515129156, -0.009885693540838514, -0.007803477134405362, 0.0538403407841302, -0.007446654755103316, -0.0025216534232170153, 0.004499568241334517, 0.009591034277125177, 0.00008612746932654223, 0.003386296829505543, -0.002600737873367083, 0.000621148057330571, -0.006603857049454523, -0.009241221870695395},
98 {-0.0034218261781145264, 0.004858466255616657, -0.004832120597294347, -0.0011466944120756015, -0.007446654755103318, 0.043746559133865104, 0.008962713024625965, -0.011099652042761613, -0.0006620240117921668, -0.0012591530037708058, -0.006899982952117269, 0.0019732354732442878, -0.002445676747004324, -0.006454778807421816, 0.0033303577606412765},
99 {-0.00371734018385458, -0.011667819871670206, -0.004576186966267273, 0.009925736654597632, -0.0025216534232170153, 0.008962713024625965, 0.03664582756831382, -0.009470328827284009, -0.006213741694945105, 0.007118775954484294, -0.0006741237990418526, -0.006003374957986355, 0.005718636997353189, -0.0005191095254772077, -0.008466566781233205},
100 {-0.007694897715679857, 0.0031697801901690347, 0.002510721148395566, -0.0007664415942207059, 0.004499568241334515, -0.011099652042761617, -0.009470328827284016, 0.057734267068088, 0.005521731225009532, -0.017008048805405164, 0.006749693090695894, -0.006348460110898, -0.007879244727681924, -0.005321753837620446, 0.011126783289057604},
101 {0.005260905282822458, 0.0067613450046548505, -0.010126911913571181, -0.00575939574023204, 0.009591034277125177, -0.0006620240117921668, -0.006213741694945106, 0.005521731225009532, 0.04610670018969681, -0.010427010812879566, -0.0009861561285861987, -0.008896020395949732, -0.0037627528719902485, 0.00033704453138913093, -0.003173552163182467},
102 {0.0013607957548231744, -0.0037599761532668475, 0.01153595152487264, -0.0002724823357326985, 0.0000861274693265406, -0.0012591530037708062, 0.007118775954484294, -0.01700804880540517, -0.010427010812879568, 0.05909125052583998, 0.002192545816395299, -0.002057672237277737, -0.004801518314458135, -0.014065326026662672, -0.005619012077114913},
103 {0.0019707858957027763, 0.005571796842520162, 0.005773054728678472, 0.003885350572544309, 0.003386296829505542, -0.006899982952117272, -0.0006741237990418522, 0.006749693090695893, -0.0009861561285862005, 0.0021925458163952988, 0.024417715762416557, -0.003037163447600162, -0.011173674374382736, -0.0008193127407211239, -0.007137012700864866},
104 {0.006708452591621083, -0.0071098291510566895, 0.005286558230422046, 0.00022362281488693216, -0.0026007378733670806, 0.0019732354732442886, -0.006003374957986352, -0.006348460110897999, -0.008896020395949732, -0.002057672237277737, -0.003037163447600163, 0.04762367868805726, 0.0008818947598625008, -0.0007262691465810616, -0.006482422704208912},
105 {-0.005107684668720825, -0.0044777735406402895, -0.005543879869413772, 0.006609741178005571, 0.0006211480573305693, -0.002445676747004324, 0.0057186369973531905, -0.00787924472768192, -0.003762752871990247, -0.004801518314458137, -0.011173674374382736, 0.0008818947598624995, 0.042639958466440225, 0.0010194948614718209, 0.0033872675386130637},
106 {0.004402554308030674, -0.011250694688474675, 0.004477221036185477, -0.003292722856107429, -0.006603857049454523, -0.006454778807421815, -0.0005191095254772072, -0.005321753837620446, 0.0003370445313891318, -0.014065326026662679, -0.0008193127407211239, -0.0007262691465810616, 0.0010194948614718226, 0.05244900188599414, -0.000256550861960499},
107 {-0.00334987648531921, 0.007465228985669282, -0.006204169580739178, -0.005873218251875899, -0.009241221870695395, 0.003330357760641278, -0.008466566781233205, 0.011126783289057604, -0.0031735521631824654, -0.005619012077114915, -0.007137012700864866, -0.006482422704208912, 0.0033872675386130632, -0.000256550861960499, 0.05380987317762257}};
108
109
110
111/* ============ Likelihood computations: ========== */
112
113
115
116 REAL8 mean[15];
117 UINT4 i=0;
118 memset(x, 0, 15*sizeof(REAL8));
119 memset(mean, 0, 15*sizeof(REAL8));
120
121 if (mode==0) { /* Univariate */
122 for(i=0;i<15;i++) mean[i]=LALInferenceAnalyticMeansCBC[i];
123 } else if (mode==1) {
124 for(i=0;i<15;i++) mean[i]=LALInferenceAnalyticMeansCBC[i] - 4.0/scaling[i]*sqrt(CM[i][i]);
125 } else if (mode==2) {
126 for(i=0;i<15;i++) mean[i]=LALInferenceAnalyticMeansCBC[i] + 4.0/scaling[i]*sqrt(CM[i][i]);
127 } else {
128 printf("Error! Unrecognized mode in analytic likelihood!\n");
129 exit(1);
130 }
131
132 for(i=0;i<15;i++)
133 {
135 }
136
137}
138
140 REAL8 frequency=100.,q=1.0,loghrss, psi, ra, dec, t,alpha=0.0,polar_eccentricity=0.0;
141 const UINT4 nparams=9;
142 REAL8 mean[nparams];
143
144 memset(x, 0, nparams*sizeof(REAL8));
145 memset(mean, 0, nparams*sizeof(REAL8));
146
147 if (mode==0) {
148 mean[0] = 211.0; // freq
149 mean[1] = 6.0; //quality
150 mean[2] = -46.; //loghrss
151 mean[3] = 0.001; //time
152 mean[4] = M_PI; //ra
153 mean[5] = 0.0; //dec
154 mean[6] = 0.7; //psi
155 mean[7] =0.5; // alpha (polar_angle)
156 mean[8] =0.25; // polar_eccentricity
157 } else if (mode==1) {
158 mean[0] = 211.0;
159 mean[1] = 6.0;
160 mean[2] = -46.;
161 mean[3] = 0.001;
162 mean[4] = M_PI;
163 mean[5] = 0.0;
164 mean[6] = 0.7;
165 mean[7] =0.5;
166 mean[8]= 0.25;
167 } else if (mode==2) {
168 /* set means of second mode to be 8 sigma from first mode */
169 mean[0] = 211 + 8./burst_scaling[0]*sqrt(bCM[0][0]);
170 mean[1] = 6.0 + 8./burst_scaling[1]*sqrt(bCM[1][1]);
171 mean[2] = -46. + 8./burst_scaling[2]*sqrt(bCM[2][2]);
172 mean[3] = 0.001 + 8./burst_scaling[3]*sqrt(bCM[3][3]);
173 mean[4] = M_PI + 8./burst_scaling[4]*sqrt(bCM[4][4]);
174 mean[5] = 0.0 + 8./burst_scaling[5]*sqrt(bCM[5][5]);
175 mean[6] = 0.7 + 8./burst_scaling[7]*sqrt(bCM[6][6]);
176 mean[7] = 0.5 + 8./burst_scaling[7]*sqrt(bCM[7][7]);
177 mean[8] = 0.25 + 8./burst_scaling[8]*sqrt(bCM[8][8]);
178 } else {
179 printf("Error! Unrecognized mode in analytic likelihood!\n");
180 exit(1);
181 }
182
183 loghrss = LALInferenceGetREAL8Variable(currentParams, "loghrss");
184 frequency = LALInferenceGetREAL8Variable(currentParams, "frequency");
186 psi = LALInferenceGetREAL8Variable(currentParams, "polarisation");
188 ra = LALInferenceGetREAL8Variable(currentParams, "rightascension");
189 dec = LALInferenceGetREAL8Variable(currentParams, "declination");
191 polar_eccentricity= LALInferenceGetREAL8Variable(currentParams, "polar_eccentricity");
192 x[0] = burst_scaling[0] * (frequency - mean[0]);
193 x[1] = burst_scaling[1] * (q - mean[1]);
194 x[2] = burst_scaling[2] * (loghrss - mean[2]);
195 x[3] = burst_scaling[3] * (t - mean[3]);
196 x[4] = burst_scaling[4] * (ra - mean[4]);
197 x[5] = burst_scaling[5] * (dec - mean[5]);
198 x[6] = burst_scaling[6] * (psi - mean[6]);
199 x[7] = burst_scaling[7] * (alpha - mean[7]);
200 x[8] = burst_scaling[8] * (polar_eccentricity - mean[8]);
201}
202
205 LALInferenceModel *model) {
206 INT4 tmpdim=0;
207 int cbc=1;
208 const REAL8 *cm=NULL;
209 int ifo=0;
210 while(data){
211 model->ifo_loglikelihoods[ifo]=0.0;
212 ifo++;
213 data=data->next;
214 }
215
216 if (LALInferenceCheckVariable(currentParams, "logdistance")){
217 /* We are dealing with spinning CBC. Set dimensions and CVM accordingly*/
218 tmpdim = 15;
219 cm=&(CM[0][0]);
220 }
222 /* We are dealing with a burst. Set dimensions and CVM accordinly*/
223 tmpdim = 9;
224 cm=&(bCM[0][0]);
225 cbc=0;
226 }
227 const INT4 DIM = tmpdim;
228 gsl_matrix *LUCM = NULL;
229 gsl_permutation *LUCMPerm = NULL;
230 INT4 mode = 0;
231
232 REAL8 x[DIM];
233 REAL8 xOrig[DIM];
234
235 gsl_vector_view xView = gsl_vector_view_array(x, DIM);
236
237 if (cbc==1)
239 else
241
242 memcpy(xOrig, x, DIM*sizeof(REAL8));
243
244 if (LUCM==NULL) {
245 gsl_matrix_const_view CMView = gsl_matrix_const_view_array(cm, DIM, DIM);
246 int signum;
247
248 LUCM = gsl_matrix_alloc(DIM, DIM);
249 LUCMPerm = gsl_permutation_alloc(DIM);
250
251 gsl_matrix_memcpy(LUCM, &(CMView.matrix));
252
253 gsl_linalg_LU_decomp(LUCM, LUCMPerm, &signum);
254 }
255
256 gsl_linalg_LU_svx(LUCM, LUCMPerm, &(xView.vector));
257
258 INT4 i;
259 REAL8 sum = 0.0;
260 for (i = 0; i < DIM; i++) {
261 sum += xOrig[i]*x[i];
262 }
263 if(LUCM) gsl_matrix_free(LUCM);
264 if(LUCMPerm) gsl_permutation_free(LUCMPerm);
265 return -sum/2.0;
266}
267
270 LALInferenceModel *model) {
271 INT4 tmpdim=0;
272 int cbc=1;
273 const REAL8 *cm=NULL;
274 int ifo=0;
275 while(data){
276 model->ifo_loglikelihoods[ifo]=0.0;
277 ifo++;
278 data=data->next;
279 }
280
281 if (LALInferenceCheckVariable(currentParams, "logdistance")){
282 /* We are dealing with spinning CBC. Set dimensions and CVM accordingly*/
283 tmpdim = 15;
284 cm=&(CM[0][0]);
285 }
287 /* We are dealing with a burst. Set dimensions and CVM accordingly*/
288 tmpdim = 9;
289 cm=&(bCM[0][0]);
290 cbc=0;
291 }
292 const INT4 MODES = 2;
293 const INT4 DIM = tmpdim;
294 INT4 i, mode;
295 REAL8 sum = 0.0;
296 REAL8 a, b;
297 gsl_matrix *LUCM = NULL;
298 gsl_permutation *LUCMPerm = NULL;
299 gsl_vector_view xView;
300
301 REAL8 x[DIM];
302 REAL8 xOrig[DIM];
303 REAL8 exps[MODES];
304
305 if (LUCM==NULL) {
306 gsl_matrix_const_view CMView = gsl_matrix_const_view_array(cm, DIM, DIM);
307 int signum;
308
309 LUCM = gsl_matrix_alloc(DIM, DIM);
310 LUCMPerm = gsl_permutation_alloc(DIM);
311
312 gsl_matrix_memcpy(LUCM, &(CMView.matrix));
313
314 gsl_linalg_LU_decomp(LUCM, LUCMPerm, &signum);
315 }
316
317 for(mode = 1; mode < 3; mode++) {
318 xView = gsl_vector_view_array(x, DIM);
319 if (cbc==1)
321 else
323
324 memcpy(xOrig, x, DIM*sizeof(REAL8));
325
326 gsl_linalg_LU_svx(LUCM, LUCMPerm, &(xView.vector));
327
328 sum = 0.0;
329 for (i = 0; i < DIM; i++) {
330 sum += xOrig[i]*x[i];
331 }
332 exps[mode-1] = -sum/2.0;
333 }
334
335 /* Assumes only two modes used from here on out */
336 if (exps[0] > exps[1]) {
337 a = exps[0];
338 b = exps[1];
339 } else {
340 a = exps[1];
341 b = exps[0];
342 }
343 /* attempt to keep returned values finite */
344 if(LUCM) gsl_matrix_free(LUCM);
345 if(LUCMPerm) gsl_permutation_free(LUCMPerm);
346 return a + log1p(exp(b-a));
347}
348
351 LALInferenceModel *model) {
352 const INT4 DIM = 15;
353 REAL8 x[DIM];
354
355 REAL8 sum = 0;
356 INT4 mode = 0;
357 INT4 i;
358 int ifo=0;
359 while(data){
360 model->ifo_loglikelihoods[ifo]=0.0;
361 ifo++;
362 data=data->next;
363 }
365
366 for (i = 0; i < DIM; i++) x[i] += 1.0;
367
368 for (i = 0; i < DIM-1; i++) {
369 REAL8 oneMX = 1.0 - x[i];
370 REAL8 dx = x[i+1] - x[i]*x[i];
371
372 sum += oneMX*oneMX + 100.0*dx*dx;
373 }
374
375 return -sum;
376}
static void extractDimensionlessVariableVector(LALInferenceVariables *currentParams, REAL8 *x, INT4 mode)
const REAL8 CM[15][15]
const REAL8 scaling[15]
static const REAL8 burst_scaling[9]
const char * LALInferenceAnalyticNamesCBC[]
static void extractBurstDimensionlessVariableVector(LALInferenceVariables *currentParams, REAL8 *x, INT4 mode)
const REAL8 LALInferenceAnalyticMeansCBC[]
static const REAL8 bCM[9][9]
static REAL8 mean(REAL8 *array, int N)
LALInferenceVariables currentParams
sigmaKerr data[0]
#define LAL_PI
double REAL8
uint32_t UINT4
int32_t INT4
REAL8 LALInferenceGetREAL8Variable(LALInferenceVariables *vars, const char *name)
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
Definition: LALInference.c:525
REAL8 LALInferenceBimodalCorrelatedAnalyticLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
An analytic likeilhood that is two correlated Gaussians in 15 dimensions.
REAL8 LALInferenceCorrelatedAnalyticLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
An analytic likeilhood that is a correlated Gaussian in 15 dimensions.
REAL8 LALInferenceRosenbrockLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
15-D Rosenbrock log(L) function (see Eq (3) of http://en.wikipedia.org/wiki/Rosenbrock_function .
static const INT4 q
static const INT4 a
double alpha
Structure to contain IFO data.
Definition: LALInference.h:625
Structure to constain a model and its parameters.
Definition: LALInference.h:436
REAL8 * ifo_loglikelihoods
Network SNR at params
Definition: LALInference.h:445
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
Definition: LALInference.h:170