Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-00ddc7f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInferenceNest.c
Go to the documentation of this file.
1/*
2 * InferenceNest.c: Nested Sampling using LALInference
3 *
4 * Copyright (C) 2009 Ilya Mandel, Vivien Raymond, Christian Roever, Marc van der Sluys and John Veitch
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with with program; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301 USA
21 */
22
23
24#include <stdio.h>
25#include <lal/Date.h>
26#include <lal/GenerateInspiral.h>
27#include <lal/LALInference.h>
28#include <lal/FrequencySeries.h>
29#include <lal/Units.h>
30#include <lal/StringInput.h>
31#include <lal/TimeSeries.h>
32#include <lal/LALInferenceNestedSampler.h>
33#include <lal/LALInferencePrior.h>
34#include <lal/LALInferenceReadData.h>
35#include <lal/LALInferenceLikelihood.h>
36#include <lal/LALInferenceTemplate.h>
37#include <lal/LALInferenceProposal.h>
38#include <lal/LALInferenceInit.h>
39#include <lal/LALInferenceCalibrationErrors.h>
40#include <lal/LALInferenceVCSInfo.h>
41
42/*************** MAIN **********************/
43
44
45int main(int argc, char *argv[]){
46 int helpflag=0;
47 char help[]="\
48 LALInferenceNest:\n\
49 Bayesian analysis tool using Nested Sampling algorithm\n\
50 for CBC analysis. Uses LALInference library for back-end.\n\n\
51 Arguments for each section follow:\n\n";
52
54 ProcessParamsTable *procParams=NULL;
56
57 /* Read command line and parse */
58 procParams=LALInferenceParseCommandLine(argc,argv);
59 if(LALInferenceGetProcParamVal(procParams,"--help"))
60 {
61 helpflag=1;
62 fprintf(stdout,"%s",help);
63 }
64 /* write down git information */
66
67 /* initialise runstate based on command line */
68 /* This includes reading in the data */
69 /* And performing any injections specified */
70 /* And allocating memory */
71 state = LALInferenceInitRunState(procParams);
72 /* Create header */
73 if (state!=NULL && !helpflag){
76 if(!ppt){
78 if(!ppt){
79 fprintf(stderr,"Must specify --outfile <filename.dat> or --outhdf <filename.h5>\n");
80 exit(1);
81 }
82 }
83 char *outfile=ppt->value;
84 char headerfile[FILENAME_MAX+100];
85 FILE *fpout=NULL;
86 snprintf(headerfile,sizeof(headerfile),"%s_header.txt",outfile);
87 fpout=fopen(headerfile,"w");
90 fclose(fpout);
91 }
92 if (state == NULL) {
93 if (!helpflag) {
94 fprintf(stderr, "run state not allocated (%s, line %d).\n",
95 __FILE__, __LINE__);
96 }
97 } else {
98 data = state->data;
99 }
100
101 /* Perform injections if data successful read or created */
102 if (state&&!helpflag){
104 }
105
106 /* Simulate calibration errors.
107 * NOTE: this must be called after both ReadData and (if relevant)
108 * injectInspiralTD/FD are called! */
110
111 /* Set up the appropriate functions for the nested sampling algorithm */
112 if (state){
115
117 }
118
119 if (!helpflag && LALInferenceGetProcParamVal(state->commandLine, "--roqtime_steps")){
120
122 fprintf(stderr, "done LALInferenceSetupROQdata\n");
123
124 }
125
126 /* Set up the threads */
128
129 /* Init the prior */
131
132 /* Set up structures for nested sampling */
134
135 if (state){
136 for(INT4 i=0;i<state->nthreads;i++)
137 {
140 }
141 }
142
143 /* Choose the likelihood and set some auxiliary variables */
145
146 /* Exit since we printed all command line arguments */
147 if(state == NULL || LALInferenceGetProcParamVal(state->commandLine,"--help"))
148 {
149 exit(0);
150 }
151
152 /* Call setupLivePointsArray() to populate live points structures */
154
155 /* write injection with noise evidence information from algorithm */
157
158 /* Call nested sampling algorithm */
159 state->algorithm(state);
160
161 /* end */
162 return(0);
163}
ProcessParamsTable * LALInferenceParseCommandLine(int argc, char *argv[])
void LALInferenceApplyCalibrationErrors(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
LALInferenceRunState * LALInferenceInitRunState(ProcessParamsTable *command_line)
void LALInferenceInitCBCThreads(LALInferenceRunState *run_state, INT4 nthreads)
int main(int argc, char *argv[])
void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
ProcessParamsTable * ppt
const LALVCSInfo lalInferenceVCSInfo
VCS and build information for LALInference.
#define fprintf
sigmaKerr data[0]
int32_t INT4
char * LALInferencePrintCommandLine(ProcessParamsTable *procparams)
Output the command line based on the ProcessParamsTable procparams.
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void LALInferenceInitLikelihood(LALInferenceRunState *runState)
Initialisation function which reads runState->commaneLine and sets up the likelihood function accordi...
void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
NestedSamplingAlgorithm implements the nested sampling algorithm, see e.g.
INT4 LALInferenceNestedSamplingOneStep(LALInferenceRunState *runState)
A single iteration of the NS algorithm.
void LALInferenceSetupLivePointsArray(LALInferenceRunState *runState)
Setup the live points by calling runState->initVariables on each of them if it is specified.
void LALInferenceNestedSamplingAlgorithmInit(LALInferenceRunState *runState)
Initialise the nested sampling algorithm by reading from the commandLine and setting up algorithmPara...
void LALInferenceInitCBCPrior(LALInferenceRunState *runState)
Initialize the prior based on command line arguments.
LALInferenceProposalCycle * LALInferenceSetupDefaultInspiralProposalCycle(LALInferenceVariables *propArgs)
A reasonable default proposal.
LALInferenceVariables * LALInferenceParseProposalArgs(LALInferenceRunState *runState)
Go through all logic for deciding proposals to use.
void LALInferenceRandomizeProposalCycle(LALInferenceProposalCycle *cycle, gsl_rng *rng)
Randomizes the order of the proposals in the proposal cycle.
void LALInferenceSetupROQdata(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
LALInferenceVariables * LALInferencePrintInjectionSample(LALInferenceRunState *runState)
Function to output a sample with logL values etc for the injection, if one is made.
help
Structure to contain IFO data.
Definition: LALInference.h:625
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
ProcessParamsTable * commandLine
Definition: LALInference.h:593
LALInferenceVariables * proposalArgs
The data from the interferometers.
Definition: LALInference.h:602
INT4 nthreads
Array of live points for Nested Sampling.
Definition: LALInference.h:606
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferenceThreadState * threads
Definition: LALInference.h:612
LALInferenceAlgorithm algorithm
A function that returns a new set of variables for the model.
Definition: LALInference.h:595
LALInferenceEvolveOneStepFunction evolve
The algorithm function.
Definition: LALInference.h:596
LALInferenceProposalCycle * cycle
The proposal cycle.
Definition: LALInference.h:547
LALInferenceVariables * proposalArgs
Definition: LALInference.h:551
const char *const vcsDate
const char *const vcsStatus
const char *const vcsAuthor
const char *const vcsId
const char *const vcsBranch
CHAR value[LIGOMETA_VALUE_MAX]
char * outfile