LALInference  4.1.6.1-89842e6
LALInferenceTest.c
Go to the documentation of this file.
1 /*
2  * LALInferenceTest.c: Unit tests for LALInference.c library code
3  *
4  * Copyright (C) 2011 Ben Aylott, Ilya Mandel, Chiara Mingarelli Vivien Raymond, Christian Roever, Marc van der Sluys and John Veitch, Will Vousden
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with with program; see the file COPYING. If not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <lal/LALInference.h>
25 #include <lal/Units.h>
26 #include <lal/FrequencySeries.h>
27 #include <lal/TimeFreqFFT.h>
28 #include <lal/VectorOps.h>
29 #include <lal/Date.h>
30 #include <lal/XLALError.h>
31 #include <lal/TimeSeries.h>
32 #include <lal/Sequence.h>
33 #include <lal/StringInput.h>
34 #include <lal/LIGOLwXMLRead.h>
35 #include <lal/LALInferenceInit.h>
36 #include <lal/LALInferenceReadData.h>
37 #include <lal/LALInferenceLikelihood.h>
38 #include <lal/LALInferenceTemplate.h>
39 #include <lal/LALInferencePrior.h>
40 
41 #include "LALInferenceTest.h"
42 
43 #ifdef __GNUC__
44 #define UNUSED __attribute__ ((unused))
45 #else
46 #define UNUSED
47 #endif
48 
49 /* for LALInferenceParseCommandLine tests*/
53 
54 /* LALInferenceProcessParamLine tests */
58 
59 /* LALInferenceExecuteFT tests */
61 
62 int main(void){
63 
64  int failureCount = 0;
65 
67  printf("\n");
69  printf("\n");
71  printf("\n");
72  failureCount += LALInferenceProcessParamLine_TEST();
73  printf("\n");
75  printf("\n");
77  printf("\n");
78  failureCount += LALInferenceExecuteFTTEST_NULLPLAN();
79  printf("\n");
80  printf("Test results: %i failure(s).\n", failureCount);
81 
82  return failureCount;
83 
84 }
85 
86 /***************** TEST CODE for LALInferenceParseCommandLine *****************/
87 
88 /*this function tests to see if LALInferenceParseCommandLine catches the double dash condition. Expect fail. */
90  TEST_HEADER();
91  int errnum,i;
92  const int number=3;
93  ProcessParamsTable *answer;
94 
95  char** list=(char**)XLALCalloc(3,sizeof(char*));
96  for(i=0;i<number;i++){
97  list[i]=(char*)XLALCalloc(10,sizeof(char));
98  }
99 
100  strcpy(list[0],"foo");
101  strcpy(list[1],"bar");
102  strcpy(list[2],"baz");
103 
104  XLAL_TRY(answer=LALInferenceParseCommandLine(number,list), errnum);
105  (void)number;
106 
107  if (errnum == XLAL_SUCCESS||answer!=NULL)
108  {
109  TEST_FAIL("Did not use double dash on fist input, should fail; XLAL error code: %i.", errnum);
110  }
111 
112  TEST_FOOTER();
113 
114 }
115 
116 /*this function tests to see if LALInferenceParseCommandLine tests standard input. Expect pass. */
118  TEST_HEADER();
119  int errnum,i;
120  ProcessParamsTable *answer;
121  const int number=3;
122 
123  char** list=(char**)XLALCalloc(3,sizeof(char*));
124  for(i=0;i<number;i++){
125  list[i]=(char*)XLALCalloc(10,sizeof(char));
126  }
127 
128  strcpy(list[0],"filename");
129  strcpy(list[1],"--bar");
130  strcpy(list[2],"--baz");
131 
132  XLAL_TRY(answer=LALInferenceParseCommandLine(number,list), errnum);
133  if (errnum == XLAL_SUCCESS||answer!=NULL)
134  {
135  printf("Standard input woking ... \n ");
136  }
137  else{
138  TEST_FAIL("Input error; XLAL error code: %i.", errnum);
139  }
140 
141  TEST_FOOTER();
142 
143 }
144 
145 /*this function tests to see if LALInferenceParseCommandLine tests inputs. We expect this to fail bc !dbldash. */
147  TEST_HEADER();
148  int errnum,i;
149  ProcessParamsTable *answer;
150  const int number=3;
151 
152  char** list=(char**)XLALCalloc(3,sizeof(char*));
153  for(i=0;i<number;i++){
154  list[i]=(char*)XLALCalloc(10,sizeof(char));
155  }
156 
157  strcpy(list[0],"foo");
158  strcpy(list[1],"-bar");
159  strcpy(list[2],"-baz");
160 
161  XLAL_TRY(answer=LALInferenceParseCommandLine(number,list), errnum);
162  if (errnum == XLAL_SUCCESS||answer!=NULL)
163  {
164  TEST_FAIL("Did not use double dash on fist input, should fail; XLAL error: %s.", XLALErrorString(errnum));
165  }
166 
167  TEST_FOOTER();
168 
169 }
170 
171 
172 
173 
174 /***************** TEST CODE for LALInferenceProcessParamLine *****************/
175 
176 //this should work, and it does
178  TEST_HEADER();
179  int errnum,i;
180 
181  FILE *file;
182  LALInferenceVariables *vars;
183 
184  const int argc=3;
185  const int argLength=10;
186  char **headers=XLALCalloc(argc + 1,sizeof(char*));
187 
188  for(i=0;i<argc;i++){
189  headers[i]=XLALCalloc(argLength,sizeof(char));
190  }
191 
192  strcpy(headers[0],"foo");
193  strcpy(headers[1],"barbie");
194  strcpy(headers[2],"baz");
195  headers[3]=NULL;
196  vars=XLALCalloc(1,sizeof(LALInferenceVariables));
197 
198  // Create a temporary file, populate it, and rewind to the beginning before using it.
199  file=tmpfile();
200  fprintf(file, "-1.01 3.01 4.01");
201  rewind(file);
202 
204  if (errnum != XLAL_SUCCESS)
205  {
206  TEST_FAIL("Could not read file; XLAL error: %s.", XLALErrorString(errnum));
207  }
208 
209  fclose(file);
210  TEST_FOOTER();
211 }
212 
213 //what happens with an empty file? expect failure and fails.
215  TEST_HEADER();
216  int errnum,i;
217 
218  FILE *file;
219  LALInferenceVariables *vars;
220 
221  const int argc=3;
222  const int argLength=10;
223  char **headers=XLALCalloc(argc + 1,sizeof(char*));
224 
225  for(i=0;i<argc;i++){
226  headers[i]=XLALCalloc(argLength,sizeof(char));
227  }
228 
229  strcpy(headers[0],"foo");
230  strcpy(headers[1],"barbie");
231  strcpy(headers[2],"baz");
232  headers[3]=NULL;
233  vars=XLALCalloc(1,sizeof(LALInferenceVariables));
234 
235  // Create a temporary file and leave it empty.
236  file=tmpfile();
237 
239  if (errnum == XLAL_SUCCESS)
240  {
241  TEST_FAIL("Reading empty file succeeded but should have failed!.");
242  }
243 
244  fclose(file);
245  TEST_FOOTER();
246 }
247 
248 /*what happens if it gets chars instad of doubles? */
250  TEST_HEADER();
251  int errnum,i;
252 
253  FILE *file;
254  LALInferenceVariables *vars;
255 
256  char** headers=(char**)XLALCalloc(4,sizeof(char*));
257 
258  for(i=0;i<3;i++){
259  headers[i]=(char*)XLALCalloc(10,sizeof(char));
260  }
261 
262  strcpy(headers[0],"foo");
263  strcpy(headers[1],"barbie");
264  strcpy(headers[2],"baz");
265  headers[3]=NULL;
266  vars=XLALCalloc(1,sizeof(LALInferenceVariables));
267 
268  // Create a temporary file, populate it, and rewind to the beginning before using it.
269  file=tmpfile();
270  fprintf(file, "2.99 3.01 b");
271  rewind(file);
272 
274  if (errnum == XLAL_SUCCESS)
275  {
276  TEST_FAIL("Should not pass; non-numeric characters in file!.");
277  }
278 
279  TEST_FOOTER();
280 }
281 
282 
283 
284 
285 /***************** TEST CODE for LALInferenceExecuteFT *****************/
286 /* Test that LALInferenceExecuteFT fails if the FFT plan is NULL .*/
287 
289 
290  TEST_HEADER();
291 
292  UINT4 i, length;
293  REAL8 deltaF;
294  LIGOTimeGPS epoch={0,0};
295  int errnum;
296 
297  length = 1;
298 
299  deltaF=0.1;
300 
302  LALInferenceModel *testModel = (LALInferenceModel *) LALCalloc(1, sizeof(LALInferenceModel));
303  //LALInferenceIFOData *testNULLIFOData = NULL;
304 
305  REAL8TimeSeries *timeModelhPlus=(REAL8TimeSeries*)XLALCalloc(1, sizeof(REAL8TimeSeries));
306  REAL8TimeSeries *timeModelhCross=(REAL8TimeSeries*)XLALCalloc(1, sizeof(REAL8TimeSeries));
308 
309  REAL8Sequence *TimedataPlus=XLALCreateREAL8Sequence(length);
310  REAL8Sequence *TimedataCross=XLALCreateREAL8Sequence(length);
311 
312  REAL8Window *window=XLALCalloc(1, sizeof(REAL8Window));
313  REAL8Sequence *Windowdata=XLALCreateREAL8Sequence(length);
314 
316 
318 
319  testIFOData->freqData=freqData;
320  testIFOData->freqData->deltaF=deltaF;
321  testIFOData->freqData->data=Freqdata;
322 
323  testIFOData->freqData->data->length=length;
324 
325  testModel->timehPlus=timeModelhPlus;
326  testModel->timehPlus->data=TimedataPlus;
327  testModel->timehPlus->data->length=length;
328 
329  testModel->timehCross=timeModelhCross;
330  testModel->timehCross->data=TimedataCross;
331  testModel->timehCross->data->length=length;
332 
333  testIFOData->timeData=TData;
334  testIFOData->timeData->epoch=epoch;
335 
336  testIFOData->window=window;
337 
338  testIFOData->window->data=Windowdata;
339 
340  testModel->timeToFreqFFTPlan=NULL;
341 
342  for (i=0; i<length; ++i){
343  testModel->timehPlus->data->data[i] = 0.0;
344  testModel->timehCross->data->data[i] = 0.0;
345  }
346 
347  if (testIFOData!=NULL && testModel!=NULL){
348  XLAL_TRY(LALInferenceExecuteFT(testModel), errnum);
349 
350  if( errnum == XLAL_SUCCESS ){
351  TEST_FAIL("Should not pass; timeToFreqFFTPlan is NULL!");
352  }
353  }
354 
355  TEST_FOOTER();
356 
357 }
358 
359 
360 /******************************************
361  *
362  * Old tests
363  *
364  ******************************************/
365 
377 
381 int i, j, k;
382 
384 
385 //Test LALEvolveOneStepFunction
386 void BasicMCMCOneStep(LALInferenceRunState *runState);
387 
388 //Test LALAlgorithm
389 void MCMCAlgorithm (struct tagLALInferenceRunState *runState);
390 void NelderMeadEval(struct tagLALInferenceRunState *runState,
391  char **names, REAL8 *values, int dim,
392  REAL8 *logprior, REAL8 *loglikelihood);
393 void NelderMeadAlgorithm(struct tagLALInferenceRunState *runState, LALInferenceVariables *subset);
394 
395 
396 void LALVariablesTest(void);
397 void DataTest(void);
398 void SingleIFOLikelihoodTest(void);
399 void BasicMCMCTest(void);
400 void TemplateDumpTest(void);
401 void PTMCMCTest(void);
402 
403 // gsl_rng * InitializeRandomSeed(void);
404 // unsigned long int random_seed();
405 
406 //REAL8 NullLogLikelihood(LALInferenceIFOData *data)
407 ///*Idential to FreqDomainNullLogLikelihood */
408 //{
409 // REAL8 loglikeli, totalChiSquared=0.0;
410 // LALInferenceIFOData *ifoPtr=data;
411 //
412 // /* loop over data (different interferometers): */
413 // while (ifoPtr != NULL) {
414 // totalChiSquared+=ComputeFrequencyDomainOverlap(ifoPtr, ifoPtr->freqData->data, ifoPtr->freqData->data);
415 // ifoPtr = ifoPtr->next;
416 // }
417 // loglikeli = -0.5 * totalChiSquared; // note (again): the log-likelihood is unnormalised!
418 // return(loglikeli);
419 //}
420 
421 
423 /* calls the "ReadData()" function to gather data & PSD from files, */
424 /* and initializes other variables accordingly. */
425 {
426  LALInferenceRunState *irs=NULL;
427  LALInferenceThreadState *thread;
428  //ProcessParamsTable *ppt=NULL;
429  unsigned long int randomseed;
430  struct timeval tv;
431  FILE *devrandom;
432 
433  irs = XLALCalloc(1, sizeof(LALInferenceRunState));
435  thread = &irs->threads[0];
436 
437  /* read data from files: */
438  fprintf(stdout, " LALInferenceReadData(): started.\n");
439  irs->data = LALInferenceReadData(commandLine);
440  /* (this will already initialise each LALInferenceIFOData's following elements: */
441  /* fLow, fHigh, detector, timeToFreqFFTPlan, freqToTimeFFTPlan, */
442  /* window, oneSidedNoisePowerSpectrum, timeDate, freqData ) */
443  fprintf(stdout, " LALInferenceReadData(): finished.\n");
444 
445  if (irs->data != NULL) {
446  fprintf(stdout, " initialize(): successfully read data.\n");
447 
448  fprintf(stdout, " LALInferenceInjectInspiralSignal(): started.\n");
449  LALInferenceInjectInspiralSignal(irs->data,commandLine);
450  fprintf(stdout, " LALInferenceInjectInspiralSignal(): finished.\n");
451 
453  printf("Injection Null Log Likelihood: %g\n", thread->currentIFOLikelihoods[0]);
454  }
455  else
456  fprintf(stdout, " initialize(): no data read.\n");
457 
458  /* set up GSL random number generator: */
459  gsl_rng_env_setup();
460  irs->GSLrandom = gsl_rng_alloc(gsl_rng_mt19937);
461  /* (try to) get random seed from command line: */
462  ppt = LALInferenceGetProcParamVal(commandLine, "--randomseed");
463  if (ppt != NULL)
464  randomseed = atoi(ppt->value);
465  else { /* otherwise generate "random" random seed: */
466  /*
467  * Note: /dev/random can be slow after the first few accesses, which is why we're using urandom instead.
468  * [Cryptographic safety isn't a concern here at all]
469  */
470  if ((devrandom = fopen("/dev/urandom","r")) == NULL) {
471  gettimeofday(&tv, 0);
472  randomseed = tv.tv_sec + tv.tv_usec;
473  }
474  else {
475  if(!fread(&randomseed, sizeof(randomseed), 1, devrandom))
476  exit(1);
477  fclose(devrandom);
478  }
479  }
480  fprintf(stdout, " initialize(): random seed: %lu\n", randomseed);
481  gsl_rng_set(irs->GSLrandom, randomseed);
482 
483  return(irs);
484 }
485 
486 
487 
488 
489 //Test LALEvolveOneStepFunction
491 // Metropolis-Hastings sampler.
492 {
493  REAL8 logPriorCurrent, logPriorProposed;
494  REAL8 logLikelihoodCurrent, logLikelihoodProposed;
495  LALInferenceVariables proposedParams;
496  REAL8 logProposalRatio = 0.0; // = log(P(backward)/P(forward))
497  REAL8 logAcceptanceProbability;
498  LALInferenceThreadState *thread = &runState->threads[0];
499 
500  // current values:
501  logPriorCurrent = runState->prior(runState, thread->currentParams, thread->model);
502  logLikelihoodCurrent = thread->currentLikelihood;
503 
504  // generate proposal:
505  proposedParams.head = NULL;
506  proposedParams.dimension = 0;
507  logProposalRatio = thread->proposal(thread, thread->currentParams, &proposedParams);
508 
509  // compute prior & likelihood:
510  logPriorProposed = runState->prior(runState, &proposedParams, thread->model);
511  if (logPriorProposed > -HUGE_VAL)
512  logLikelihoodProposed = runState->likelihood(&proposedParams, runState->data, thread->model);
513  else
514  logLikelihoodProposed = -HUGE_VAL;
515 
516  // determine acceptance probability:
517  logAcceptanceProbability = (logLikelihoodProposed - logLikelihoodCurrent)
518  + (logPriorProposed - logPriorCurrent)
519  + logProposalRatio;
520 
521  // accept/reject:
522  if ((logAcceptanceProbability > 0)
523  || (log(gsl_rng_uniform(thread->GSLrandom)) < logAcceptanceProbability)) { //accept
524  LALInferenceCopyVariables(&proposedParams, thread->currentParams);
525  thread->currentLikelihood = logLikelihoodProposed;
526  }
527 
528  LALInferenceClearVariables(&proposedParams);
529 }
530 
531 
532 
533 //Test LALAlgorithm
534 void MCMCAlgorithm(struct tagLALInferenceRunState *runState)
535 {
536  //int i;
537  REAL8 dummyR8;
538  LALInferenceThreadState *thread = &runState->threads[0];
539 
540  printf(" MCMCAlgorithm(); starting parameter values:\n");
542  // initialize starting likelihood value:
543  thread->currentLikelihood = runState->likelihood(thread->currentParams, runState->data, thread->model);
544  // iterate:
545  for(i=0; i<100; i++) {
546  printf(" MCMC iteration: %d\n", i+1);
547  dummyR8 = thread->currentLikelihood;
548  runState->evolve(runState);
549  if (thread->currentLikelihood != dummyR8) {
550  printf(" accepted! new parameter values:\n");
552  }
553  }
554 }
555 
556 
557 void NelderMeadEval(struct tagLALInferenceRunState *runState,
558  char **names, REAL8 *values, int dim,
559  REAL8 *logprior, REAL8 *loglikelihood)
560 // Auxiliary function for "NelderMeadAlgorithm()" (see below).
561 // Evaluates Prior & Likelihood for a given (sub-) set of parameters.
562 // /!\ Side effect: alters value of "runState->currentParams" !
563 {
564  //int i;
565  // copy over (subset of) values from "value" argument
566  // (other parameter values, if any, remain as they are):
567  LALInferenceThreadState *thread = &runState->threads[0];
568  for (i=0; i<dim; ++i)
569  LALInferenceSetVariable(thread->currentParams, names[i], &values[i]);
570  // evaluate prior & likelihood:
571  *logprior = runstate->prior(runstate, thread->currentParams, thread->model);
572  if (*logprior > -HUGE_VAL)
573  *loglikelihood = runState->likelihood(thread->currentParams, runState->data, thread->model);
574  else
575  *loglikelihood = -HUGE_VAL;
576  thread->currentLikelihood = *loglikelihood;
577  // printf(" x");
578  return;
579 }
580 
581 
582 void NelderMeadAlgorithm(struct tagLALInferenceRunState *runState, LALInferenceVariables *subset)
583 /************************************************************************************/
584 /* Nelder-Mead (flexible polyhedron search) algorithm */
585 /* following D. M. Himmelblau (1972): Applied nonlinear programming. McGraw-Hill. */
586 /************************************************************************************/
587 /* Starting values are generated from the "runState->threads[0]->currentParams" */
588 /* value, by using repeated draws from "runState->threads[0]->proposal()" functio */
589 /* while ensuring non-zero prior density for these. Depending on the "ML" setting */
590 /* (still hard-coded, see below), it will either aim for Maximum-Likelihood (ML) or */
591 /* Maximum-A-Posteriori (MAP) values. In future, one should be able to specify the */
592 /* subset of parameters to be optimized over (since e.g. one wouldn't want */
593 /* tooptimize over PN order, whichi may also be part of the parameters. Or one may */
594 /* want to keep sky location fixed). */
595 /* By now the algorithm can only handle REAL8 parameters. */
596 /************************************************************************************/
597 /* TO DO: */
598 /* - use (named) "subset" argument to determine subset of parameters over which to */
599 /* optimize. By now simply all "REAL8" values are used. */
600 /* - allow to specify "ML" option from outside function. */
601 /* - allow to supply starting simplex? */
602 /* - allow to specify stop criteria from outside. */
603 /* - get rid of text output. */
604 /* - somehow allow parameters like phase or rightascension to wrap around */
605 /* (i.e. let the simplex move across parameter space bounds) */
606 /************************************************************************************/
607 {
608  int ML = 1; // ML==1 --> Maximum-Likelihood (ML); ML==0 --> Maximum-A-Posteriori (MAP).
609  //REAL8 e = sqrt(LAL_REAL8_EPS); // stop criterion
610  REAL8 epsilon = 0.001; // stop criterion
611  int maxiter = 500; // also stop criterion
612 
613  //int i, j;
614  LALInferenceVariables param;
615  LALInferenceVariables startval;
616  char str[VARNAME_MAX];
617  int nmDim; // dimension of (sub-) space to be optimized over.
618  char **nameVec=NULL; // vector of dimensions' names.
619  REAL8 *R8Vec=NULL;
620  REAL8 *simplex=NULL; // (d x (d+1)) - matrix containing simplex vertices.
621  REAL8 *val_simplex; // corresponding function values (likelihood or posterior).
622  REAL8 logprior, loglikelihood; // dummy variables.
623  REAL8 *centroid, *reflected, *expanded, *contracted; // proposed new vertices...
624  REAL8 val_reflected, val_expanded, val_contracted; // ...and corresponding function values
625  int iteration;
626  int terminate=0;
627  int mini, maxi;
628 
629  LALInferenceThreadState *thread = &runState->threads[0];
630 
631  printf(" NelderMeadAlgorithm(); current parameter values:\n");
633  startval.head=NULL;
634  startval.dimension=0;
635  LALInferenceCopyVariables(thread->currentParams, &startval);
636 
637  // initialize "param":
638  param.head=NULL;
639  param.dimension=0;
640  // "subset" specified? If not, simply gather all REAL8 elements of "currentParams" to optimize over:
641  if (subset==NULL) {
642  if (thread->currentParams == NULL) {
643  fprintf(stderr," ERROR in NelderMeadAlgorithm(): no \"thread->currentParams\" vector provided.\n");
644  exit(1);
645  }
647  if (i==0) {
648  fprintf(stderr," ERROR in NelderMeadAlgorithm(): empty \"thread->currentParams\" vector provided.\n");
649  exit(1);
650  }
651  for (j=1; j<=i; ++j) { // check "currentParams" entries and copy all REAL( values:
653  strcpy(str, LALInferenceGetVariableName(thread->currentParams, j));
655  }
656  }
657  }
658  else {
659  fprintf(stderr," ERROR in NelderMeadAlgorithm(): \"subset\" feature not yet implemented.\n"); exit(0);
660  // TODO: take a (named) "subset" vector of zeroes/ones indicating which variables optimize over and which to keep fixed.
661  }
662 
663  // Figure out parameter space dimension, names, &c.:
664  nmDim = LALInferenceGetVariableDimension(&param);
665  R8Vec = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim);
666  nameVec = (char**) XLALMalloc(sizeof(char*) * nmDim);
667  for (i=0; i<nmDim; ++i) {
668  nameVec[i] = (char*) XLALMalloc(sizeof(char) * VARNAME_MAX);
669  strcpy(nameVec[i], LALInferenceGetVariableName(&param, i+1));
670  R8Vec[i] = *(REAL8*) LALInferenceGetVariable(&param, nameVec[i]);
671  }
672  simplex = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim * (nmDim+1));
673  val_simplex = (REAL8*) XLALMalloc(sizeof(REAL8) * (nmDim+1));
674  centroid = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim);
675  reflected = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim);
676  expanded = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim);
677  contracted = (REAL8*) XLALMalloc(sizeof(REAL8) * nmDim);
678 
679  // populate simplex;
680  // first corner is starting value:
681  for (j=0; j<nmDim; ++j)
682  simplex[j] = *(REAL8*) LALInferenceGetVariable(&param, nameVec[j]);
683  NelderMeadEval(runState, nameVec, &simplex[0], nmDim, &logprior, &loglikelihood);
684  if (!(loglikelihood>-HUGE_VAL)) {
685  fprintf(stderr," ERROR in NelderMeadAlgorithm(): invalid starting value provided.\n");
686  exit(1);
687  }
688  val_simplex[0] = ML ? loglikelihood : logprior+loglikelihood;
689  // remaining corners are drawn from "runState->proposal()" function:
690  for (i=1; i<(nmDim+1); ++i) { // (loop over vertices (except 1st))
691  logprior = -HUGE_VAL;
692  while (!(logprior > -HUGE_VAL)) {
693  // draw a proposal & copy over:
694  LALInferenceCopyVariables(&startval, thread->currentParams);
695  thread->proposal(thread, thread->currentParams, &param);
696  for (j=0; j<nmDim; ++j)
697  simplex[i*nmDim+j] = *(REAL8*) LALInferenceGetVariable(&param, nameVec[j]);
698  // compute prior & likelihood:
699  NelderMeadEval(runState, nameVec, &simplex[i*nmDim], nmDim, &logprior, &loglikelihood);
700  val_simplex[i] = ML ? loglikelihood : logprior+loglikelihood;
701  }
702  }
703  // determine minimum & maximum in simplex:
704  mini = maxi = 0;
705  for (i=1; i<(nmDim+1); ++i) {
706  if (val_simplex[i] < val_simplex[mini]) mini = i;
707  if (val_simplex[i] > val_simplex[maxi]) maxi = i;
708  }
709 
710  // start actual Nelder-Mead iterations:
711  iteration = 0;
712  while (!terminate) {
713  ++iteration;
714  // determine centroid of simplex, excluding the worst (minimal) point:
715  for (i=0; i<nmDim; ++i) { // (loop over parameter dimensions)
716  centroid[i] = 0.0;
717  for (j=0; j<(nmDim+1); ++j) // (loop over simplex vertices)
718  centroid[i] += (j==mini) ? 0.0 : (1.0/((double)nmDim)) * simplex[j*nmDim+i];
719  }
720  NelderMeadEval(runState, nameVec, centroid, nmDim, &logprior, &loglikelihood);
721  // UNUSED!!: REAL8 val_centroid = ML ? loglikelihood : logprior+loglikelihood;
722 
723  // REFLECT:
724  for (i=0; i<nmDim; ++i)
725  reflected[i] = centroid[i] + 1.0*(centroid[i] - simplex[mini*nmDim + i]);
726  NelderMeadEval(runState, nameVec, reflected, nmDim, &logprior, &loglikelihood);
727  val_reflected = ML ? loglikelihood : logprior+loglikelihood;
728  if (val_reflected > val_simplex[maxi]) { // reflected better than best so far?
729  // EXPAND:
730  for (i=0; i<nmDim; ++i)
731  expanded[i] = centroid[i] + 2.9*(reflected[i] - centroid[i]);
732  NelderMeadEval(runState, nameVec, expanded, nmDim, &logprior, &loglikelihood);
733  val_expanded = ML ? loglikelihood : logprior+loglikelihood;
734  if (val_expanded > val_simplex[maxi]) { // expanded better than best so far?
735  for (i=0; i<nmDim; ++i) // adopt expanded
736  simplex[mini*nmDim+i] = expanded[i];
737  val_simplex[mini] = val_expanded;
738  }
739  else {
740  for (i=0; i<nmDim; ++i) // adopt reflected
741  simplex[mini*nmDim+i] = reflected[i];
742  val_simplex[mini] = val_reflected;
743  }
744  }
745  else { // (reflected is worse that best so far)
746  // check: reflected better than any of current (except worst)?
747  j=0;
748  for (i=0; i<(nmDim+1); ++i)
749  j += ((i!=mini) && (val_reflected > val_simplex[i]));
750  if (j>0) {
751  for (i=0; i<nmDim; ++i) // adopt reflected
752  simplex[mini*nmDim+i] = reflected[i];
753  val_simplex[mini] = val_reflected;
754  }
755  else { // (reflected is either worst or 2nd worst)
756  if (val_reflected > val_simplex[mini]) { // if 2nd worst, adopt
757  for (i=0; i<nmDim; ++i) // adopt reflected
758  simplex[mini*nmDim+i] = reflected[i];
759  val_simplex[mini] = val_reflected;
760  }
761  // either way: CONTRACT:
762  for (i=0; i<nmDim; ++i)
763  contracted[i] = centroid[i] + 0.5*(simplex[mini*nmDim+i] - centroid[i]);
764  NelderMeadEval(runState, nameVec, contracted, nmDim, &logprior, &loglikelihood);
765  val_contracted = ML ? loglikelihood : logprior+loglikelihood;
766  if (val_contracted > val_simplex[mini]) { // adopt contracted
767  for (i=0; i<nmDim; ++i)
768  simplex[mini*nmDim+i] = contracted[i];
769  val_simplex[mini] = val_contracted;
770  }
771  else { // contraction didn't help, REDUCE:
772  for (i=0; i<(nmDim+1); ++i) // loop over vertices
773  if (i!=maxi) {
774  for (j=0; j<nmDim; ++j) // loop over parameters
775  simplex[i*nmDim+j] += 0.5 * (simplex[maxi*nmDim+j] - simplex[i*nmDim+j]);
776  NelderMeadEval(runState, nameVec, &simplex[i*nmDim], nmDim, &logprior, &loglikelihood);
777  val_simplex[i] = ML ? loglikelihood : logprior+loglikelihood;
778  }
779  }
780  }
781  }
782  // re-determine minimum & maximum:
783  mini = maxi = 0;
784  for (i=1; i<(nmDim+1); ++i) {
785  if (val_simplex[i] < val_simplex[mini]) mini = i;
786  if (val_simplex[i] > val_simplex[maxi]) maxi = i;
787  }
788  printf(" iter=%d, maxi=%f, range=%f\n",
789  iteration, val_simplex[maxi], val_simplex[maxi]-val_simplex[mini]);
790  // termination condition:
791  terminate = ((val_simplex[maxi]-val_simplex[mini]<epsilon) || (iteration>=maxiter));
792  }
793  // copy optimized value over to "thread->currentParams":
794  for (j=0; j<nmDim; ++j)
795  LALInferenceSetVariable(thread->currentParams, nameVec[j], &simplex[maxi*nmDim+j]);
796  thread->currentLikelihood = ML ? val_simplex[maxi] : runState->likelihood(thread->currentParams, runState->data, thread->model);
797 
798  printf(" NelderMeadAlgorithm(); done.\n");
800 
801  LALInferenceClearVariables(&startval);
803  XLALFree(R8Vec);
804  for (i=0; i<nmDim; ++i) XLALFree(nameVec[i]);
805  XLALFree(nameVec);
806  XLALFree(simplex);
807  XLALFree(val_simplex);
808  XLALFree(centroid);
809  XLALFree(reflected);
810  XLALFree(expanded);
811  XLALFree(contracted);
812 }
813 
814 
816 {
817  number = 10.0;
818  five=5.0;
819  variables.head=NULL;
821 
822  memset(&status,0,sizeof(status));
824  numberR8 = 7.0;
826  numberR8 = LAL_PI;
828  numberI4 = 123;
830  numberI8 = 256*256*256*64;
832  numberC8 = crectf( 2.0, 3.0 );
834  numberC16 = crect( 1.23, -3.45 );
836 
838  fprintf(stdout,"Got %lf\n",number);
841  fprintf(stdout,"Got %lf\n",number);
842  fprintf(stdout,"Checkvariable?: %i\n",LALInferenceCheckVariable(&variables,"number"));
846  fprintf(stdout,"LALInferenceCompareVariables?: %i\n",
848  numberC16 = crect( creal(numberC16), 4.56 );
850  fprintf(stdout,"LALInferenceCompareVariables?: %i\n",
852  numberC16 = crect( creal(numberC16), -3.45 );
854  fprintf(stdout,"LALInferenceCompareVariables?: %i\n",
856 
858  fprintf(stdout,"Removed, Checkvariable?: %i\n",LALInferenceCheckVariable(&variables,"number"));
859 
860  fprintf(stdout,"LALInferenceCompareVariables?: %i\n",
865 
866  fprintf(stdout," ----------\n");
867 }
868 
869 void DataTest(void)
870 {
871  fprintf(stdout," data found --> trying some template computations etc.\n");
872 
873  /* print some information on individual "runstate->data" elements: */
874  IfoPtr = runstate->data; i = 1;
875  while (IfoPtr != NULL) {
876  if (IfoPtr->timeData)
877  fprintf(stdout, " [%d] timeData (\"%s\"): length=%d, deltaT=%f, epoch=%.3f\n",
880  if (IfoPtr->freqData)
881  fprintf(stdout, " freqData (\"%s\"): length=%d, deltaF=%f\n",
883  fprintf(stdout, " fLow=%.1f Hz, fHigh=%.1f Hz (%d freq bins w/in range)\n",
884  IfoPtr->fLow, IfoPtr->fHigh,
885  ((int) (floor(IfoPtr->fHigh / IfoPtr->freqData->deltaF) - ceil(IfoPtr->fLow / IfoPtr->freqData->deltaF)))+1);
886  fprintf(stdout, " detector location: (%.1f, %.1f, %.1f)\n",
888  fprintf(stdout, " detector response matrix:\n");
889  for (j=0; j<3; ++j){
890  fprintf(stdout, " ");
891  for (k=0; k<3; ++k)
892  fprintf(stdout, "%f ", IfoPtr->detector->response[j][k]);
893  fprintf(stdout, "\n");
894  }
895  IfoPtr = IfoPtr->next;
896  }
897 
900 
901  REAL8 mc = injTable->mchirp;
902  REAL8 eta = injTable->eta;
903  REAL8 iota = injTable->inclination;
904  REAL8 phi = injTable->coa_phase;
905  LIGOTimeGPS trigger_time=injTable->geocent_end_time;
906  REAL8 tc = XLALGPSGetREAL8(&trigger_time);
907  REAL8 ra_current = injTable->longitude;
908  REAL8 dec_current = injTable->latitude;
909  REAL8 psi_current = injTable->polarization;
910  REAL8 distMpc_current = injTable->distance;
911 
912 
922  /* fprintf(stdout, " trying 'templateLAL' likelihood...\n");
923  numberI4 = TaylorF2;
924  LALInferenceAddVariable(&currentParams, "LAL_APPROXIMANT", &numberI4, LALINFERENCE_INT4_t, LALINFERENCE_PARAM_FIXED);
925  numberI4 = LAL_PNORDER_TWO;
926  LALInferenceAddVariable(&currentParams, "LAL_PNORDER", &numberI4, LALINFERENCE_INT4_t, LALINFERENCE_PARAM_FIXED);*/
928 printf("Likelihood %g NullLikelihood %g RelativeLikelihood %g\n", likelihood, nulllikelihood, likelihood-nulllikelihood);
929 
930 /*
931  LALTemplateGeneratePPN(runstate->data);
932  executeFT(runstate->data);
933 
934  FILE *testout=fopen("test_FD.txt","w");
935  for (i=0;i<runstate->data->freqModelhPlus->data->length;i++){
936  fprintf(testout,"%g %g %g %g %g\n",i*runstate->data->freqModelhPlus->deltaF,
937  runstate->data->freqModelhPlus->data->data[i].re,
938  runstate->data->freqModelhPlus->data->data[i].im,
939  runstate->data->freqModelhCross->data->data[i].re,
940  runstate->data->freqModelhCross->data->data[i].im);
941  }
942  fclose(testout);
943  testout=fopen("test_TD.txt","w");
944  for (i=0;i<runstate->data->timeModelhPlus->data->length;i++){
945  fprintf(testout,"%10.10lf %g %g\n",runstate->data->timeData->epoch.gpsSeconds
946  +(1e-9*runstate->data->timeData->epoch.gpsNanoSeconds)+i*runstate->data->timeModelhPlus->deltaT,
947  runstate->data->timeModelhPlus->data->data[i],
948  runstate->data->timeModelhCross->data->data[i]);
949  }
950  fclose(testout);
951  testout=fopen("PSD.txt","w");
952  for (i=0;i<runstate->data->oneSidedNoisePowerSpectrum->data->length;i++){
953  fprintf(testout,"%g %g\n",i*runstate->data->oneSidedNoisePowerSpectrum->deltaF,
954  runstate->data->oneSidedNoisePowerSpectrum->data->data[i]);
955  }
956  fclose(testout);
957  testout=fopen("noise_TD.txt","w");
958  for (i=0;i<runstate->data->timeData->data->length;i++){
959  fprintf(testout,"%10.10lf %g\n",runstate->data->timeData->epoch.gpsSeconds
960  +(1e-9*runstate->data->timeData->epoch.gpsNanoSeconds)+i*runstate->data->timeData->deltaT,
961  runstate->data->timeData->data->data[i]);
962  }
963  fclose(testout);
964  testout=fopen("noise_FD.txt","w");
965  for (i=0;i<runstate->data->freqData->data->length;i++){
966  //fprintf(testout,"%g %g %g %g %g\n",i*runstate->data->freqData->deltaF,
967  fprintf(testout,"%g %g %g\n",i*runstate->data->freqData->deltaF,
968  runstate->data->freqData->data->data[i].re,
969  //runstate->data->freqData->data->data[i].im,
970  //runstate->data->freqData->data->data[i].re,
971  runstate->data->freqData->data->data[i].im);
972  }
973 
974 */
975  fprintf(stdout," ----------\n");
976 }
977 
978 
979 
981 {
983  fprintf(stdout, "Single IFO likelihood test\n");
984  //COMPLEX16Vector *freqModel1=XLALCreateCOMPLEX16Vector(runstate->data->freqData->data->length);
985  //COMPLEX16Vector *freqModel2=XLALCreateCOMPLEX16Vector(runstate->data->freqData->data->length);
987  LALInferenceSetVariable(&currentParams, "LAL_PNORDER", &numberI4);
988  numberI4 = TaylorT1;
989  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
990  //LALInferenceComputeFreqDomainResponse(&currentParams, runstate->data, runstate->model, freqModel1);
991  //freqModel2=runstate->data->freqData->data;
992  //ComputeFreqDomainResponse(&currentParams, runstate->data, templateLAL, freqModel2);
993  //FILE * freqModelFile=fopen("freqModelFile.dat", "w");
994  /*for(i=0; i<(int)runstate->data->freqData->data->length; i++){
995  fprintf(freqModelFile, "%g\t %g\t %g\t %g\t %g\t %g\n",
996  ((double)i)*1.0/ (((double)runstate->data->timeData->data->length) * runstate->data->timeData->deltaT),
997  creal(freqModel1->data[i]), cimag(freqModel1->data[i]), creal(freqModel2->data[i]), cimag(freqModel2->data[i]),
998  runstate->data->oneSidedNoisePowerSpectrum->data->data[i]);
999  }*/
1000  /*fprintf(stdout, "overlap=%g\n",
1001  LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel1, freqModel2));
1002  fprintf(stdout, "<d|d>=%g, <d|h>=%g, <h|h>=%g, <d|h>-1/2<h|h>=%g\n",
1003  LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel2, freqModel2),
1004  LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel1, freqModel2),
1005  LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel1, freqModel1),
1006  LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel2, freqModel1)
1007  -0.5*LALInferenceComputeFrequencyDomainOverlap(runstate->data, freqModel1, freqModel1)
1008  );*/
1009  //fprintf(stdout, "likelihood %g\n",
1010  // LALInferenceFreqDomainLogLikelihood(&currentParams, runstate->data, runstate->model));
1011  fprintf(stdout, "undecomposed likelihood %g \n",
1013  fprintf(stdout, "null likelihood %g decomposed null likelihood %g\n",
1016  //XLALDestroyCOMPLEX16Vector(freqModel1);
1017  // XLALDestroyCOMPLEX16Vector(freqModel2);
1018 }
1019 
1020 
1021 
1023 {
1024  LALInferenceThreadState *thread = &runstate->threads[0];
1025 
1026  /* NOTE: try out the "forceTimeLocation" flag within the "templateLAL()" function */
1027  /* for aligning (time domain) templates. */
1028  fprintf(stdout," generating templates & writing to files...:\n");
1029  LALInferenceDumptemplateFreqDomain(&currentParams, thread->model, "test_FTemplate25SP.csv");
1030  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplate25SP.csv");
1031  LALInferenceDumptemplateFreqDomain(&currentParams, thread->model, "test_FTemplate3525TD.csv");
1032  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplate3525TD.csv");
1033 
1034  fprintf(stdout," ----------\n");
1035 
1036  double mass1=10.;
1037  double mass2=1.4;
1040  double spin1x = 0.5;
1041  double spin1y = 0.1;
1042  double spin1z = 0.0;
1043  double spin2x = 0.2;
1044  double spin2y = 0.0;
1045  double spin2z = 0.3;
1052  double shift0 = 0.3;
1054  double coa_phase = 0.1;
1056  double PNorder = 3.5;
1058  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveformSTPN.csv");
1059 
1060 
1061  /* These are the LAL templates that (...seem to...) work right now: */
1062  /* TaylorT1, TaylorT2, TaylorT3, TaylorF2, IMRPhenomA, PadeT1, EOB */
1064  LALInferenceSetVariable(&currentParams, "LAL_PNORDER", &numberI4);
1065  numberI4 = TaylorF2;
1066  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1067  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-TF2.csv");
1068  numberI4 = TaylorT1;
1069  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1070  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-TT1.csv");
1071  numberI4 = TaylorT2;
1072  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1073  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-TT2.csv");
1074  numberI4 = TaylorT3;
1075  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1076  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-TT3.csv");
1077 
1078  numberI4 = IMRPhenomA;
1079  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1080  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-Phenom.csv");
1081  LALInferenceDumptemplateFreqDomain(&currentParams,thread->model, "test_FTemplateXLALSimInspiralChooseWaveform-Phenom.csv");
1082 
1083  numberI4 = PadeT1;
1084  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1085  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-PadeT1.csv");
1086 
1087  numberI4 = EOB;
1088  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1090  LALInferenceSetVariable(&currentParams, "LAL_PNORDER", &numberI4);
1091  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-EOB.csv");
1092 
1093  numberI4 = BCV;
1094  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1096  LALInferenceSetVariable(&currentParams, "LAL_PNORDER", &numberI4);
1097  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-BCV.csv");
1098 
1099  numberI4 = EOBNR;
1100  LALInferenceSetVariable(&currentParams, "LAL_APPROXIMANT", &numberI4);
1102  LALInferenceSetVariable(&currentParams, "LAL_PNORDER", &numberI4);
1103  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateXLALSimInspiralChooseWaveform-EOBNR.csv");
1104 
1105  fprintf(stdout," ----------\n");
1106 
1107  numberR8 = 440;
1109  numberR8 = 1e-19;
1112  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateSinc.csv");
1113 
1114  numberR8 = 0.01;
1117  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateSineGauss.csv");
1118 
1119  numberR8 = 0.01;
1122  LALInferenceDumptemplateTimeDomain(&currentParams, thread->model, "test_TTemplateDampedSinus.csv");
1123 
1126  fprintf(stdout," ----------\n");
1127 }
1128 
1129 void PTMCMCTest(void)
1130 {
1131  fprintf(stdout, "PTMCMC test\n");
1132  LALInferenceThreadState *thread = &runstate->threads[0];
1133  //runstate->algorithm=PTMCMCAlgorithm;
1134  //runstate->evolve=PTMCMCOneStep;
1135  //runstate->prior=PTUniformLALPrior;
1136  //runstate->prior=PTUniformGaussianPrior;
1137  //runstate->proposal=PTMCMCLALProposal;
1138  //runstate->proposal=PTMCMCGaussianProposal;
1140  runstate->proposalArgs->head=NULL;
1142  //runstate->likelihood=LALInferenceFreqDomainLogLikelihood;
1144  //runstate->likelihood=GaussianLikelihood;
1146 
1147 
1149 
1150  REAL8 mc = injTable->mchirp;
1151  REAL8 eta = injTable->eta;
1152  REAL8 iota = injTable->inclination;
1153  REAL8 phi = injTable->coa_phase;
1154  LIGOTimeGPS trigger_time=injTable->geocent_end_time;
1155  REAL8 tc = XLALGPSGetREAL8(&trigger_time);
1156  REAL8 ra_current = injTable->longitude;
1157  REAL8 dec_current = injTable->latitude;
1158  REAL8 psi_current = injTable->polarization;
1159  REAL8 distMpc_current = injTable->distance;
1160 
1161  numberI4 = TaylorF2;
1165 
1175 
1176 
1177  REAL8 x0 = 0.9;
1179 
1180 
1181 
1182 
1183  thread->currentParams=&currentParams;
1184  //PTMCMCAlgorithm(runstate);
1185  fprintf(stdout, "End of PTMCMC test\n");
1186 }
1187 
1188 
ProcessParamsTable * LALInferenceParseCommandLine(int argc, char *argv[])
void LALInferenceInitCBCThreads(LALInferenceRunState *run_state, INT4 nthreads)
void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
INT4 numberI4
void NelderMeadAlgorithm(struct tagLALInferenceRunState *runState, LALInferenceVariables *subset)
REAL8 nulllikelihood
void TemplateDumpTest(void)
LALInferenceVariables currentParams
int LALInferenceParseCommandLineTEST_STDINPUT(void)
LALInferenceVariables variables2
REAL8 numberR8
LALInferenceVariables variables
void PTMCMCTest(void)
INT8 numberI8
ProcessParamsTable * ppt
int LALInferenceProcessParamLine_TEST_CHARFILE(void)
int j
REAL4 number
void NelderMeadEval(struct tagLALInferenceRunState *runState, char **names, REAL8 *values, int dim, REAL8 *logprior, REAL8 *loglikelihood)
void LALVariablesTest(void)
void DataTest(void)
void BasicMCMCOneStep(LALInferenceRunState *runState)
REAL8 likelihood
COMPLEX8 numberC8
int LALInferenceParseCommandLineTEST_DASHINPUT(void)
int main(void)
int LALInferenceExecuteFTTEST_NULLPLAN(void)
LALInferenceIFOData * IfoPtr
LALStatus status
REAL4 five
COMPLEX16 numberC16
LALInferenceRunState * runstate
ProcessParamsTable * ptr
int k
int LALInferenceProcessParamLine_TEST_EMPTYFILE(void)
int LALInferenceParseCommandLineTEST_NODBLDASH(void)
int i
void BasicMCMCTest(void)
LALInferenceRunState * initialize(ProcessParamsTable *commandLine)
*Idential to FreqDomainNullLogLikelihood *‍/
int LALInferenceProcessParamLine_TEST(void)
void SingleIFOLikelihoodTest(void)
void MCMCAlgorithm(struct tagLALInferenceRunState *runState)
#define TEST_FAIL(...)
#define TEST_FOOTER()
#define TEST_HEADER()
#define LALCalloc(m, n)
SimInspiralTable * XLALSimInspiralTableFromLIGOLw(const char *fileName)
#define fprintf
const char * names[]
double e
#define LAL_PI
#define crect(re, im)
double complex COMPLEX16
double REAL8
int64_t INT8
#define crectf(re, im)
uint32_t UINT4
float complex COMPLEX8
int32_t INT4
float REAL4
#define VARNAME_MAX
Definition: LALInference.h:50
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
Add a variable named name to vars with initial value referenced by value.
Definition: LALInference.c:395
void LALInferenceExecuteFT(LALInferenceModel *model)
Execute FFT for data in IFOdata.
int LALInferenceCompareVariables(LALInferenceVariables *var1, LALInferenceVariables *var2)
Check for equality in two variables.
char * LALInferenceGetVariableName(LALInferenceVariables *vars, int idx)
Get the name of the idx-th variable Indexing starts at 1.
Definition: LALInference.c:339
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
Definition: LALInference.c:450
INT4 LALInferenceGetVariableTypeByIndex(LALInferenceVariables *vars, int idx)
Get the LALInferenceVariableType of the idx -th item in the vars Indexing starts at 1.
Definition: LALInference.c:326
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
Definition: LALInference.c:558
void LALInferenceProcessParamLine(FILE *inp, char **headers, LALInferenceVariables *vars)
Reads one line from the given file and stores the values there into the variable structure,...
INT4 LALInferenceGetVariableDimension(LALInferenceVariables *vars)
Get number of dimensions in variable vars.
Definition: LALInference.c:250
void LALInferenceClearVariables(LALInferenceVariables *vars)
Delete the variables in this structure.
Definition: LALInference.c:532
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
Return a pointer to the memory the variable vars is stored in specified by name User must cast this p...
Definition: LALInference.c:238
void LALInferencePrintVariables(LALInferenceVariables *var)
output contents of a 'LALInferenceVariables' structure * / / * (by now only prints names and types,...
Definition: LALInference.c:798
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
Definition: LALInference.c:525
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
Set a variable named name in vars with a value.
Definition: LALInference.c:352
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
Definition: LALInference.h:130
@ LALINFERENCE_PARAM_CIRCULAR
A parameter that simply has a maximum and a minimum.
Definition: LALInference.h:129
@ LALINFERENCE_PARAM_LINEAR
Definition: LALInference.h:128
@ LALINFERENCE_COMPLEX16_t
Definition: LALInference.h:111
@ LALINFERENCE_REAL8_t
Definition: LALInference.h:109
@ LALINFERENCE_REAL4_t
Definition: LALInference.h:108
@ LALINFERENCE_INT4_t
Definition: LALInference.h:105
@ LALINFERENCE_INT8_t
Definition: LALInference.h:106
@ LALINFERENCE_COMPLEX8_t
Definition: LALInference.h:110
REAL8 LALInferenceNullLogLikelihood(LALInferenceIFOData *data)
Identical to LALInferenceFreqDomainNullLogLikelihood, but returns the likelihood of a null template.
REAL8 LALInferenceUndecomposedFreqDomainLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
(log-) likelihood function.
LALInferenceIFOData * LALInferenceReadData(ProcessParamsTable *commandLine)
Read IFO data according to command line arguments.
void LALInferenceDumptemplateFreqDomain(LALInferenceVariables *currentParams, LALInferenceModel *model, const char *filename)
De-bugging function writing a (frequency-domain) signal template to a CSV file.
void LALInferenceDumptemplateTimeDomain(LALInferenceVariables *currentParams, LALInferenceModel *model, const char *filename)
De-bugging function writing a (time-domain) signal template to a CSV file.
void LALInferenceTemplateSineGaussian(LALInferenceModel *model)
Sine-Gaussian (burst) template.
void LALInferenceTemplateXLALSimInspiralChooseWaveform(LALInferenceModel *model)
"XLALSimInspiralChooseWaveform{TD,FD}" wrapper.
void LALInferenceTemplateSinc(LALInferenceModel *model)
Sinc function (burst) template.
void LALInferenceTemplateDampedSinusoid(LALInferenceModel *model)
Damped Sinusoid template.
void * XLALCalloc(size_t m, size_t n)
void * XLALMalloc(size_t n)
void XLALFree(void *p)
EOB
PadeT1
EOBNR
IMRPhenomA
TaylorT3
TaylorF2
BCV
TaylorT1
TaylorT2
LAL_PNORDER_TWO
LAL_PNORDER_PSEUDO_FOUR
REAL8Sequence * XLALCreateREAL8Sequence(size_t length)
COMPLEX16Sequence * XLALCreateCOMPLEX16Sequence(size_t length)
REAL8TimeSeries * XLALCreateREAL8TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
const LALUnit lalDimensionlessUnit
const char * XLALErrorString(int errnum)
#define XLAL_TRY(statement, errnum)
XLAL_SUCCESS
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
CHAR name[LALNameLength]
COMPLEX16Sequence * data
REAL4 response[3][3]
REAL8 location[3]
Structure to contain IFO data.
Definition: LALInference.h:625
REAL8TimeSeries * timeData
Detector name.
Definition: LALInference.h:627
LALDetector * detector
integration limits for overlap integral in F-domain
Definition: LALInference.h:651
REAL8Window * window
(one-sided Noise Power Spectrum)^{-1/2}
Definition: LALInference.h:646
COMPLEX16FrequencySeries * freqData
What is this?
Definition: LALInference.h:639
struct tagLALInferenceIFOData * next
ROQ data.
Definition: LALInference.h:659
REAL8 fLow
FFT plan needed for time/time-and-phase marginalisation.
Definition: LALInference.h:650
Structure to constain a model and its parameters.
Definition: LALInference.h:436
REAL8FFTPlan * timeToFreqFFTPlan
Burst Waveform cache for LIB.
Definition: LALInference.h:460
REAL8TimeSeries * timehCross
Definition: LALInference.h:453
REAL8TimeSeries * timehPlus
Definition: LALInference.h:453
LALInferenceTemplateFunction templt
Domain of model.
Definition: LALInference.h:440
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
LALInferenceVariables * proposalArgs
The data from the interferometers.
Definition: LALInference.h:602
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferenceThreadState * threads
Definition: LALInference.h:612
LALInferencePriorFunction prior
The algorithm's single iteration function.
Definition: LALInference.h:597
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Definition: LALInference.h:599
Structure containing chain-specific variables.
Definition: LALInference.h:541
LALInferenceVariables * currentParams
Prior boundaries, etc.
Definition: LALInference.h:556
LALInferenceModel * model
Cycle of proposals to call.
Definition: LALInference.h:548
LALInferenceProposalFunction proposal
Step counter for this thread.
Definition: LALInference.h:546
REAL8 * currentIFOLikelihoods
Array storing single-IFO SNRs of current sample.
Definition: LALInference.h:569
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
Definition: LALInference.h:170
LALInferenceVariableItem * head
Definition: LALInference.h:171
CHAR value[LIGOMETA_VALUE_MAX]
REAL8Sequence * data
LIGOTimeGPS epoch
CHAR name[LALNameLength]
REAL8 * data
REAL8Sequence * data
LIGOTimeGPS geocent_end_time
enum @1 epoch