Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ppe_likelihood.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2014 Matthew Pitkin
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 * \file
22 * \ingroup lalpulsar_bin_HeterodyneSearch
23 * \author Matthew Pitkin, John Veitch, Colin Gill
24 *
25 * \brief Pulsar likelihood and prior functions for use in parameter estimation
26 * codes for targeted pulsar searches.
27 */
28
29#include "config.h"
30#include "ppe_likelihood.h"
31
32/******************************************************************************/
33/* LIKELIHOOD AND PRIOR FUNCTIONS */
34/******************************************************************************/
35/**
36 * \brief The log likelihood function
37 *
38 * This function calculates natural logarithm of the likelihood of a signal model (specified by a given set of
39 * parameters) given the data from a set of detectors.
40 *
41 * The likelihood is the joint likelihood of chunks of data over which the noise is assumed stationary and Gaussian. For
42 * each chunk a Gaussian likelihood for the noise and data has been marginalised over the unknown noise standard
43 * deviation using a Jeffreys prior on the standard deviation. Given the data consisting of independent real and
44 * imaginary parts this gives a Students-t distribution for each chunk (of length \f$ m \f$ ) with \f$ m/2 \f$ degrees of
45 * freedom:
46 * \f[
47 * p(\mathbf{\theta}|\mathbf{B}) = \prod_{j=1}^M \frac{(m_j-1)!}{2\pi^{m_j}}
48 * \left( \sum_{k=k_0}^{k_0+(m_j-1)} |B_k - y(\mathbf{\theta})_k|^2
49 * \right)^{-m_j},
50 * \f]
51 * where \f$ \mathbf{B} \f$ is a vector of the complex data, \f$ y(\mathbf{\theta}) \f$ is the model for a set of parameters
52 * \f$ \mathbf{\theta} \f$ , \f$ M \f$ is the total number of independent data chunks with lengths \f$ m_j \f$ and \f$ k_0 =
53 * \sum_{i=1}^j 1 + m_{i-1} \f$ (with \f$ m_0 = 0 \f$ ) is the index of the first data point in each chunk. The product of
54 * this for each detector will give the full joint likelihood. See \cite DupuisWoan2005 for a
55 * more detailed description.
56 *
57 * In this function data in chunks smaller than a certain minimum length \c chunkMin are ignored.
58 *
59 * \param vars [in] The parameter values
60 * \param data [in] The detector data and initial signal phase template
61 * \param get_model [in] The signal model structure
62 *
63 * \return The natural logarithm of the likelihood function
64 */
66 LALInferenceModel *get_model )
67{
68 REAL8 loglike = 0.; /* the log likelihood */
69 UINT4 i = 0, ifo = 0, nonGR = 0, roq = 0;
70 INT4 gaussianLike = 0;
71 LALInferenceIFOModel *ifomodeltemp = get_model->ifo;
72 LALInferenceIFOData *tempdata = data;
73
74 /* copy model parameters to data parameters */
75 LALInferenceCopyVariables( vars, get_model->params );
76
77 /* get pulsar model (this will internally loop over all data frequency streams and IFOs) */
78 get_model->templt( get_model );
79
80 if ( LALInferenceCheckVariable( ifomodeltemp->params, "nonGR" ) ) {
81 nonGR = 1;
82 }
83 if ( LALInferenceCheckVariable( ifomodeltemp->params, "roq" ) ) {
84 roq = 1;
85 }
86
87 while ( tempdata ) {
88 /* check if using a Gaussian likelihood - default is the students-t */
89 if ( LALInferenceCheckVariable( ifomodeltemp->params, "gaussianLikelihood" ) ) {
90 gaussianLike = 1;
91 }
92
93 get_model->ifo_loglikelihoods[ifo] = 0.0;
94
95 REAL8Vector *sumDat = NULL;
96 UINT4Vector *chunkLengths = NULL;
97 UINT4 chunkMin, j = 0, count = 0, cl = 0;
98 REAL8 chunkLength = 0., logliketmp = 0., chiSquare = 0.;
99
100 sumDat = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumData" );
101 chunkLengths = *( UINT4Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "chunkLength" );
102 chunkMin = *( INT4 * )LALInferenceGetVariable( ifomodeltemp->params, "chunkMin" );
103
104 if ( !roq ) { /* not using reduced order quadrature to calculate likelihood */
105 UINT4 length = 0;
106 REAL8 sumModel = 0., sumDataModel = 0.;
107 COMPLEX16 B = 0., M = 0., Mp = 0., Mc = 0., vari = 0.;
108
109 REAL8Vector *sumP = NULL, *sumC = NULL, *sumX = NULL, *sumY = NULL, *sumB = NULL, *sumL = NULL;
110 REAL8Vector *sumPC = NULL, *sumPX = NULL, *sumPY = NULL, *sumPB = NULL, *sumPL = NULL;
111 REAL8Vector *sumCX = NULL, *sumCY = NULL, *sumCB = NULL, *sumCL = NULL;
112 REAL8Vector *sumXY = NULL, *sumXB = NULL, *sumXL = NULL;
113 REAL8Vector *sumYB = NULL, *sumYL = NULL;
114 REAL8Vector *sumBL = NULL;
115
116 COMPLEX16Vector *sumDataP = NULL, *sumDataC = NULL, *sumDataX = NULL, *sumDataY = NULL, *sumDataB = NULL, *sumDataL = NULL;
117 INT4 varyphase = 0;
118
119 if ( LALInferenceCheckVariable( ifomodeltemp->params, "varyphase" ) ) {
120 varyphase = 1;
121 }
122
123 length = tempdata->compTimeData->data->length;
124
125 /* get pre-summed antenna pattern values if required */
126 if ( !varyphase ) {
127 sumP = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumP" );
128 sumC = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumC" );
129 sumPC = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumPC" );
130 sumDataP = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataP" );
131 sumDataC = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataC" );
132
133 /* get non-GR components */
134 if ( nonGR ) {
135 sumX = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumX" );
136 sumY = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumY" );
137 sumB = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumB" );
138 sumL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumL" );
139
140 sumPX = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumPX" );
141 sumPY = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumPY" );
142 sumPB = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumPB" );
143 sumPL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumPL" );
144 sumCX = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumCX" );
145 sumCY = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumCY" );
146 sumCB = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumCB" );
147 sumCL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumCL" );
148 sumXY = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumXY" );
149 sumXB = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumXB" );
150 sumXL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumXL" );
151 sumYB = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumYB" );
152 sumYL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumYL" );
153 sumBL = *( REAL8Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumBL" );
154
155 sumDataX = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataX" );
156 sumDataY = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataY" );
157 sumDataB = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataB" );
158 sumDataL = *( COMPLEX16Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "sumDataL" );
159 }
160 }
161
162 for ( i = 0 ; i < length ; i += chunkLength ) {
163 chunkLength = ( REAL8 )chunkLengths->data[count];
164
165 /* skip section of data if its length is less than the minimum allowed chunk length */
166 if ( chunkLength < chunkMin ) {
167 count++;
168 continue;
169 }
170
171 sumModel = 0.;
172 sumDataModel = 0.;
173
174 cl = i + ( INT4 )chunkLength;
175
176 if ( varyphase ) { /* not using pre-summed values */
177 for ( j = i ; j < cl ; j++ ) {
178 B = tempdata->compTimeData->data->data[j];
179 M = ifomodeltemp->compTimeSignal->data->data[j];
180
181 vari = 1.;
182 if ( gaussianLike ) {
183 vari = tempdata->varTimeData->data->data[j];
184 }
185
186 /* sum over the model */
187 sumModel += ( creal( M ) * creal( M ) + cimag( M ) * cimag( M ) ) / vari;
188
189 /* sum over that data and model */
190 sumDataModel += ( creal( B ) * creal( M ) + cimag( B ) * cimag( M ) ) / vari;
191 }
192 } else { /* using pre-summed data */
193 Mp = ifomodeltemp->compTimeSignal->data->data[0];
194 Mc = ifomodeltemp->compTimeSignal->data->data[1];
195
196 sumModel += sumP->data[count] * ( creal( Mp ) * creal( Mp ) + cimag( Mp ) * cimag( Mp ) ) +
197 sumC->data[count] * ( creal( Mc ) * creal( Mc ) + cimag( Mc ) * cimag( Mc ) ) +
198 2.*sumPC->data[count] * ( creal( Mp ) * creal( Mc ) + cimag( Mp ) * cimag( Mc ) );
199
200 sumDataModel += creal( sumDataP->data[count] ) * creal( Mp ) + cimag( sumDataP->data[count] ) * cimag( Mp ) +
201 creal( sumDataC->data[count] ) * creal( Mc ) + cimag( sumDataC->data[count] ) * cimag( Mc );
202
203 if ( nonGR ) {
204 COMPLEX16 Mx = 0., My = 0., Mb = 0., Ml = 0.;
205
206 Mx = ifomodeltemp->compTimeSignal->data->data[2];
207 My = ifomodeltemp->compTimeSignal->data->data[3];
208 Mb = ifomodeltemp->compTimeSignal->data->data[4];
209 Ml = ifomodeltemp->compTimeSignal->data->data[5];
210
211 sumModel += sumX->data[count] * ( creal( Mx ) * creal( Mx ) + cimag( Mx ) * cimag( Mx ) ) +
212 sumY->data[count] * ( creal( My ) * creal( My ) + cimag( My ) * cimag( My ) ) +
213 sumB->data[count] * ( creal( Mb ) * creal( Mb ) + cimag( Mb ) * cimag( Mb ) ) +
214 sumL->data[count] * ( creal( Ml ) * creal( Ml ) + cimag( Ml ) * cimag( Ml ) ) +
215 2.*( sumPX->data[count] * ( creal( Mp ) * creal( Mx ) + cimag( Mp ) * cimag( Mx ) ) +
216 sumPY->data[count] * ( creal( Mp ) * creal( My ) + cimag( Mp ) * cimag( My ) ) +
217 sumPB->data[count] * ( creal( Mp ) * creal( Mb ) + cimag( Mp ) * cimag( Mb ) ) +
218 sumPL->data[count] * ( creal( Mp ) * creal( Ml ) + cimag( Mp ) * cimag( Ml ) ) +
219 sumCX->data[count] * ( creal( Mc ) * creal( Mx ) + cimag( Mc ) * cimag( Mx ) ) +
220 sumCY->data[count] * ( creal( Mc ) * creal( My ) + cimag( Mc ) * cimag( My ) ) +
221 sumCB->data[count] * ( creal( Mc ) * creal( Mb ) + cimag( Mc ) * cimag( Mb ) ) +
222 sumCL->data[count] * ( creal( Mc ) * creal( Ml ) + cimag( Mc ) * cimag( Ml ) ) +
223 sumXY->data[count] * ( creal( Mx ) * creal( My ) + cimag( Mx ) * cimag( My ) ) +
224 sumXB->data[count] * ( creal( Mx ) * creal( Mb ) + cimag( Mx ) * cimag( Mb ) ) +
225 sumXL->data[count] * ( creal( Mx ) * creal( Ml ) + cimag( Mx ) * cimag( Ml ) ) +
226 sumYB->data[count] * ( creal( My ) * creal( Mb ) + cimag( My ) * cimag( Mb ) ) +
227 sumYL->data[count] * ( creal( My ) * creal( Ml ) + cimag( My ) * cimag( Ml ) ) +
228 sumBL->data[count] * ( creal( Mb ) * creal( Ml ) + cimag( Mb ) * cimag( Ml ) ) );
229
230 sumDataModel += creal( sumDataX->data[count] ) * creal( Mx ) + cimag( sumDataX->data[count] ) * cimag( Mx ) +
231 creal( sumDataY->data[count] ) * creal( My ) + cimag( sumDataY->data[count] ) * cimag( My ) +
232 creal( sumDataB->data[count] ) * creal( Mb ) + cimag( sumDataB->data[count] ) * cimag( Mb ) +
233 creal( sumDataL->data[count] ) * creal( Ml ) + cimag( sumDataL->data[count] ) * cimag( Ml );
234 }
235 }
236
237 chiSquare = sumDat->data[count] - 2.*sumDataModel + sumModel;
238
239 if ( !gaussianLike ) { /* using Students-t likelihood */
240 logliketmp += ( gsl_sf_lnfact( chunkLength - 1 ) - LAL_LN2 - chunkLength * LAL_LNPI );
241 logliketmp -= chunkLength * log( chiSquare );
242 } else { /* using Gaussian likelihood */
243 logliketmp -= 0.5 * chiSquare;
244 }
245
246 count++;
247 }
248 } else { /* using ROQ to get likelihoods */
249 UINT4Vector *numbases = *( UINT4Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "numBases" );
250 UINT4Vector *numbasesquad = *( UINT4Vector ** )LALInferenceGetVariable( ifomodeltemp->params, "numBasesQuad" );
251
252 UINT4 vstart = 0, mstart = 0, dstart = 0;
253
254 /* loop over chunks */
255 for ( i = 0; i < chunkLengths->length; i++ ) {
256 COMPLEX16Vector dmweights;
257 REAL8Vector mmweights;
258
259 chunkLength = ( REAL8 )chunkLengths->data[i];
260
261 /* get the weights for this chunk */
262 dmweights.data = &tempdata->roq->weightsLinear[vstart];
263 dmweights.length = numbases->data[i];
264
265 mmweights.data = &tempdata->roq->weightsQuadratic[mstart];
266 mmweights.length = numbasesquad->data[i];
267
268 /* get data/model term */
269 COMPLEX16Vector cmodel; /* get vector view of required chuck of data */
270 cmodel.data = &ifomodeltemp->compTimeSignal->data->data[dstart];
271 cmodel.length = numbases->data[i];
272
273 dstart += numbases->data[i]; /* increment where the model starts */
274
275 /* get the quadratic of the model */
276 REAL8Vector *quadmodel = XLALCreateREAL8Vector( numbasesquad->data[i] );
277 for ( UINT4 idx = 0; idx < quadmodel->length; idx++ ) {
278 COMPLEX16 qval = ifomodeltemp->compTimeSignal->data->data[dstart + idx];
279 quadmodel->data[idx] = creal( qval * conj( qval ) );
280 }
281 dstart += numbasesquad->data[i]; /* increment where the model starts */
282
283 COMPLEX16 dm = LALInferenceROQCOMPLEX16DotProduct( &dmweights, &cmodel );
284 REAL8 mm = LALInferenceROQREAL8DotProduct( &mmweights, quadmodel );
285
286 XLALDestroyREAL8Vector( quadmodel );
287
288 chiSquare = sumDat->data[i] - 2.*creal( dm ) + mm;
289
290 if ( !gaussianLike ) { /* using Students-t likelihood */
291 logliketmp += ( gsl_sf_lnfact( chunkLength - 1 ) - LAL_LN2 - chunkLength * LAL_LNPI );
292 logliketmp -= chunkLength * log( chiSquare );
293 } else { /* using Gaussian likelihood */
294 logliketmp -= 0.5 * chiSquare;
295 }
296
297 /* shift start indices */
298 vstart += numbases->data[i];
299 mstart += numbasesquad->data[i];
300 }
301 }
302
303 /* add normalisation constant for the Gaussian likelihoods */
304 if ( gaussianLike ) {
305 REAL8 logGaussianNorm = *( REAL8 * )LALInferenceGetVariable( ifomodeltemp->params, "logGaussianNorm" );
306 logliketmp += logGaussianNorm;
307 }
308
309 get_model->ifo_loglikelihoods[ifo] = logliketmp;
310
311 loglike += logliketmp;
312 tempdata->likeli_counter += 1;
313 tempdata = tempdata->next;
314 ifomodeltemp = ifomodeltemp->next;
315 ifo++;
316 }
317
318 return loglike;
319}
320
321
322/**
323 * \brief Calculate the natural logarithm of the evidence that the data consists of only Gaussian noise
324 * The function will calculate the natural logarithm of the evidence that the data (from one or more detectors) consists
325 * of stationary segments/chunks described by a Gaussian with zero mean and unknown variance.
326 *
327 * The evidence is obtained from the joint likelihood given in \c pulsar_log_likelihood with the model term \f$ y \f$ set
328 * to zero.
329 *
330 * \param runState [in] The algorithm run state
331 *
332 * \return The natural logarithm of the noise only evidence
333 */
335{
336 /* Single thread code */
337 LALInferenceThreadState *threadState = &runState->threads[0];
338 LALInferenceIFOData *data = runState->data;
339 LALInferenceIFOModel *ifo = threadState->model->ifo;
340
341 REAL8 logL = 0.0;
342 UINT4 i = 0;
343 INT4 k = 0;
344
345 REAL8Vector *freqFactors = NULL;
346 FILE *fp = NULL;
347 CHAR *Znoisefile = NULL;
348 ProcessParamsTable *ppt;
349 ProcessParamsTable *commandLine = runState->commandLine;
350 INT4 gaussianLike = 0;
351 /*-----------------------------*/
352 /*get the outfile name*/
353 ppt = LALInferenceGetProcParamVal( commandLine, "--outfile" );
354 if ( !ppt ) {
355 fprintf( stderr, "Error... not output file specified\n" );
356 exit( 1 );
357 }
358
359 freqFactors = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "freqfactors" );
360
361 /* open the file to output noise evidence (or null signal evidence) for each individual data stream */
362 /* set the Znoise filename to the outfile name with "_Znoise" appended */
363 Znoisefile = XLALStringDuplicate( ppt->value );
364 /* strip the file extension */
365 CHAR *dotloc = strrchr( Znoisefile, '.' );
366 CHAR *slashloc = strrchr( Znoisefile, '/' );
367 if ( dotloc != NULL ) {
368 if ( slashloc != NULL ) { /* check dot is after any filename seperator */
369 if ( slashloc < dotloc ) {
370 *dotloc = '\0';
371 }
372 } else {
373 *dotloc = '\0';
374 }
375 }
376 Znoisefile = XLALStringAppend( Znoisefile, "_Znoise" );
377
378 if ( ( fp = fopen( Znoisefile, "w" ) ) == NULL ) {
379 XLAL_ERROR_REAL8( XLAL_EIO, "Error... cannot open output Znoise file \"%s\"!\n", Znoisefile );
380 }
381
382 /* check whether using Gaussian or students-t likelihood - using Gaussian if --gaussian
383 * has been given as a command line argument. */
384 if ( LALInferenceGetProcParamVal( commandLine, "--gaussian-like" ) ) {
385 gaussianLike = 1;
386 }
387
388 /*calculate the evidence */
389 while ( ifo ) {
390 UINT4Vector *chunkLengths = NULL;
391 REAL8Vector *sumDat = NULL;
392
393 REAL8 chunkLength = 0.;
394 REAL8 logLtmp = 0.;
395
396 chunkLengths = *( UINT4Vector ** )LALInferenceGetVariable( ifo->params, "chunkLength" );
397 sumDat = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "sumData" );
398 /*Sum the logL over the datachunks*/
399 if ( !gaussianLike ) {
400 for ( i = 0; i < chunkLengths->length; i++ ) {
401 chunkLength = ( REAL8 )chunkLengths->data[i];
402 logLtmp += ( gsl_sf_lnfact( chunkLength - 1 ) - LAL_LN2 - chunkLength * LAL_LNPI );
403 logLtmp -= chunkLength * log( sumDat->data[i] );
404 }
405 } else {
406 /* for Gaussian likelihood there's only one chunk */
407 REAL8 logGaussianNorm = *( REAL8 * )LALInferenceGetVariable( ifo->params, "logGaussianNorm" );
408 logLtmp += logGaussianNorm;
409 logLtmp -= 0.5 * sumDat->data[0];
410 }
411
412 data->nullloglikelihood = logLtmp;
413
414 logL += logLtmp;
415
416 /* output the noise evidence for each data stream for each detector */
417 fprintf( fp, "%s\t%.3lf\t%.16le\n", data->name, freqFactors->data[k], logLtmp );
418
419 k += 1; /* advance counter now, as freqfactors array index starts at zero.*/
420
421 /* reset k, freqfactor counter once all datastreamns for a detector are done */
422 if ( k >= ( INT4 )freqFactors->length ) {
423 k = 0;
424 }
425
426 data = data->next;
427 ifo = ifo->next;
428 }
429
430 fclose( fp );
431
432 return logL;
433}
434
435
436/**
437 * \brief The prior function
438 *
439 * This function calculates the natural logarithm of the prior for a set of parameters. If the prior on a particular
440 * parameter is uniform over a given range then \f$ p(\theta) = 1/(\theta_{\rm max} - \theta_{\rm min}) \f$ . If the
441 * prior is Gaussian then the probability of that value given the mean and standard deviation of the Gaussian is
442 * calculated.
443 *
444 * \param runState [in] A pointer to the LALInferenceRunState
445 * \param params [in] The set of parameter values
446 * \param model UNDOCUMENTED
447 *
448 * \return The natural logarithm of the prior value for a set of parameters
449 */
451{
452 /* Single thread */
453 LALInferenceThreadState *threadState = &runState->threads[0];
454 LALInferenceIFOModel *ifo = threadState->model->ifo;
455 ( void )runState;
456 LALInferenceVariableItem *item = params->head;
457 REAL8 prior = 0, value = 0.;
458
459 REAL8Vector *corVals = NULL;
460 UINT4 cori = 0;
461
462 /* check that parameters are within their prior ranges */
463 if ( !in_range( runState->priorArgs, params ) ) {
464 return -INFINITY;
465 }
466
467 /* I31 and I21 values required to check/set I31 >= I21 */
468 REAL8 I31 = -INFINITY, I21 = -INFINITY;
469
470 /* C21 and C22 values required to check/set that they are either both positive or both
471 * negative for the case of a biaxial star */
472 REAL8 C21 = -INFINITY, C22 = -INFINITY;
473
474 for ( ; item; item = item->next ) {
475 /* get scale factor */
476 if ( item->vary == LALINFERENCE_PARAM_FIXED || item->vary == LALINFERENCE_PARAM_OUTPUT ) {
477 continue;
478 }
479
481 value = ( *( REAL8 * )item->value );
482
483 /* Check for a gaussian */
484 if ( LALInferenceCheckGaussianPrior( runState->priorArgs, item->name ) ) {
485 REAL8 mu = 0., sigma = 0.;
486 LALInferenceGetGaussianPrior( runState->priorArgs, item->name, &mu, &sigma );
487
488 prior -= 0.5 * ( ( *( REAL8 * )item->value - mu ) * ( *( REAL8 * )item->value - mu ) ) / ( sigma * sigma );
489
490 if ( !strcmp( item->name, "I21" ) ) {
491 I21 = value;
492 }
493 if ( !strcmp( item->name, "I31" ) ) {
494 I31 = value;
495 }
496 if ( !strcmp( item->name, "C21" ) ) {
497 C21 = value;
498 }
499 if ( !strcmp( item->name, "C22" ) ) {
500 C22 = value;
501 }
502 }
503 /* check for a flat prior */
504 else if ( LALInferenceCheckMinMaxPrior( runState->priorArgs, item->name ) ) {
505 /* check if either using theta or iota rather than their cosines */
506 if ( !strcmp( item->name, "IOTA" ) || !strcmp( item->name, "THETA" ) ) {
507 prior += theta_prior( value );
508 } else { /* note: we don't need to update the prior as it is a constant */
509 if ( !strcmp( item->name, "I21" ) ) {
510 I21 = value;
511 }
512 if ( !strcmp( item->name, "I31" ) ) {
513 I31 = value;
514 }
515 if ( !strcmp( item->name, "C21" ) ) {
516 C21 = value;
517 }
518 if ( !strcmp( item->name, "C22" ) ) {
519 C22 = value;
520 }
521 }
522 } else if ( LALInferenceCheckFermiDiracPrior( runState->priorArgs, item->name ) ) {
523 prior += LALInferenceFermiDiracPrior( runState->priorArgs, item->name, value );
524 } else if ( LALInferenceCheckCorrelatedPrior( runState->priorArgs, item->name ) && corlist ) {
525 /* set item in correct position given the order of the correlation matrix given by corlist */
526 REAL8 mu = 0., sigma = 0.;
527 gsl_matrix *cor = NULL, *invcor = NULL;
528 UINT4 idx = 0;
529 LALInferenceGetCorrelatedPrior( runState->priorArgs, item->name, &cor, &invcor, &mu, &sigma, &idx );
530
531 /* if some correlated priors exist allocate corVals */
532 if ( corVals == NULL ) {
534 }
535
536 for ( cori = 0; cori < corlist->length; cori++ ) {
537 if ( !strcmp( item->name, corlist->data[cori] ) ) {
538 /* scale to a zero mean and unit variance Gaussian */
539 corVals->data[cori] = ( value - mu ) / sigma;
540 break;
541 }
542 }
543 }
544 /* check if using a Gaussian Mixture Model prior */
545 else if ( LALInferenceCheckGMMPrior( runState->priorArgs, item->name ) ) {
546 prior += LALInferenceGMMPrior( runState->priorArgs, item->name, value );
547 }
548 /* check for log(uniform) prior */
549 else if ( LALInferenceCheckLogUniformPrior( runState->priorArgs, item->name ) ) {
550 prior += LALInferenceLogUniformPrior( runState->priorArgs, item->name, value );
551 } else {
552 XLAL_ERROR_REAL8( XLAL_EFUNC, "Error... no prior specified!" );
553 }
554 }
555
556 /* check if the I21 and I31 value have been set, and if so set the prior I31 >= I21 */
557 if ( I21 != -INFINITY && I31 != -INFINITY ) {
558 if ( I31 < I21 ) {
559 return -INFINITY;
560 }
561 }
562 }
563
564 /* if a biaxial star check that C21 and C22 are the same sign */
565 if ( LALInferenceCheckVariable( ifo->params, "biaxial" ) ) {
566 /* in case one parameter is fixed check that */
567 if ( C21 == -INFINITY ) {
568 C21 = LALInferenceGetREAL8Variable( threadState->currentParams, "C21" );
569 }
570 if ( C22 == -INFINITY ) {
571 C22 = LALInferenceGetREAL8Variable( threadState->currentParams, "C22" );
572 }
573 if ( ( C21 < 0. && C22 > 0. ) || ( C21 > 0. && C22 < 0. ) ) {
574 return -INFINITY; /* if same sign this will be positive */
575 }
576 }
577
578 /* if there are values for which the priors are defined by a correlation coefficient matrix then get add the prior from that */
579 if ( corlist ) {
580 gsl_matrix *cor = NULL, *invcor = NULL;
581 gsl_vector_view vals;
582 gsl_vector *vm = gsl_vector_alloc( corVals->length );
583 REAL8 mu = 0., sigma = 0.;
584 UINT4 idx = 0;
585 REAL8 ptmp = 0;
586
587 LALInferenceGetCorrelatedPrior( runState->priorArgs, corlist->data[0], &cor, &invcor, &mu, &sigma, &idx );
588
589 /* get the log prior (this only works properly if the parameter values have been prescaled so as to be from a
590 * Gaussian of zero mean and unit variance, which happens on line 510) */
591 vals = gsl_vector_view_array( corVals->data, corVals->length );
592
593 XLAL_CALLGSL( gsl_blas_dgemv( CblasNoTrans, 1., invcor, &vals.vector, 0., vm ) );
594 XLAL_CALLGSL( gsl_blas_ddot( &vals.vector, vm, &ptmp ) );
595
596 /* divide by the 2 in the denominator of the Gaussian */
597 ptmp /= 2.;
598
599 prior -= ptmp;
600
601 XLALDestroyREAL8Vector( corVals );
602 XLAL_CALLGSL( gsl_vector_free( vm ) );
603 }
604
605 return prior;
606}
607
608
609/**
610 * \brief Prior for angle that is equivalent to an latitude value to give a uniform prior on a sphere
611 *
612 * If you have two angles that define spherical polar coordinates and you want these to have a prior
613 * that is uniform over the sphere then you can instead work with the cosine of the latitude-like angle
614 * and have this to be uniform between -1 and 1. However, if you want to work in the actual angle then
615 * you need to set the correct prior which will be \f$ p(\theta) \propto \sin{\theta) \f$ .
616 *
617 * \param theta [in] The angle in radians
618 *
619 * \return The log prior as defined above.
620 */
622{
623 return log( sin( theta ) );
624}
625
626
627/**
628 * \brief Convert an array of nested samples to posterior samples
629 *
630 * This function generates an array of posterior samples from the nested samples by drawing points from the nested
631 * samples weighted by their prior weighting. This assumes that the nested samples are in the array in ascending
632 * likelihood order (which should be the case for the output of the \c LALInferenceNestedSampler() function. The
633 * posterior sample generation is based on the method used in lalapps/src/inspiral/posterior/nest2pos.py
634 *
635 * Within the input runstate->algorthimParams there needs to be: an array of LALInferenceVariables called
636 * "nestedsamples" containing nested samples to be converted in to the posterior; a value of "Nsamp" giving the number
637 * of nested samples; and, a value of "numberlive" giving the number live points used to generate the posterior samples.
638 *
639 * The posterior samples will be output in runstate->algorthimParams as an array of LALInferenceVariables called
640 * "posteriorsamples", and the number of these in a value called "Nposterior".
641 *
642 * \param runState [in]
643 */
645{
646 UINT4 i = 0, count = 0, k = 0;
647 UINT4Vector *Nsamp = NULL, *Nlive = NULL;
648
649 UINT4 Npost = 0; /* no. of posterior samples required from each NS run */
650 ProcessParamsTable *ppt = NULL;
651
654 "nestedsamples" );
655
656 /* get number of samples and live points */
657 Nsamp = *( UINT4Vector ** )LALInferenceGetVariable( runState->algorithmParams, "Nsamps" );
658 Nlive = *( UINT4Vector ** )LALInferenceGetVariable( runState->algorithmParams, "numberlive" );
659 /* get (approximate) number of posterior samples to generate from each nested sample file */
660 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--Npost" );
661 if ( ppt != NULL ) {
662 Npost = atoi( ppt->value );
663 } else {
664 Npost = 1000; /* default to 1000 */
665 }
666
667 if ( Nsamp->length != Nlive->length ) {
668 XLAL_ERROR_VOID( XLAL_EBADLEN, "Number of nested sample arrays not equal to number of live point for each array!" );
669 }
670
672 REAL8Vector **log_ws = XLALCalloc( Nsamp->length, ( sizeof( REAL8Vector * ) ) );
673 REAL8 log_tot_ev = -INFINITY;
674
675 for ( k = 0; k < Nsamp->length; k++ ) {
676 /* vector of prior weights */
677 log_ws[k] = XLALCreateREAL8Vector( Nsamp->data[k] );
678
679 REAL8 log_vol_factor = log( 1. - ( 1. / ( REAL8 )Nlive->data[k] ) );
680 REAL8 log_dvol = -1. / ( REAL8 )Nlive->data[k];
681 REAL8 log_vol = 0., log_ev = -INFINITY;
682 REAL8 avg_log_like_end = -INFINITY;
683
684 /* fill in sample weights */
685 for ( i = 0; i < Nsamp->data[k]; i++ ) {
686 REAL8 logL = *( REAL8 * )LALInferenceGetVariable( nsamples[k][i], "logL" );
687
688 if ( i < Nsamp->data[k] - Nlive->data[k] ) {
689 log_ws[k]->data[i] = logL + log_vol + log_dvol;
690 log_ev = LOGPLUS( log_ev, log_ws[k]->data[i] );
691 log_vol += log_vol_factor;
692 } else {
693 avg_log_like_end = LOGPLUS( avg_log_like_end, logL );
694 log_ws[k]->data[i] = log_vol + logL;
695 }
696 }
697
698 avg_log_like_end -= log( ( REAL8 )Nlive->data[k] );
699 log_ev = LOGPLUS( log_ev, avg_log_like_end + log_vol );
700
701 log_evs->data[k] = log_ev;
702 log_tot_ev = LOGPLUS( log_tot_ev, log_ev );
703 }
704
705 for ( k = 0; k < Nsamp->length; k++ ) {
706 /* round Npost based on the evidence for each data set */
707 UINT4 Ns = ( UINT4 )ROUND( ( REAL8 )Npost * exp( log_evs->data[k] - log_tot_ev ) );
708
709 /* generate cumulative sum of weigths */
710 REAL8Vector *log_cumsums = XLALCreateREAL8Vector( Nsamp->data[k] + 1 );
711 log_cumsums->data[0] = -INFINITY;
712
713 /* get posterior samples */
714 for ( i = 0; i < Nsamp->data[k]; i++ ) {
715 log_ws[k]->data[i] -= log_evs->data[k]; /* normalise weights */
716
717 log_cumsums->data[i + 1] = LOGPLUS( log_cumsums->data[i], log_ws[k]->data[i] );
718 }
719
720 for ( UINT4 j = 0; j < Ns; j++ ) {
721 REAL8 us = log( gsl_rng_uniform( runState->GSLrandom ) );
722
723 /* draw the samples */
724 for ( i = 1; i < Nsamp->data[k] + 1; i++ )
725 if ( log_cumsums->data[i - 1] < us && us <= log_cumsums->data[i] ) {
726 break;
727 }
728
729 /* add the posterior sample */
730 psamples = XLALRealloc( psamples, ( count + 1 ) * sizeof( LALInferenceVariables * ) );
732 LALInferenceCopyVariables( nsamples[k][i - 1], psamples[count] );
733 count++;
734 }
735 }
736
737 /* free weights and evidence */
738 for ( k = 0; k < Nsamp->length; k++ ) {
739 XLALDestroyREAL8Vector( log_ws[k] );
740 }
741 XLALFree( log_ws );
743
748}
749
750/**
751 * \brief Create a k-d tree from prior samples
752 *
753 * This function creates a k-d tree from prior samples for use as a prior distribution in the algorithm. The ranges of
754 * the tree dimensions (parameters) are calculated from the maximum and minimum values of the parameter. If the the
755 * lower and upper values are closer than half of there overall range to those specified in the prior file then the
756 * prior file values are used. Otherwise the upper/lower value + half the overall range is used. In this case the prior
757 * ranges set in priorArgs, and scale factors, will need to be replaced. [NOTE: This case will mean that the whole prior
758 * range specified may not be searched, however the prior samples would suggest that there is very little probability of
759 * information existing in the excluded areas]. The reason for not just using the full prior ranges is that if the prior
760 * samples are tightly peaked in a small area of the prior space the k-D tree resolution is poor and can cause an
761 * unwanted broadening of the prior e.g. if the h0 samples are peaked at zero with a distribution width of ~1e-24, but
762 * the prior range is set from 0 to 1e-22 then new samples drawn from a k-D tree produced with the full range in h0
763 * yields a broader distribution than required.
764 *
765 * [WARNING: Do NOT use this function. As the k-d tree is a binned, rather than smooth, version of the posterior
766 * there will be areas of zero probability that actually should contain some probability. This will end up
767 * severely biasing any result. Instead some sort of smooth form should be used such as a Gaussian Mixture Model,
768 * maybe found though a DPGMM approach!]
769 *
770 * \param runState [in] A pointer to the LALInferenceRunState
771 */
773{
774 LALInferenceThreadState *threadState = &runState->threads[0];
775 LALInferenceKDTree *priortree = NULL;
776 LALInferenceVariables **posterior = NULL; /* use these samples as prior */
777 UINT4 nsamp = 0, i = 0, cnt = 0;
778
779 LALInferenceVariableItem *samp = NULL; /* a single sample */
780 REAL8 *low = NULL, *high = NULL;
781 REAL8 *lownew = NULL, *highnew = NULL; /* upper and lower bounds of tree */
782 REAL8 *pt = NULL;
783 size_t ndim = 0;
784
785 LALInferenceVariables *template = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
786
787 /* get posterior samples to use as prior */
788 if ( LALInferenceCheckVariable( runState->algorithmParams, "posteriorsamples" ) ) {
789 posterior = *( LALInferenceVariables *** )LALInferenceGetVariable( runState->algorithmParams, "posteriorsamples" );
790 } else {
791 XLAL_ERROR_VOID( XLAL_EFUNC, "No posterior samples set to use as prior." );
792 }
793
794 /* get the number of posterior samples */
795 if ( LALInferenceCheckVariable( runState->algorithmParams, "Nposterior" ) ) {
796 nsamp = *( UINT4 * )LALInferenceGetVariable( runState->algorithmParams, "Nposterior" );
797 } else {
798 XLAL_ERROR_VOID( XLAL_EFUNC, "Number of posterior samples not set." );
799 }
800
801 /* get the upper and lower bounds for each variable parameter i.e. we won't be adding log likelihood, or log prior
802 * values */
803 samp = posterior[0]->head;
804 while ( samp ) {
805 UINT4 change = 0; /* set it a range has changed */
806
807 if ( samp->vary != LALINFERENCE_PARAM_FIXED && samp->vary != LALINFERENCE_PARAM_OUTPUT ) {
808 /* get the minimum and maximum prior sample and the range */
809 REAL8 maxvaltmp = -INFINITY, minvaltmp = INFINITY;
810 REAL8 posthigh = 0., postlow = 0., difflh = 0.;
811 REAL8 lowr = 0., highr = 0.;
812
813 for ( UINT4 k = 0; k < nsamp; k++ ) {
814 REAL8 val = *( REAL8 * )LALInferenceGetVariable( posterior[k], samp->name );
815
816 if ( val < minvaltmp ) {
817 minvaltmp = val;
818 }
819 if ( val > maxvaltmp ) {
820 maxvaltmp = val;
821 }
822 }
823
824 /* max and min of the prior samples */
825 posthigh = maxvaltmp;
826 postlow = minvaltmp;
827
828 difflh = posthigh - postlow; /* range of the samples */
829
830 /* dynamically allocate memory for the k-D tree ranges */
831 low = XLALRealloc( low, sizeof( REAL8 ) * ( cnt + 1 ) );
832 high = XLALRealloc( high, sizeof( REAL8 ) * ( cnt + 1 ) );
833 lownew = XLALRealloc( lownew, sizeof( REAL8 ) * ( cnt + 1 ) );
834 highnew = XLALRealloc( highnew, sizeof( REAL8 ) * ( cnt + 1 ) );
835
836 /* if there's a minmax prior check the ranges */
837 if ( LALInferenceCheckMinMaxPrior( runState->priorArgs, samp->name ) ) {
838 LALInferenceGetMinMaxPrior( runState->priorArgs, samp->name, &lowr, &highr );
839
840 /* check how far min and max samples are from the prior ranges */
841 if ( posthigh > highr || posthigh < lowr ) {
842 fprintf( stderr, "Error... prior samples are out of range!\n" );
843 exit( 1 );
844 } else if ( posthigh + difflh / 2. > highr ) {
845 high[cnt] = highr; /* just stick with prior range */
846 } else {
847 high[cnt] = posthigh + difflh / 2.; /* use max from samples+diff/2 */
848 change++; /* we have changed the range */
849 }
850
851 if ( postlow > highr || postlow < lowr ) {
852 fprintf( stderr, "Error... prior samples are out of range!\n" );
853 exit( 1 );
854 } else if ( postlow - difflh / 2. < lowr ) {
855 low[cnt] = lowr; /* just stick with prior range */
856 } else {
857 low[cnt] = postlow - difflh / 2.; /* use min from samples-diff/2 */
858 change++; /* we have changed the range */
859 }
860 } else if ( LALInferenceCheckGaussianPrior( runState->priorArgs, samp->name ) ) {
861 /* to add a bit of room at either side add on half the difference */
862 low[cnt] = postlow - difflh / 2.;
863 high[cnt] = posthigh + difflh / 2.;
864
865 /* remove the Gaussian prior and replace with min/max range */
867
868 change++; /* the range will change */
869 } else {
870 fprintf( stderr, "Error... Prior type not specified!\n" );
871 exit( 1 );
872 }
873
874 /* change the prior ranges, the scale factors and the current params */
875 if ( change != 0 ) {
876 LALInferenceIFOModel *ifo = threadState->model->ifo;
877
878 /* with the scaled parameters the k-D tree ranges will be between 0 and 1 */
879 lownew[cnt] = 0.;
880 highnew[cnt] = 1.;
881
882 INT4 ii = 0;
883
884 /* now change the current param to reflect new ranges */
885 REAL8 var = *( REAL8 * )LALInferenceGetVariable( threadState->currentParams, samp->name );
886 while ( ifo ) {
887 /* rescale current parameter value */
888 if ( ii == 0 ) {
889 ii++;
890
891 LALInferenceSetVariable( threadState->currentParams, samp->name, &var );
892 }
893
894 ifo = ifo->next;
895 }
896
897 /* reset (or add) priorArgs */
898 LALInferenceAddMinMaxPrior( runState->priorArgs, samp->name, &( lownew[cnt] ), &( highnew[cnt] ),
900 } else {
901 lownew[cnt] = low[cnt];
902 highnew[cnt] = high[cnt];
903 }
904
905 cnt++;
906 }
907
908 samp = samp->next;
909 }
910
911 ndim = ( size_t )cnt;
912 pt = XLALMalloc( cnt * sizeof( REAL8 ) );
913
914 /* set up tree */
915 priortree = LALInferenceKDEmpty( lownew, highnew, ndim );
916
917 /* get template */
918 LALInferenceCopyVariables( posterior[0], template );
919
920 /* add points to tree */
921 for ( i = 0; i < nsamp; i++ ) {
922 samp = posterior[i]->head;
923
924 cnt = 0;
925
926 while ( samp ) {
927 if ( samp->vary != LALINFERENCE_PARAM_FIXED && samp->vary != LALINFERENCE_PARAM_OUTPUT ) {
928 REAL8 val = *( REAL8 * )samp->value;
929 LALInferenceSetVariable( posterior[i], samp->name, &val );
930 cnt++;
931 }
932
933 samp = samp->next;
934 }
935
937 LALInferenceKDAddPoint( priortree, pt );
938 }
939
940 /* add tree */
941 LALInferenceAddVariable( runState->priorArgs, "kDTreePrior", &priortree, LALINFERENCE_void_ptr_t,
943
944 LALInferenceAddVariable( runState->priorArgs, "kDTreePriorTemplate", &template, LALINFERENCE_void_ptr_t,
946
947 XLALFree( high );
948 XLALFree( low );
949 XLALFree( pt );
950}
951
952
953/**
954 * \brief Check that any parameters with minimum and maximum ranges are within that range
955 *
956 * This function performs any cylcic transform and then makes sure that all parameters in \c params, that
957 * have a defined minimum and maximum value, are within their allowed prior ranges.
958 *
959 * \param priors [in] A pointer to the prior args LALInferenceVariables
960 * \param params [in] The current parameters
961 *
962 * \return 0 if out of range and 1 if in range
963 */
965{
966 LALInferenceVariableItem *item = params->head;
967 REAL8 min, max, val;
968
969 /* loop over variables */
970 for ( ; item; item = item->next ) {
971 if ( item->vary == LALINFERENCE_PARAM_FIXED || item->vary == LALINFERENCE_PARAM_OUTPUT ) {
972 continue;
973 }
974 val = *( REAL8 * )item->value;
975
976 /* make sure certain values are not negative (H0, Q22, DIST, PX, CGW, ECC, A1, MTOT, M2) NOTE: I'm not sure if DR and DTHETA should also be only positive */
977 if ( val < 0. ) {
978 if ( !strcmp( item->name, "H0" ) || !strcmp( item->name, "Q22" ) || !strcmp( item->name, "DIST" ) ||
979 !strcmp( item->name, "PX" ) || !strcmp( item->name, "CGW" ) || !strncmp( item->name, "ECC", sizeof( CHAR ) * 3 ) ||
980 !strncmp( item->name, "A1", sizeof( CHAR ) * 2 ) || !strcmp( item->name, "MTOT" ) || !strcmp( item->name, "M2" ) ) {
981 return 0;
982 }
983 }
984
985 /* make sure any sin or cos parameters are within -1 and 1 */
986 if ( fabs( val ) > 1. ) {
987 if ( !strncmp( item->name, "SIN", sizeof( CHAR ) * 3 ) || !strncmp( item->name, "COS", sizeof( CHAR ) * 3 ) ) {
988 return 0;
989 }
990 }
991
992 if ( LALInferenceCheckMinMaxPrior( priors, item->name ) ) {
993 LALInferenceGetMinMaxPrior( priors, item->name, &min, &max );
994
995 /* For cyclic boundaries, mod out by range. */
996 if ( item->vary == LALINFERENCE_PARAM_CIRCULAR ) {
997 REAL8 delta = max - min;
998
999 if ( val > max ) {
1000 REAL8 offset = val - min;
1001
1002 *( REAL8 * )item->value = min + fmod( offset, delta );
1003 } else {
1004 REAL8 offset = max - val;
1005
1006 *( REAL8 * )item->value = max - fmod( offset, delta );
1007 }
1008
1009 continue;
1010 }
1011
1012 if ( ( *( REAL8 * ) item->value ) < min || ( *( REAL8 * )item->value ) > max ) {
1013 return 0;
1014 }
1015 }
1016 }
1017
1018 return 1;
1019}
1020
1021
1022/*--------------- END OF LIKELIHOOD AND PRIOR FUNCTIONS ----------------------*/
#define min(a, b)
COMPLEX16 LALInferenceROQCOMPLEX16DotProduct(COMPLEX16Vector *weights, COMPLEX16Vector *model)
REAL8 LALInferenceROQREAL8DotProduct(REAL8Vector *weights, REAL8Vector *model)
ProcessParamsTable * ppt
int j
int k
static double double delta
UINT2 B
Definition: SFTnaming.c:47
#define fprintf
#define XLAL_CALLGSL(statement)
double theta
#define LAL_LN2
#define LAL_LNPI
double complex COMPLEX16
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
int LALInferenceKDAddPoint(LALInferenceKDTree *tree, REAL8 *pt)
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
void LALInferenceKDVariablesToREAL8(LALInferenceVariables *params, REAL8 *pt, LALInferenceVariables *templt)
REAL8 LALInferenceGetREAL8Variable(LALInferenceVariables *vars, const char *name)
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
LALInferenceKDTree * LALInferenceKDEmpty(REAL8 *lowerLeft, REAL8 *upperRight, size_t ndim)
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
LALINFERENCE_PARAM_OUTPUT
LALINFERENCE_PARAM_FIXED
LALINFERENCE_PARAM_CIRCULAR
LALINFERENCE_PARAM_LINEAR
LALINFERENCE_REAL8_t
LALINFERENCE_void_ptr_t
LALINFERENCE_UINT4_t
REAL8 LALInferenceGMMPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceAddMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max, LALInferenceVariableType type)
void LALInferenceRemoveGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
REAL8 LALInferenceLogUniformPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name)
REAL8 LALInferenceFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckGMMPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceGetMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max)
int LALInferenceCheckGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
int LALInferenceCheckFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name)
int LALInferenceCheckLogUniformPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceGetGaussianPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *mu, REAL8 *sigma)
void LALInferenceGetCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name, gsl_matrix **cor, gsl_matrix **invcor, REAL8 *mu, REAL8 *sigma, UINT4 *idx)
void * XLALMalloc(size_t n)
void * XLALCalloc(size_t m, size_t n)
void * XLALRealloc(void *p, size_t n)
void XLALFree(void *p)
char char * XLALStringDuplicate(const char *s)
int char * XLALStringAppend(char *s, const char *append)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_REAL8(...)
XLAL_EBADLEN
XLAL_EFUNC
XLAL_EIO
#define ROUND(a)
long long count
Definition: hwinject.c:371
float data[BLOCKSIZE]
Definition: hwinject.c:360
M
list mu
def psamples
log_ev
vals
log_evs
def posterior
REAL8 priorFunction(LALInferenceRunState *runState, LALInferenceVariables *params, UNUSED LALInferenceModel *model)
The prior function.
void create_kdtree_prior(LALInferenceRunState *runState)
Create a k-d tree from prior samples.
REAL8 noise_only_likelihood(LALInferenceRunState *runState)
Calculate the natural logarithm of the evidence that the data consists of only Gaussian noise The fun...
void ns_to_posterior(LALInferenceRunState *runState)
Convert an array of nested samples to posterior samples.
REAL8 theta_prior(REAL8 theta)
Prior for angle that is equivalent to an latitude value to give a uniform prior on a sphere.
UINT4 in_range(LALInferenceVariables *priors, LALInferenceVariables *params)
Check that any parameters with minimum and maximum ranges are within that range.
REAL8 pulsar_log_likelihood(LALInferenceVariables *vars, LALInferenceIFOData *data, LALInferenceModel *get_model)
The log likelihood function.
Header file for the likelihood and prior functions used in parameter estimation code for known pulsar...
LALStringVector * corlist
#define LOGPLUS(x, y)
Macro to perform addition of two values within logarithm space .
COMPLEX16Sequence * data
COMPLEX16 * data
REAL8TimeSeries * varTimeData
struct tagLALInferenceROQData * roq
struct tagLALInferenceIFOData * next
COMPLEX16TimeSeries * compTimeData
struct tagLALInferenceIFOModel * next
LALInferenceVariables * params
COMPLEX16TimeSeries * compTimeSignal
REAL8 * ifo_loglikelihoods
LALInferenceVariables * params
LALInferenceIFOModel * ifo
LALInferenceTemplateFunction templt
ProcessParamsTable * commandLine
LALInferenceVariables * algorithmParams
struct tagLALInferenceIFOData * data
LALInferenceVariables * priorArgs
LALInferenceThreadState * threads
LALInferenceVariables * currentParams
LALInferenceModel * model
char name[VARNAME_MAX]
struct tagVariableItem * next
LALInferenceParamVaryType vary
REAL8Sequence * data
REAL8 * data
UINT4 * data
#define max(a, b)