Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pulsar_parameter_estimation_nested.h
Go to the documentation of this file.
1/* ******************************************************************************
2 Matt Pitkin, John Veitch - 2011
3
4 pulsar_parameter_estimation_nested.h
5
6 Header file for pulsar_parameter_estimation_nested.c
7
8*******************************************************************************/
9
10/*
11 Author:
12*/
13
14/**
15 * \defgroup lalpulsar_bin_HeterodyneSearch Heterodyne Search Applications
16 * \ingroup lalpulsar_bin_Apps
17 */
18
19/**
20 * \file
21 * \ingroup lalpulsar_bin_HeterodyneSearch
22 * \author Matthew Pitkin, John Veitch, Colin Gill
23 *
24 * \brief Header file for the parameter estimation code for known pulsar
25 * searches using the nested sampling algorithm.
26 */
27
28#ifndef _PULSAR_PARAMETER_ESTIMATION_NESTED_H
29#define _PULSAR_PARAMETER_ESTIMATION_NESTED_H
30
31#include "config.h"
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <math.h>
36#include <string.h>
37#include <complex.h>
38#include <time.h>
39#include <sys/time.h>
40
41#include <lal/LALStdlib.h>
42#include <lal/LALgetopt.h>
43#include <lal/LALAtomicDatatypes.h>
44#include <lal/LALDatatypes.h>
45#include <lal/AVFactories.h>
46#include <lal/SkyCoordinates.h>
47#include <lal/DetectorSite.h>
48#include <lal/DetResponse.h>
49#include <lal/BinaryPulsarTiming.h>
50#include <lal/Random.h>
51#include <lal/LALString.h>
52#include <lal/SFTfileIO.h>
53#include <lal/LALBarycenter.h>
54#include <lal/LALInitBarycenter.h>
55#include <lal/MatrixUtils.h>
56#include <lal/LALConstants.h>
57#include <lal/XLALError.h>
58#include <lal/ComputeFstat.h>
59#include <lal/TimeSeries.h>
60#include <lal/LALNoiseModels.h>
61#include <lal/Units.h>
62#include <lal/Date.h>
63#include <lal/StringVector.h>
64#include <lal/XLALGSL.h>
65#include <lal/FileIO.h>
66#include <lal/LALPulsarVCSInfo.h>
67
68#include <lal/LALInference.h>
69#include <lal/LALInferenceNestedSampler.h>
70#include <lal/LALInferencePrior.h>
71#include <lal/LALInferenceProposal.h>
72#include <lal/LALInferenceGenerateROQ.h>
73
74#include <lal/LALSimNoise.h>
75
76#include <gsl/gsl_sort_double.h>
77#include <gsl/gsl_statistics_double.h>
78#include <gsl/gsl_blas.h>
79#include <gsl/gsl_sf_gamma.h>
80#include <gsl/gsl_randist.h>
81
82#ifdef __cplusplus
83extern "C" {
84#endif
85
86#ifdef __GNUC__
87#define UNUSED __attribute__ ((unused))
88#else
89#define UNUSED
90#endif
91
92/** Macro to round a value to the nearest integer. */
93#define ROUND(x) (floor(x+0.5))
94
95/** Macro to perform addition of two values within logarithm space \f$ \log{(e^x + e^y)} \f$ . */
96#define LOGPLUS(x,y) ( x>y ? x+log(1.+exp(y-x)) : y+log(1.+exp(x-y)) )
97
98/** Macro that gives the integer number of times that \c x goes in to \c y. */
99#define FACTOR(x,y) ((INT4)floor(x/y))
100
101/** Macro to square a value. */
102#define SQUARE(x) ( (x) * (x) )
103
104/**
105 * The maximum allowable length of the input data stream. Note: this may be
106 * removed in the future with memory allocated dynamically.
107 */
108#define MAXLENGTH 1000000
109
110/**
111 * The maximum line length (in characters) of a heterodyned data file.
112 */
113#define PPEN_MAXLINELENGTH 1024
114
115/* default values */
116/** Default value of the minimum length into which the data can be split. */
117#define CHUNKMIN 5
118/** Default value of the maximum length into which the data can be split. */
119#define CHUNKMAX 0
120
121/**
122 * Default number of bins in time (over one sidereal day) for the time vs.
123 * \f$ \psi \f$ antenna pattern lookup table.
124 */
125#define TIMEBINS 2880
126
127/**
128 * The total number of 'amplitude' parameters that can define a signal e.g. gravitational wave amplitude from a
129 * triaxial star emitting from the \f$ l=m=2 \f$ mode we have \f$ h_0 \f$ , initial phase of the signal \f$ \phi_0 \f$ ,
130 * polarisation angle \f$ psi \f$ , and cosine of the inclination angle \f$ \cos{\iota} \f$ . Or, more generally for
131 * emission from \f$ l=2 \f$ and \f$ m=1,2 \f$ instead of \f$ h_0 \f$ and \f$ \phi_0 \f$ there can be complex amplitude and
132 * phase parameters \f$ C_{22} \f$ , \f$ C_{21} \f$ , \f$ \phi_{22} \f$ and \f$ \phi_{21} \f$ .
133 *
134 * Note: These should be increased if additional model parameters are added.
135 */
136#define NUMAMPPARS 29
137
138/**
139 * The total number of sky position parameters that can define a signal e.g.
140 * right ascension, declination, proper motion, parallax and the positional epoch.
141 */
142#define NUMSKYPARS 6
143
144/**
145 * The total number of binary system parameters that can define a signal e.g.
146 * binary period, orbital eccentricity, projected semi-major axis, time of
147 * periastron and angle of periastron.
148 */
149#define NUMBINPARS 34
150
151/**
152 * The total number of glitch parameters that can define a signal
153 */
154#define NUMGLITCHPARS 7
155
156/** The maximum number of different detectors allowable. */
157#define MAXDETS 10
158
159/** The usage format for the code. */
160#define USAGE \
161"Usage: %s [options]\n\n"\
162" --help display this message\n"\
163" --verbose display all error messages\n"\
164" --detectors all IFOs with data to be analysed e.g. H1,H2\n\
165 (delimited by commas) (if generating fake data these\n\
166 should not be set)\n"\
167" --par-file pulsar parameter (.par) file (full path)\n"\
168" --cor-file pulsar TEMPO-fit parameter correlation matrix\n"\
169" --input-files full paths and file names for the data for each\n\
170 detector and model harmonic in the list (must be in the\n\
171 same order) delimited by commas. These files can be gzipped.\n\
172 If not set you can generate fake data (see --fake-data below)\n"\
173" --outfile name of output data file (a HDF5 formated file with the\n\
174 extension '.hdf' or '.h5' [required])\n"\
175" --output-chunks Output lists of stationary chunks into which the data has been split\n"\
176" --chunk-min (INT4) minimum stationary length of data to be used in\n\
177 the likelihood e.g. 5 mins\n"\
178" --chunk-max (INT4) maximum stationary length of data to be used in\n\
179 the likelihood e.g. 30 mins\n"\
180" --time-bins (INT4) no. of time bins in the time-psi lookup table\n"\
181" --prior-file file containing the parameters to search over and\n\
182 their upper and lower ranges\n"\
183" --ephem-earth Earth ephemeris file\n"\
184" --ephem-sun Sun ephemeris file\n"\
185" --ephem-timecorr Einstein delay time correction ephemeris file\n"\
186" --harmonics (CHAR) the signal model frequency harmonics that you want\n\
187 to use (delimited by commas). Currently this can be either\n\
188 the 'triaxial' model for which you use 2 (the default\n\
189 value) or 1,2 for a model with emission at both the rotation\n\
190 frequency and twice the rotation frequency.\n"\
191" --biaxial Set this if the waveform model parameters spcify a biaxial star\n"\
192" --gaussian-like Set this if a Gaussian likelihood is to be used. If the input\n\
193 file contains a column specifying the noise standard deviation of\n\
194 the data then that will be used in the Gaussian likelihood function,\n\
195 otherwise the noise variance will be calculated from the data.\n"\
196" --nonGR Set to allow non-GR polarisation modes and/or a variable\n\
197 speed of gravitational waves\n"\
198" --randomise Set this, with an INT seed, to randomise the data (through permutations\n\
199 of the time stamps) for use in Monte-Carlo studies. NOTE: this will not\n\
200 work if using the code to create injections\n"\
201" --start-time (REAL8) only use data after the given GPS start time\n"\
202" --end-time (REAL8) discard data after the given GPS end time\n"\
203" --truncate-time maximum GPS time to be analyzed (discards data with larger\n\
204 timestamp)\n"\
205" --truncate-samples maximum sample number to be analyzed (analyzes only first\n\
206 datapoints and discards rest)\n"\
207" --truncate-fraction fraction of data samples to be analyzed (0<f<=1)\n"\
208" --veto-threshold veto any data samples with an absolute value greater than the input\n\
209 threshold (defaults to 1e-18)\n"\
210"\n"\
211" Nested sampling parameters:\n"\
212" --Nlive (INT4) no. of live points for nested sampling\n"\
213" --Nmcmc (INT4) no. of for MCMC used to find new live points\n\
214 (if not specified an adaptive number of points is used)\n"\
215" --Nmcmcinitial (INT4) no. of MCMC points to use in the initial resampling of\n\
216 the prior (default is to use MAXMCMC)\n"\
217" --tolerance (REAL8) tolerance of nested sampling integrator\n"\
218" --randomseed seed for random number generator\n"\
219"\n"\
220" MCMC proposal parameters:\n"\
221" --diffev (UINT4) relative weight of using differential evolution\n\
222 of the live points as the proposal (DEFAULT = 0, e.g.\n\
223 0%%)\n"\
224" --freqBinJump (UINT4) relative weight of using jumps to adjacent\n\
225 frequency bins as a proposal (DEFAULT = 0, e.g. this is\n\
226 not required unless searching over frequency)\n"\
227" --ensembleStretch (UINT4) relative weight of the ensemble stretch\n\
228 proposal (DEFAULT = 0, e.g. 0%%) [NOTE: this proposal\n\
229 greatly increases the autocorrelation lengths, so in\n\
230 general should be avoided]\n"\
231" --ensembleWalk (UINT4) relative weight of the ensemble walk\n\
232 proposal (DEFAULT = 3, e.g. 75%%)\n"\
233" --uniformprop (UINT4) relative weights of uniform proposal\n\
234 (DEFAULT = 1, e.g. 25%%)\n"\
235"\n"\
236" Reduced order quadrature (ROQ) parameters:\n"\
237" --roq Set this to use reduced order quadrature to compute the\n\
238 likelihood\n"\
239" --ntraining (UINT4) The number of training models used to generate an\n\
240 orthonormal basis of waveform models\n"\
241" --roq-tolerance (REAL8) The tolerance used during the basis generation\n\
242 (DEFAULT = 1e-11)\n"\
243" --enrich-max (UINT4) The number of times to try and \"enrich\" the\n\
244 basis set using new training data. The enrichment process\n\
245 stop before this value is reached if three consecutive\n\
246 enrichment steps produce no new bases (DEFAULT = 100)\n"\
247" --roq-uniform Set this flag to cause training model parameters for\n\
248 parameters with Gaussian prior distributions to be drawn\n\
249 from a uniform distribution spanning mu +/- 5 sigma.\n\
250 Otherwise, by default parameters are drawn from their given\n\
251 prior distributions\n"\
252" --output-weights (CHAR) If this is set then the weights will be output to\n\
253 the (binary) file that is named and the programme will\n\
254 exit. These could be read in later instead of being\n\
255 regenerated. This allows the ROQ to be generated on a\n\
256 machine with a large amount of RAM, whilst the full\n\
257 parameter estimation can run on a machine with less RAM.\n"\
258" --input-weights (CHAR) A binary file containing all the weights in a\n\
259 defined format. If this is present then the RQO will\n\
260 not be recalculated\n"\
261"\n"\
262" Signal injection parameters:\n"\
263" --inject-file a pulsar parameter (par) file containing the parameters\n\
264 of a signal to be injected. If this is given a signal\n\
265 will be injected\n"\
266" --inject-output a filename to which the injected signal will be\n\
267 output if specified\n"\
268" --inject-only do not perform nested sampling on a created injection\n\
269 provided that injection has been output (i.e. exit the code\n\
270 after creation of and writing out of the injection).\n"\
271" --inject-coarse create an injected signal as if it has only been \"coarse\n\
272 heterodyned\", i.e., the orbital modulation effects have not\n\
273 been removed from the signal. This will only work when using\n\
274 the code to just create and output an injection with the\n\
275 \"--inject-only\" flag set.\n"\
276" --fake-data a list of IFO's for which fake data will be generated\n\
277 e.g. H1,L1 (delimited by commas). Unless the --fake-psd\n\
278 flag is set the power spectral density for the data will\n\
279 be generated from the noise models in LALNoiseModels.\n\
280 For Advanced detectors (e.g Advanced LIGO) prefix the\n\
281 name with an A (e.g. AH1 for an Advanced LIGO detector\n\
282 at Hanford). The noise will be white across the data\n\
283 band width\n"\
284" --fake-psd if you want to generate fake data with specific power\n\
285 spectral densities for each detector giving in\n\
286 --fake-data then they should be specified here delimited\n\
287 by commas (e.g. for --fake-data H1,L1 then you could use\n\
288 --fake-psd 1e-48,1.5e-48) where values are single-sided\n\
289 PSDs in Hz^-1\n"\
290" --fake-starts the start times (in GPS seconds) of the fake data for\n\
291 each detector separated by commas (e.g.\n\
292 910000000,910021000). If not specified these will all\n\
293 default to 900000000\n"\
294" --fake-lengths the length of each fake data set (in seconds) for each\n\
295 detector separated by commas. If not specified these\n\
296 will all default to 86400 (i.e. 1 day)\n"\
297" --fake-dt the data sample rate (in seconds) for the fake data for\n\
298 each detector. If not specified this will default to\n\
299 60s\n"\
300" --scale-snr give a (multi-detector) SNR value to which you want to\n\
301 scale the injection. This is 1 by default\n"\
302"\n"\
303" Flags for using a Nested sampling file as a prior (DO NOT USE!):\n"\
304" --sample-files a list of (comma separated) file containing the nested\n\
305 samples from a previous run of the code (these should\n\
306 contain samples in ascending likelihood order and be\n\
307 accompanied by a file containg a list of the parameter\n\
308 names for each column with the suffix _params.txt). If\n\
309 this is set this WILL be used as the only prior, but the\n\
310 prior ranges set in the --prior-file and --par-file are\n\
311 still needed (and should be consistent with the variable\n\
312 parameters in the nested sample file)\n"\
313" --sample-nlives a list (comma separated) of the number of live point\n\
314 that where used when creating each nested sample file.\n"\
315" --prior-cell The number of samples to use in a k-d tree cell for the\n\
316 prior (the default will be 8)\n"\
317" --Npost The (approximate) number of posterior samples to be\n\
318 generated from each nested sample file (default = 1000)\n"\
319"\n"\
320" Legacy code flags:\n"\
321" --oldChunks Set if using fixed chunk sizes for dividing the data as\n\
322 in the old code, rather than the calculating chunks\n\
323 using the change point method\n"\
324" --source-model Set if using both 1 and 2 multiples of the frequency and\n\
325 requiring the use of the original source model parameters\n\
326 from Jones, MNRAS, 402 (2010)\n"\
327"\n"\
328" Benchmarking:\n"\
329" --time-it Set if wanting to time the various parts of the code.\n\
330 A output file with the \"outfile\" filename appended with\n\
331 \"_timings\" will contain the timings\n"\
332" --sampleprior (UINT4) Set this to be a number of samples generated from\n\
333 the prior. The nested sampling will not be performed\n"\
334"\n"
335
336/**
337 * A list of the amplitude parameters. The names given here are those that are
338 * recognised within the code.
339 */
340static const CHAR amppars[NUMAMPPARS][VARNAME_MAX] = { "H0", "PHI0", "PSI",
341 "COSIOTA", "C22", "C21", "PHI22", "PHI21", "HPLUS", "HCROSS", "HSCALARB",
342 "HSCALARL", "HVECTORX", "HVECTORY", "PSIVECTOR", "PHI0VECTOR", "PSISCALAR",
343 "PHI0SCALAR", "PSITENSOR", "PHI0TENSOR", "I21", "I31", "LAMBDA", "COSTHETA",
344 "IOTA", "THETA", "Q22", "DIST", "H0_F"
345 };
346
347/**
348 * A list of the sky position parameters. The names given here are those that
349 * are recognised within the code.
350 */
351static const CHAR skypars[NUMSKYPARS][VARNAME_MAX] = { "RA", "PMRA", "DEC",
352 "PMDEC", "POSEPOCH", "PX"
353 };
354
355/**
356 * A list of the binary system parameters. The names given here are those that
357 * are recognised within the code.
358 */
359static const CHAR binpars[NUMBINPARS][VARNAME_MAX] = { "PB", "ECC", "EPS1",
360 "EPS2", "T0", "TASC", "A1", "OM", "PB_2", "ECC_2", "T0_2", "A1_2", "OM_2", "PB_3", "ECC_3",
361 "T0_3", "A1_3", "OM_3", "XPBDOT", "EPS1DOT", "EPS2DOT", "OMDOT", "GAMMA", "PBDOT",
362 "XDOT", "EDOT", "SINI", "DR", "DTHETA", "A0", "B0", "MTOT", "M2", "FB"
363 };
364
365/** A list of the glitch parameters. */
366static const CHAR glitchpars[NUMGLITCHPARS][VARNAME_MAX] = {"GLEP", "GLPH", "GLF0", "GLF1", "GLF2", "GLF0D", "GLTD"};
367
369
370#ifdef __cplusplus
371}
372#endif
373
374#endif /* _PULSAR_PARAMETER_ESTIMATION__NESTED_H */
char CHAR
#define VARNAME_MAX
#define NUMGLITCHPARS
The total number of glitch parameters that can define a signal.
#define NUMSKYPARS
The total number of sky position parameters that can define a signal e.g.
LALStringVector * corlist
static const CHAR binpars[NUMBINPARS][VARNAME_MAX]
A list of the binary system parameters.
#define NUMAMPPARS
The total number of 'amplitude' parameters that can define a signal e.g.
static const CHAR amppars[NUMAMPPARS][VARNAME_MAX]
A list of the amplitude parameters.
static const CHAR glitchpars[NUMGLITCHPARS][VARNAME_MAX]
A list of the glitch parameters.
#define NUMBINPARS
The total number of binary system parameters that can define a signal e.g.
static const CHAR skypars[NUMSKYPARS][VARNAME_MAX]
A list of the sky position parameters.