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_roq.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2015, 2016 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
24 *
25 * \brief Reduced order quadrature generation functions for use in parameter estimation
26 * codes for targeted pulsar searches.
27 */
28
29#include "config.h"
30#include "ppe_roq.h"
31#include "ppe_models.h"
32
33/******************************************************************************/
34/* REDUCED ORDER QUADRATURE FUNCTIONS */
35/******************************************************************************/
36
37/**
38 * \brief Generate Chebyshev-Gauss-Lobatto nodes in frequency
39 *
40 * @param[in] freqmin The minimum frequency
41 * @param[in] freqmax The maximum frequency
42 * @param[in] nnodes The number of nodes
43 *
44 * @return An array with the node freqeuncy values
45 */
47{
48 UINT4 i = 0;
49 REAL8 *fnodes = NULL;
50 REAL8 df, fplus, n;
51
52 XLAL_CHECK_NULL( fnodes = XLALMalloc( nnodes * sizeof( REAL8 ) ), XLAL_EFUNC, "Couldn't allocate memory for frequency nodes." );
53
54 df = ( freqmax - freqmin ) / 2.;
55 fplus = ( freqmax + freqmin ) / 2.;
56 n = ( REAL8 )nnodes - 1.;
57
58 for ( i = 0; i < nnodes; i++ ) {
59 fnodes[i] = -cos( LAL_PI * ( REAL8 )i / n ) * df + fplus;
60 }
61
62 return fnodes;
63}
64
65
66/**
67 * \brief Generate an orthonormal basis set of waveforms from a training set
68 *
69 * This function will use the prior ranges on the parameters to generate a set of
70 * training waveforms. From these training waveforms it will generate a set of
71 * orthonormal basis functions, with the number generated controlled by a stopping
72 * tolerance criterion. In general the values of the parameters for the training set
73 * will be drawn randomly from across the prior ranges. However, ff frequency is one
74 * of the parameters being used then values will be placed the the Chebyshev-Gauss-Lobatto
75 * nodes.
76 *
77 * This basis set will be generated seperately for the real and imaginary parts of
78 * the model.
79 *
80 * @param[in] runState The algorithm run state
81 */
83{
84 REAL8 tolerance = ROQTOLERANCE;
85 UINT4 ntraining = 0, nenrichmax = 100, verbose = 0, outputroq = 0, inputroq = 0, nconsec = 3;
86 UINT4 counter = 0, i = 0, j = 0, conseccount = 0;
87 INT4 gaussianLike = 0;
88 ProcessParamsTable *ppt;
89
90 /* variables if reading in weights file */
91 UINT4 nstreams = 0, nchunks = 0;
92 FILE *fpin = NULL, *fpout = NULL;
93
95 LALInferenceIFOData *data = runState->data;
96
97 /* timing values */
98 struct timeval time1, time2;
99 REAL8 tottime;
100 UINT4 nquadtot = 0, nlineartot = 0, ndatatot = 0;
101
102 if ( LALInferenceCheckVariable( runState->algorithmParams, "timefile" ) ) {
103 gettimeofday( &time1, NULL );
104 }
105
106 /* check whether to use ROQ */
107 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--roq" );
108 if ( !ppt ) {
109 return;
110 }
111
112 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--input-weights" );
113 if ( !ppt ) {
114 /* get tolerance stopping criterion */
115 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--roq-tolerance" );
116 if ( ppt ) {
117 tolerance = atof( ppt->value );
118 }
119 XLAL_CHECK_VOID( tolerance < 1. && tolerance > 0., XLAL_EFUNC, "ROQ tolerence (%le) is not within allowed range.", tolerance );
120
121 /* get number of training sets */
122 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--ntraining" );
123 if ( ppt ) {
124 ntraining = atoi( ppt->value );
125 } else {
126 XLAL_ERROR_VOID( XLAL_EFUNC, "Number of training sets must be specifed if running with --roq" );
127 }
128 XLAL_CHECK_VOID( ntraining > 1, XLAL_EFUNC, "Number of training sets (%d) is too small!", ntraining );
129
130 /* check whether to output weights */
131 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--output-weights" );
132 if ( ppt ) {
133 CHAR *outputweights = ppt->value;
134 XLAL_CHECK_VOID( ( fpout = fopen( outputweights, "wb" ) ) != NULL, XLAL_EIO, "Could not open weights file for output." );
135 outputroq = 1;
136
137 /* write out the number of data streams */
138 nstreams = *( UINT4 * )LALInferenceGetVariable( runState->algorithmParams, "numstreams" );
139 XLAL_CHECK_VOID( fwrite( &nstreams, sizeof( UINT4 ), 1, fpout ) == 1, XLAL_EIO, "Could not write the number of data steams to file!" );
140 }
141
142 /* check if a maximum number of enrichment steps is set */
143 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--enrich-max" );
144 if ( ppt ) {
145 nenrichmax = atoi( ppt->value );
146 }
147 } else {
148 /* read in weights from a file */
149 CHAR *inputweights = ppt->value;
150 UINT4 nstreamcheck = *( UINT4 * )LALInferenceGetVariable( runState->algorithmParams, "numstreams" );
151
152 XLAL_CHECK_VOID( ( fpin = fopen( inputweights, "rb" ) ) != NULL, XLAL_EIO, "Could not open weights file for reading." );
153
154 /* read in the first bit of information, which is the number of datastreams as an UINT4 */
155 XLAL_CHECK_VOID( fread( ( void * )&nstreams, sizeof( UINT4 ), 1, fpin ) == 1, XLAL_EIO, "Could not read in first value from weights file\n" );
156 XLAL_CHECK_VOID( nstreams == nstreamcheck, XLAL_EFUNC, "Number of data streams inconsistent with ROQ weights file" );
157
158 inputroq = 1;
159 }
160
161 ppt = LALInferenceGetProcParamVal( runState->commandLine, "--verbose" );
162 if ( ppt ) {
163 verbose = 1;
164 }
165
166 /* check if using a Gaussian likelihoodm and therefore need variance weighted ROQ values */
167 if ( LALInferenceGetProcParamVal( runState->commandLine, "--gaussian-like" ) ) {
168 gaussianLike = 1;
169 }
170
171 ifo = runState->threads[0].model->ifo;
172
173 /* we need to get the frequency factors */
174 REAL8Vector *freqFactors = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "freqfactors" );
175 UINT4 nfreqs = freqFactors->length;
176 REAL8Vector *freqsCopy = XLALCreateREAL8Vector( nfreqs );
177 memcpy( freqsCopy->data, freqFactors->data, sizeof( REAL8 )*nfreqs );
178
179 while ( ifo ) {
180 UINT4Vector *chunkLengths = *( UINT4Vector ** )LALInferenceGetVariable( ifo->params, "chunkLength" );
181 REAL8 dt = *( REAL8 * )LALInferenceGetVariable( ifo->params, "dt" );
182 INT4 startidx = 0;
183
184 UINT4 dlen = 0;
185 UINT4Vector *nbases = XLALCreateUINT4Vector( chunkLengths->length );
186 UINT4Vector *nbasesquad = XLALCreateUINT4Vector( chunkLengths->length );
187
188 /* vectors to hold the vector and matrices with the interpolation weights */
189 COMPLEX16 *dmweights = NULL;
190 REAL8 *mmweights = NULL;
191 UINT4 dmlength = 0, mmlength = 0;
192
193 /* create a copy of the model vector */
194 LIGOTimeGPS gpstime = {0, 0};
195 REAL8Vector *sidDayFrac = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "siderealDay" );
196 REAL8Vector *ssbdelays = NULL, *bsbdelays = NULL, *glitchphase = NULL;
197
198 LIGOTimeGPSVector *timenodes = NULL;
199 REAL8Vector *sidtimenodes = NULL;
200 REAL8Vector *ssbnodes = NULL, *bsbnodes = NULL, *gpnodes = NULL;
201
202 data->roq = XLALMalloc( sizeof( LALInferenceROQData ) );
203
204 ssbdelays = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "ssb_delays" );
205 if ( LALInferenceCheckVariable( ifo->params, "bsb_delays" ) ) {
206 bsbdelays = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "bsb_delays" );
207 }
208 if ( LALInferenceCheckVariable( ifo->params, "glitch_phase" ) ) {
209 glitchphase = *( REAL8Vector ** )LALInferenceGetVariable( ifo->params, "glitch_phase" );
210 }
211
212 if ( inputroq ) {
213 /* we assume that the data has been split into the same number and length chunks as in that
214 * used to calculate the weights, but the second value(s) will be the number of chunks,
215 * for the given stream, which can be checked */
216 XLAL_CHECK_VOID( fread( ( void * )&nchunks, sizeof( UINT4 ), 1, fpin ) == 1, XLAL_EIO, "Could not read chunk numbers from weights file\n" );
217 XLAL_CHECK_VOID( nchunks == chunkLengths->length, XLAL_EFUNC, "Number of chunks is not consistent!" );
218 }
219
220 if ( outputroq ) {
221 XLAL_CHECK_VOID( fwrite( &chunkLengths->length, sizeof( UINT4 ), 1, fpout ) == 1, XLAL_EIO, "Could not write number of chunks!" );
222 }
223
224 /* as we only use one datastream at a time (e.g. one frequency time series) we need to set the
225 * freqFactor to just contain that one frequency */
226 REAL8Vector *freqsTemp = XLALCreateREAL8Vector( 1 );
227 freqsTemp->data[0] = freqsCopy->data[counter % nfreqs];
228 check_and_add_fixed_variable( ifo->params, "freqfactors", &freqsTemp, LALINFERENCE_REAL8Vector_t );
229
230 /* get chunk */
231 for ( i = 0; i < chunkLengths->length; i++ ) {
232 UINT4 tlen = chunkLengths->data[i], enrichcounts = 0, nbases0 = 0, nbases0quad = 0;
234 LALInferenceREALROQInterpolant *interpquad = NULL;
235
236 if ( !inputroq ) {
237 COMPLEX16Array *ts = NULL; /* training set for linear part of interpolant */
238 REAL8Array *tsquad = NULL; /* training set for quadratic part of interpolant */
239 REAL8 maxprojerr = 0.;
240
241 /* a temporary run state containing just the required data for a single detector */
244 ifotmp->extraData = XLALCalloc( 1, sizeof( IFOModelExtraData ) );
245 ifotmp->next = NULL;
246 tmpRS->threads = LALInferenceInitThreads( 1 );
247 tmpRS->threads[0].model = XLALMalloc( sizeof( LALInferenceModel ) );
248 tmpRS->threads[0].model->templt = runState->threads[0].model->templt;
249 LALInferenceClearVariables( tmpRS->threads[0].currentParams ); /* free memory as LALInferenceInitThreads already has allocated memory */
250 tmpRS->threads[0].currentParams = runState->threads[0].currentParams;
251 tmpRS->threads[0].model->ifo = ifotmp;
252 tmpRS->GSLrandom = runState->GSLrandom;
253 tmpRS->priorArgs = runState->priorArgs;
254 tmpRS->prior = runState->prior;
255 tmpRS->commandLine = runState->commandLine;
256
257 IFO_XTRA_DATA( ifotmp )->times = XLALCreateTimestampVector( tlen );
258 /* create a new model vector */
259 ifotmp->compTimeSignal = XLALCreateCOMPLEX16TimeSeries( "", &gpstime, 0., 1., &lalSecondUnit, tlen );
260
261 ifotmp->params = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
262 LALInferenceCopyVariables( ifo->params, ifotmp->params ); /* copy parameters */
263 IFO_XTRA_DATA( ifotmp )->ephem = IFO_XTRA_DATA( ifo )->ephem;
264 ifotmp->detector = ifo->detector;
265 IFO_XTRA_DATA( ifotmp )->tdat = IFO_XTRA_DATA( ifo )->tdat;
266 IFO_XTRA_DATA( ifotmp )->ttype = IFO_XTRA_DATA( ifo )->ttype;
267
268 REAL8Vector *thissiddayfrac = NULL;
269 thissiddayfrac = XLALCreateREAL8Vector( tlen );
270 LALInferenceRemoveVariable( ifotmp->params, "siderealDay" );
271
272 REAL8Vector *thisssbdelay = NULL;
273 thisssbdelay = XLALCreateREAL8Vector( tlen );
274 LALInferenceRemoveVariable( ifotmp->params, "ssb_delays" );
275
276 REAL8Vector *thisbsbdelay = NULL;
277 if ( bsbdelays != NULL ) {
278 thisbsbdelay = XLALCreateREAL8Vector( tlen );
279 LALInferenceRemoveVariable( ifotmp->params, "bsb_delays" );
280 }
281
282 REAL8Vector *thisglitchphase = NULL;
283 if ( glitchphase != NULL ) {
284 thisglitchphase = XLALCreateREAL8Vector( tlen );
285 LALInferenceRemoveVariable( ifotmp->params, "glitch_phase" );
286 }
287
288 /* get chunk times */
289 for ( j = 0; j < tlen; j++ ) {
290 IFO_XTRA_DATA( ifotmp )->times->data[j] = IFO_XTRA_DATA( ifo )->times->data[startidx + j];
291 thissiddayfrac->data[j] = sidDayFrac->data[startidx + j];
292 thisssbdelay->data[j] = ssbdelays->data[startidx + j];
293 if ( bsbdelays != NULL ) {
294 thisbsbdelay->data[j] = bsbdelays->data[startidx + j];
295 }
296 if ( glitchphase != NULL ) {
297 thisglitchphase->data[j] = glitchphase->data[startidx + j];
298 }
299 }
300
301 LALInferenceAddVariable( ifotmp->params, "siderealDay", &thissiddayfrac, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
303 if ( bsbdelays != NULL ) {
305 }
306 if ( glitchphase != NULL ) {
307 LALInferenceAddVariable( ifotmp->params, "glitch_phase", &thisglitchphase, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
308 }
309
310 REAL8Vector *deltas = XLALCreateREAL8Vector( 1 );
311 deltas->data[0] = dt;
312
313 if ( verbose ) {
314 fprintf( stderr, "Data chunk no. %d of %d (length: %d)\n", i + 1, chunkLengths->length, tlen );
315 }
316
317 /* GENERATE TRAINING SET FOR PART OF ROQ THAT IS LINEAR WRT THE MODEL <d|h> */
318 ts = generate_training_set( tmpRS, ntraining ); /* generate the training set */
319
320 COMPLEX16Array *RB = NULL; /* the reduced basis */
321 UINT4Vector *greedypts = NULL; /* the points in the training set used to produce the reduced basis */
322 maxprojerr = LALInferenceGenerateCOMPLEX16OrthonormalBasis( &RB, deltas, tolerance, &ts, &greedypts ); /* generate reduced basis */
323 XLAL_CHECK_VOID( RB != NULL, XLAL_EFUNC, "Could not produce linear basis set" );
324 nbases->data[i] = RB->dimLength->data[0];
325
326 /* iterate over enrichment steps */
327 if ( nenrichmax > 0 && nbases->data[i] < tlen ) {
328 enrichcounts = 0;
329 conseccount = 0; /* counter for number of consecutive enrichments that add no new bases */
330 if ( verbose ) {
331 fprintf( stderr, "Enriching linear basis (no. bases): %d", nbases->data[i] );
332 }
333
334 do {
335 /* create a new training set to try and "enrich" the original one */
336 COMPLEX16Array *tsenrich = NULL;
337 REAL8 newmaxprojerr = maxprojerr;
338 tsenrich = generate_training_set( tmpRS, ntraining );
339
340 newmaxprojerr = LALInferenceEnrichCOMPLEX16Basis( deltas, tolerance, &RB, &greedypts, ts, &tsenrich ); /* regenerate reduced basis */
341 if ( newmaxprojerr != 0. ) {
342 maxprojerr = newmaxprojerr; // update only if a new reduced basis has been generated
343 }
344
345 /* check if no new bases have been added */
346 if ( nbases->data[i] == RB->dimLength->data[0] ) {
347 /* check if LALInferenceGenerateCOMPLEX16OrthonormalBasis exited before reaching the required tolerance */
348 if ( maxprojerr < tolerance ) {
349 conseccount++;
350 }
351 } else {
352 conseccount = 0;
353 }
354
355 nbases->data[i] = RB->dimLength->data[0];
356
357 /* check if there are more bases than actual data points */
358 if ( nbases->data[i] >= tlen ) {
359 XLALDestroyCOMPLEX16Array( tsenrich );
360 nbases->data[i] = tlen;
361 break;
362 }
363
364 if ( verbose ) {
365 fprintf( stderr, "...%d", nbases->data[i] );
366 }
367
368 // copy tsenrich into ts (as this is the new enriched training set from which the reduced basis was calculated)
369 if ( nbases->data[i] != RB->dimLength->data[0] ) {
371 UINT4Vector *dimstmp = NULL;
372 dimstmp = XLALCreateUINT4Vector( 2 );
373 dimstmp->data[0] = tsenrich->dimLength->data[0];
374 dimstmp->data[1] = tsenrich->dimLength->data[1];
375 ts = XLALCreateCOMPLEX16Array( dimstmp );
376 for ( UINT4 didx = 0; didx < ( dimstmp->data[0]*dimstmp->data[1] ); didx++ ) {
377 ts->data[didx] = tsenrich->data[didx];
378 }
379 XLALDestroyUINT4Vector( dimstmp );
380 }
381
382 XLALDestroyCOMPLEX16Array( tsenrich );
383 enrichcounts++;
384 } while ( enrichcounts < nenrichmax && conseccount < nconsec );
385 if ( verbose ) {
386 fprintf( stderr, "\n" );
387 }
388 }
389
390 XLALDestroyUINT4Vector( greedypts );
392
393 if ( verbose ) {
394 fprintf( stderr, "Number of linear reduced bases for ROQ generation is %d, with a maximum projection error of %le\n", nbases->data[i], maxprojerr );
395 }
396
397 nbases0 = nbases->data[i];
398 nlineartot += nbases0;
399
400 /* generate the interpolants (pass the data noise variances for weighting the interpolants in the case of using a Gaussian likelihood) */
401 if ( nbases0 <= tlen - 1 ) {
403 } else {
404 /* if the number of bases is greater than the length just use all the data points in a chunk */
405 interp = XLALMalloc( sizeof( LALInferenceCOMPLEXROQInterpolant ) );
406 interp->B = NULL;
407 interp->nodes = XLALMalloc( sizeof( UINT4 ) * tlen );
408
409 for ( j = 0; j < tlen; j++ ) {
410 interp->nodes[j] = ( UINT4 )j;
411 }
412 }
413
414 /* free the reduced basis set and training set */
416
417 /* GENERATE TRAINING SET FOR PART OF ROQ THAT IS QUADRATIC WRT THE MODEL <h|h> */
418 tsquad = generate_training_set_quad( tmpRS, ntraining ); /* generate the training set */
419
420 REAL8Array *RBquad = NULL; /* the reduced basis */
421 greedypts = NULL;
422 maxprojerr = LALInferenceGenerateREAL8OrthonormalBasis( &RBquad, deltas, tolerance, &tsquad, &greedypts ); /* generate reduced basis */
423 XLAL_CHECK_VOID( RBquad != NULL, XLAL_EFUNC, "Could not produce quadratic basis set" );
424 nbasesquad->data[i] = RBquad->dimLength->data[0];
425
426 /* iterate over enrichment steps */
427 if ( nenrichmax > 0 && nbasesquad->data[i] < tlen ) {
428 enrichcounts = 0;
429 conseccount = 0; /* counter for number of consecutive enrichments that add no new bases */
430
431 if ( verbose ) {
432 fprintf( stderr, "Enriching quadratic basis (no. bases): %d", nbasesquad->data[i] );
433 }
434 do {
435 /* create a new training set to try and "enrich" the original one */
436 REAL8Array *tsenrich = NULL;
437 REAL8 newmaxprojerr = maxprojerr;
438 tsenrich = generate_training_set_quad( tmpRS, ntraining );
439
440 newmaxprojerr = LALInferenceEnrichREAL8Basis( deltas, tolerance, &RBquad, &greedypts, tsquad, &tsenrich ); /* regenerate reduced basis */
441 if ( newmaxprojerr != 0. ) {
442 maxprojerr = newmaxprojerr; // update only if a new reduced basis has been generated
443 }
444
445 /* check if no new bases have been added */
446 if ( nbasesquad->data[i] == RBquad->dimLength->data[0] ) {
447 /* check if LALInferenceGenerateREAL8OrthonormalBasis exited before reaching the required tolerance */
448 if ( maxprojerr < tolerance ) {
449 conseccount++;
450 }
451 } else {
452 conseccount = 0;
453 }
454
455 nbasesquad->data[i] = RBquad->dimLength->data[0];
456
457 /* check if there are more bases than actual data points */
458 if ( nbasesquad->data[i] >= tlen ) {
459 XLALDestroyREAL8Array( tsenrich );
460 nbasesquad->data[i] = tlen;
461 break;
462 }
463
464 // copy tsenrich into tsquad (as this is the new enriched training set from which the reduced basis was calculated)
465 if ( nbasesquad->data[i] != RBquad->dimLength->data[0] ) {
466 XLALDestroyREAL8Array( tsquad );
467 UINT4Vector *dimstmp = NULL;
468 dimstmp = XLALCreateUINT4Vector( 2 );
469 dimstmp->data[0] = tsenrich->dimLength->data[0];
470 dimstmp->data[1] = tsenrich->dimLength->data[1];
471 tsquad = XLALCreateREAL8Array( dimstmp );
472 for ( UINT4 didx = 0; didx < ( dimstmp->data[0]*dimstmp->data[1] ); didx++ ) {
473 tsquad->data[didx] = tsenrich->data[didx];
474 }
475 XLALDestroyUINT4Vector( dimstmp );
476 }
477
478 if ( verbose ) {
479 fprintf( stderr, "...%d", nbasesquad->data[i] );
480 }
481 XLALDestroyREAL8Array( tsenrich );
482 enrichcounts++;
483 } while ( enrichcounts < nenrichmax && conseccount < nconsec );
484 if ( verbose ) {
485 fprintf( stderr, "\n" );
486 }
487 }
488
489 XLALDestroyUINT4Vector( greedypts );
490 XLALDestroyREAL8Array( tsquad );
491
492 if ( verbose ) {
493 fprintf( stderr, "Number of quadratic reduced bases for ROQ generation is %d, with a maximum projection error of %le\n", nbasesquad->data[i], maxprojerr );
494 }
495
496 nbases0quad = nbasesquad->data[i];
497 nquadtot += nbases0quad;
498
499 /* generate the interpolants (pass the data noise variances for weighting the interpolants in the case of using a Gaussian likelihood) */
500 if ( nbases0quad <= tlen - 1 ) {
501 interpquad = LALInferenceGenerateREALROQInterpolant( RBquad );
502 } else {
503 /* if the number of bases is greater than the length just use all the data points in a chunk */
504 interpquad = XLALMalloc( sizeof( LALInferenceREALROQInterpolant ) );
505 interpquad->B = NULL;
506 interpquad->nodes = XLALMalloc( sizeof( UINT4 ) * tlen );
507
508 for ( j = 0; j < tlen; j++ ) {
509 interpquad->nodes[j] = ( UINT4 )j;
510 }
511 }
512
513 /* free the reduced basis set and training set */
514 XLALDestroyREAL8Array( RBquad );
515
516 XLALDestroyREAL8Vector( deltas );
517 XLALDestroyTimestampVector( IFO_XTRA_DATA( ifotmp )->times );
520 XLALFree( tmpRS->threads[0].model );
521 XLALFree( tmpRS->threads );
522 XLALFree( tmpRS );
523
524 /* get view of data and variance */
525 REAL8Vector vari, *varist = NULL;
526 COMPLEX16Vector datasub;
527
528 /* point to section of data */
529 datasub.data = &data->compTimeData->data->data[startidx];
530 datasub.length = tlen;
531
532 if ( gaussianLike ) {
533 /* point to section of variance required */
534 vari.data = &data->varTimeData->data->data[startidx];
535 vari.length = tlen;
536 } else {
537 varist = XLALCreateREAL8Vector( 1 );
538 varist->data[0] = 1.; /* using Students-t likelihood, so just set to 1 */
539 }
540
541 /* create the data/model and model/model inner product weights */
542 COMPLEX16Vector *dmw = NULL;
543 REAL8Vector *mmw = NULL;
544 if ( nbases0 <= tlen - 1 ) {
545 if ( gaussianLike ) {
546 dmw = LALInferenceGenerateCOMPLEX16LinearWeights( interp->B, &datasub, &vari );
547 } else {
548 dmw = LALInferenceGenerateCOMPLEX16LinearWeights( interp->B, &datasub, varist );
549 }
550 } else {
551 /* if the number of bases is longer than the data then fill in the data-model weights with just the data */
552 dmw = XLALCreateCOMPLEX16Vector( tlen );
553
554 for ( j = 0; j < tlen; j++ ) {
555 if ( gaussianLike ) {
556 dmw->data[j] = datasub.data[j] / vari.data[j];
557 } else {
558 dmw->data[j] = datasub.data[j] / varist->data[0];
559 }
560 }
561 }
562
563 if ( nbases0quad <= tlen - 1 ) {
564 if ( gaussianLike ) {
565 mmw = LALInferenceGenerateQuadraticWeights( interpquad->B, &vari );
566 } else {
567 mmw = LALInferenceGenerateQuadraticWeights( interpquad->B, varist );
568 }
569 } else {
570 /* if the number of bases is longer than the data then fill the model-model weights filled with one over the variances */
571 mmw = XLALCreateREAL8Vector( tlen );
572
573 for ( j = 0; j < tlen; j++ ) {
574 if ( gaussianLike ) {
575 mmw->data[j] = 1. / vari.data[j];
576 } else {
577 mmw->data[j] = 1. / varist->data[0];
578 }
579 }
580 }
581
582 if ( !gaussianLike ) {
583 XLALDestroyREAL8Vector( varist );
584 }
585
586 /* put weights into a vector */
587 mmlength += nbases0quad;
588 dmlength += nbases0;
589
590 dmweights = XLALRealloc( dmweights, sizeof( COMPLEX16 ) * dmlength );
591 mmweights = XLALRealloc( mmweights, sizeof( REAL8 ) * mmlength );
592
593 memcpy( &dmweights[dmlength - nbases0], dmw->data, sizeof( COMPLEX16 )*nbases0 );
594 memcpy( &mmweights[mmlength - nbases0quad], mmw->data, sizeof( REAL8 )*nbases0quad );
595
596 /* output the node indices */
597 if ( outputroq ) {
598 XLAL_CHECK_VOID( fwrite( &nbases0, sizeof( UINT4 ), 1, fpout ) == 1, XLAL_EIO, "Could not output number of linear nodes to file." );
599 XLAL_CHECK_VOID( fwrite( &interp->nodes[0], sizeof( UINT4 ), nbases0, fpout ) == nbases0, XLAL_EIO, "Could not output linear interpolation node indices." );
600 XLAL_CHECK_VOID( fwrite( &nbases0quad, sizeof( UINT4 ), 1, fpout ) == 1, XLAL_EIO, "Could not output number of quadratic nodes to file." );
601 XLAL_CHECK_VOID( fwrite( &interpquad->nodes[0], sizeof( UINT4 ), nbases0quad, fpout ) == nbases0quad, XLAL_EIO, "Could not output quadratic interpolation node indices." );
602 }
603
606 } else { /* reading in previously computed interpolant nodes */
607 interp = XLALMalloc( sizeof( LALInferenceCOMPLEXROQInterpolant ) );
608 interp->B = NULL;
609
610 /* read in the number of linear interpolant nodes for the current chunk and then the node indices */
611 XLAL_CHECK_VOID( fread( ( void * )&nbases0, sizeof( UINT4 ), 1, fpin ) == 1, XLAL_EIO, "Could not read number of linear nodes" );
612
613 if ( verbose ) {
614 fprintf( stderr, "Number of linear reduced bases for ROQ generation is %d\n", nbases0 );
615 }
616
617 /* read in the number of nodes for this chunk */
618 interp->nodes = XLALMalloc( nbases0 * sizeof( UINT4 ) );
619 XLAL_CHECK_VOID( fread( ( void * )interp->nodes, sizeof( UINT4 ), nbases0, fpin ) == nbases0, XLAL_EIO, "Could not read in linear interpolation indices" );
620 nbases->data[i] = nbases0;
621 dmlength += nbases0;
622 nlineartot += nbases0;
623
624 interpquad = XLALMalloc( sizeof( LALInferenceREALROQInterpolant ) );
625 interpquad->B = NULL;
626
627 /* read in the number of quadratic interpolant nodes for the current chunk and then the node indices */
628 XLAL_CHECK_VOID( fread( ( void * )&nbases0quad, sizeof( UINT4 ), 1, fpin ) == 1, XLAL_EIO, "Could not read number of linear nodes" );
629
630 if ( verbose ) {
631 fprintf( stderr, "Number of quadratic reduced bases for ROQ generation is %d\n", nbases0quad );
632 }
633
634 /* read in the number of nodes for this chunk */
635 interpquad->nodes = XLALMalloc( nbases0quad * sizeof( UINT4 ) );
636 XLAL_CHECK_VOID( fread( ( void * )interpquad->nodes, sizeof( UINT4 ), nbases0quad, fpin ) == nbases0quad, XLAL_EIO, "Could not read in quadratic interpolation indices" );
637 nbasesquad->data[i] = nbases0quad;
638 mmlength += nbases0quad;
639 nquadtot += nbases0quad;
640 }
641
642 /* create vectors of time stamps at the nodes, the vector holds a "linear" set of nodes and then a "quadratic" set of nodes */
643 /* add times at the linear interpolation nodes */
644 UINT4 tnlength = 0;
645 if ( !timenodes ) {
646 tnlength = nbases0;
647 } else {
648 tnlength = timenodes->length + nbases0;
649 }
650
651 timenodes = XLALResizeTimestampVector( timenodes, tnlength );
652 sidtimenodes = XLALResizeREAL8Vector( sidtimenodes, tnlength );
653 ssbnodes = XLALResizeREAL8Vector( ssbnodes, tnlength );
654 if ( bsbdelays != NULL ) {
655 bsbnodes = XLALResizeREAL8Vector( bsbnodes, tnlength );
656 }
657 if ( glitchphase != NULL ) {
658 gpnodes = XLALResizeREAL8Vector( gpnodes, tnlength );
659 }
660
661 for ( j = 0; j < nbases0; j++ ) {
662 timenodes->data[dlen + j] = IFO_XTRA_DATA( ifo )->times->data[startidx + interp->nodes[j]];
663 sidtimenodes->data[dlen + j] = sidDayFrac->data[startidx + interp->nodes[j]];
664 ssbnodes->data[dlen + j] = ssbdelays->data[startidx + interp->nodes[j]];
665 if ( bsbdelays != NULL ) {
666 bsbnodes->data[dlen + j] = bsbdelays->data[startidx + interp->nodes[j]];
667 }
668 if ( glitchphase != NULL ) {
669 gpnodes->data[dlen + j] = glitchphase->data[startidx + interp->nodes[j]];
670 }
671 }
672
673 dlen += nbases0;
674 tnlength = timenodes->length + nbases0quad;
675
676 /* get times at the quadratic interpolation nodes */
677 timenodes = XLALResizeTimestampVector( timenodes, tnlength );
678 sidtimenodes = XLALResizeREAL8Vector( sidtimenodes, tnlength );
679
680 ssbnodes = XLALResizeREAL8Vector( ssbnodes, tnlength );
681 if ( bsbdelays != NULL ) {
682 bsbnodes = XLALResizeREAL8Vector( bsbnodes, tnlength );
683 }
684 if ( glitchphase != NULL ) {
685 gpnodes = XLALResizeREAL8Vector( gpnodes, tnlength );
686 }
687
688 for ( j = 0; j < nbases0quad; j++ ) {
689 timenodes->data[dlen + j] = IFO_XTRA_DATA( ifo )->times->data[startidx + interpquad->nodes[j]];
690 sidtimenodes->data[dlen + j] = sidDayFrac->data[startidx + interpquad->nodes[j]];
691 ssbnodes->data[dlen + j] = ssbdelays->data[startidx + interpquad->nodes[j]];
692 if ( bsbdelays != NULL ) {
693 bsbnodes->data[dlen + j] = bsbdelays->data[startidx + interpquad->nodes[j]];
694 }
695 if ( glitchphase != NULL ) {
696 gpnodes->data[dlen + j] = glitchphase->data[startidx + interpquad->nodes[j]];
697 }
698 }
699
702
703 startidx += tlen;
704 dlen += nbases0quad;
705 }
706
707 ndatatot += IFO_XTRA_DATA( ifo )->times->length;
708
709 /* resize time vectors and model vectors, so they just contain values at the interpolation nodes */
710 LIGOTimeGPSVector *timescopy = XLALCreateTimestampVector( IFO_XTRA_DATA( ifo )->times->length );
711 memcpy( timescopy->data, IFO_XTRA_DATA( ifo )->times->data, sizeof( LIGOTimeGPS )*IFO_XTRA_DATA( ifo )->times->length );
712 LALInferenceAddVariable( ifo->params, "timeStampVectorFull", &timescopy, LALINFERENCE_void_ptr_t, LALINFERENCE_PARAM_FIXED );
714 IFO_XTRA_DATA( ifo )->times = timenodes;
715
716 /* make a copy of the original sidereal time vectors and time stamp vectors - this is needed when calculating the SNR of the maximum likelihood point */
717 REAL8Vector *siddaycopy = XLALCreateREAL8Vector( sidDayFrac->length );
718 memcpy( siddaycopy->data, sidDayFrac->data, sizeof( REAL8 )*sidDayFrac->length );
719 LALInferenceRemoveVariable( ifo->params, "siderealDay" );
720 LALInferenceAddVariable( ifo->params, "siderealDay", &sidtimenodes, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
721 LALInferenceAddVariable( ifo->params, "siderealDayFull", &siddaycopy, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
722
723 REAL8Vector *ssbcopy = XLALCreateREAL8Vector( ssbdelays->length );
724 memcpy( ssbcopy->data, ssbdelays->data, sizeof( REAL8 )*ssbdelays->length );
725 LALInferenceRemoveVariable( ifo->params, "ssb_delays" );
727 LALInferenceAddVariable( ifo->params, "ssb_delays_full", &ssbcopy, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
728
729 if ( bsbdelays != NULL ) {
730 REAL8Vector *bsbcopy = XLALCreateREAL8Vector( bsbdelays->length );
731 memcpy( bsbcopy->data, bsbdelays->data, sizeof( REAL8 )*bsbdelays->length );
732 LALInferenceRemoveVariable( ifo->params, "bsb_delays" );
734 LALInferenceAddVariable( ifo->params, "bsb_delays_full", &bsbcopy, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
735 }
736
737 if ( glitchphase != NULL ) {
738 REAL8Vector *glitchphasecopy = XLALCreateREAL8Vector( glitchphase->length );
739 memcpy( glitchphasecopy->data, glitchphase->data, sizeof( REAL8 )*glitchphase->length );
740 LALInferenceRemoveVariable( ifo->params, "glitch_phase" );
742 LALInferenceAddVariable( ifo->params, "glitch_phase_full", &glitchphasecopy, LALINFERENCE_REAL8Vector_t, LALINFERENCE_PARAM_FIXED );
743 }
744
745 ifo->compTimeSignal = XLALResizeCOMPLEX16TimeSeries( ifo->compTimeSignal, 0, dmlength + mmlength );
746
747 if ( inputroq ) {
748 /* now read in all the weights */
749 dmweights = XLALMalloc( sizeof( COMPLEX16 ) * dmlength );
750 XLAL_CHECK_VOID( fread( ( void * )dmweights, sizeof( COMPLEX16 ), dmlength, fpin ) == dmlength, XLAL_EIO, "Could not read in data-model product weights" );
751
752 mmweights = XLALMalloc( sizeof( REAL8 ) * mmlength );
753 XLAL_CHECK_VOID( fread( ( void * )mmweights, sizeof( REAL8 ), mmlength, fpin ) == mmlength, XLAL_EIO, "Could not read in model-model product weights" );
754 }
755
756 if ( outputroq ) {
757 XLAL_CHECK_VOID( fwrite( dmweights, sizeof( COMPLEX16 ), dmlength, fpout ) == dmlength, XLAL_EIO, "Could not output data-model product weights" );
758 XLAL_CHECK_VOID( fwrite( mmweights, sizeof( REAL8 ), mmlength, fpout ) == mmlength, XLAL_EIO, "Could not output model-model product weights" );
759 }
760
761 /* fill in data/model weights into roq->weights complex matrix */
762 data->roq->weightsLinear = XLALMalloc( dmlength * sizeof( COMPLEX16 ) );
763 memcpy( data->roq->weightsLinear, dmweights, dmlength * sizeof( COMPLEX16 ) );
764 XLALFree( dmweights );
765
766 data->roq->weightsQuadratic = XLALMalloc( mmlength * sizeof( REAL8 ) );
767 memcpy( data->roq->weightsQuadratic, mmweights, mmlength * sizeof( REAL8 ) );
768 XLALFree( mmweights );
769
770 /* add interpolation nodes to a variable in runState->threads[0].model->ifo->params */
772 LALInferenceAddVariable( ifo->params, "numBasesQuad", &nbasesquad, LALINFERENCE_UINT4Vector_t, LALINFERENCE_PARAM_FIXED );
773
774 ifo = ifo->next;
775 data = data->next;
776 counter++;
777 }
778
779 if ( verbose ) {
780 fprintf( stderr, "Total number of linear bases = %d, total number of quadratic bases = %d, total number of data points = %d\n", nlineartot, nquadtot, ndatatot );
781 }
782
783 /* reset freqfactors to the correct value */
784 ifo = runState->threads[0].model->ifo;
785 while ( ifo ) {
786 check_and_add_fixed_variable( ifo->params, "freqfactors", &freqsCopy, LALINFERENCE_REAL8Vector_t );
787 ifo = ifo->next;
788 }
789
790 if ( inputroq ) {
791 fclose( fpin );
792 }
793
794 if ( LALInferenceCheckVariable( runState->algorithmParams, "timefile" ) ) {
795 gettimeofday( &time2, NULL );
796
797 FILE *timefile = *( FILE ** )LALInferenceGetVariable( runState->algorithmParams, "timefile" );
798 UINT4 timenum = *( UINT4 * )LALInferenceGetVariable( runState->algorithmParams, "timenum" );
799 tottime = ( REAL8 )( ( time2.tv_sec + time2.tv_usec * 1.e-6 ) - ( time1.tv_sec + time1.tv_usec * 1.e-6 ) );
800 fprintf( timefile, "[%d] %s: %.9le secs\n", timenum, __func__, tottime );
801 timenum++;
802 check_and_add_fixed_variable( runState->algorithmParams, "timenum", &timenum, LALINFERENCE_UINT4_t );
803 }
804
805 if ( outputroq ) {
806 if ( LALInferenceCheckVariable( runState->algorithmParams, "timefile" ) ) {
807 fclose( *( FILE ** )LALInferenceGetVariable( runState->algorithmParams, "timefile" ) );
808 }
809 fclose( fpout );
810 if ( verbose ) {
811 fprintf( stdout, "ROQ weights have been written to file.\nExiting program.\n" );
812 }
813 exit( 0 ); /* exit the programme succussfully */
814 }
815}
816
817
818/**
819 * \brief Generate a training set of waveforms for the basis generation
820 *
821 * This function will create a set of \a n waveforms randomly placed over the
822 * prior parameter space.
823 *
824 * @param[in] rs A temporary run state
825 * @param[in] n The number of training waveforms
826 *
827 * @return A complex matrix containing an array of training waveforms
828 */
830{
831 UINT4 j = 0;
833 dims->data[0] = n;
834 dims->data[1] = IFO_XTRA_DATA( rs->threads[0].model->ifo )->times->length;
836 gsl_matrix_complex_view tsview = gsl_matrix_complex_view_array( ( double * )ts->data, dims->data[0], dims->data[1] );
838 REAL8 logprior = 0.;
839
840 rs->threads[0].model->params = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
841
842 /* for parameters with Gaussian priors reset them to be flat, with ranges over +/-5 sigma for training set generation if required */
843 LALInferenceVariables *priorcopy = NULL;
844
845 if ( LALInferenceGetProcParamVal( rs->commandLine, "--roq-uniform" ) ) {
846 priorcopy = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
847 LALInferenceCopyVariables( rs->priorArgs, priorcopy );
849 UINT4 hascorrelated = 0; /* set if there is a correlated prior */
850 for ( ; item; item = item->next ) {
851 REAL8 mu = 0., sigma = 0., minval = 0., maxval = 0.;
852 if ( LALInferenceCheckGaussianPrior( rs->priorArgs, item->name ) ) {
853 LALInferenceGetGaussianPrior( rs->priorArgs, item->name, &mu, &sigma );
854 minval = mu - 5.*sigma;
855 maxval = mu + 5.*sigma;
856 LALInferenceRemoveGaussianPrior( rs->priorArgs, item->name ); /* remove prior */
857 } else if ( LALInferenceCheckCorrelatedPrior( rs->priorArgs, item->name ) ) {
858 gsl_matrix *cor = NULL, *invcor = NULL;
859 UINT4 idx = 0;
860 LALInferenceGetCorrelatedPrior( rs->priorArgs, item->name, &cor, &invcor, &mu, &sigma, &idx );
861 minval = mu - 5.*sigma;
862 maxval = mu + 5.*sigma;
863 hascorrelated = 1;
864 } else {
865 continue;
866 }
867
868 /* re-add prior as a uniform prior */
869 LALInferenceAddMinMaxPrior( rs->priorArgs, item->name, &minval, &maxval, LALINFERENCE_REAL8_t );
870 }
871 if ( hascorrelated ) {
872 LALInferenceRemoveCorrelatedPrior( rs->priorArgs ); /* remove correlated prior */
873 }
874 }
875
876 /* choose random variables values and fill in runState->threads[0].model->params */
877 while ( j < n ) {
878 /* copy values to model parameters */
880
881 /* draw from the prior distributions */
883
884 /* check prior is non-zero */
885 logprior = rs->prior( rs, rs->threads[0].model->params, rs->threads[0].model );
886 if ( logprior == -DBL_MAX || logprior == -INFINITY || isnan( logprior ) ) {
887 continue;
888 }
889
890 /* generate model */
891 rs->threads[0].model->templt( rs->threads[0].model );
892
893 /* place model into an array */
894 gsl_vector_complex_view cview;
895 cview = gsl_vector_complex_view_array( ( double * )rs->threads[0].model->ifo->compTimeSignal->data->data, IFO_XTRA_DATA( rs->threads[0].model->ifo )->times->length );
896 gsl_matrix_complex_set_row( &tsview.matrix, j, &cview.vector );
897 j++;
898 }
899
901
902 /* reset priors if required */
903 if ( LALInferenceGetProcParamVal( rs->commandLine, "--roq-uniform" ) ) {
905 LALInferenceCopyVariables( priorcopy, rs->priorArgs );
906 LALInferenceClearVariables( priorcopy );
907 }
908
909 return ts;
910}
911
912
913/**
914 * \brief Generate a training set of waveforms for the quadratic term basis generation
915 *
916 * This function will create a set of \a n waveforms randomly placed over the
917 * prior parameter space. The returned array will contain the real part of the product
918 * of the waveform with its complex conjugate.
919 *
920 * @param[in] rs A temporary run state
921 * @param[in] n The number of training waveforms
922 *
923 * @return A real matrix containing an array of training waveforms
924 */
926{
927 UINT4 j = 0, k = 0;
929 dims->data[0] = n;
930 dims->data[1] = IFO_XTRA_DATA( rs->threads[0].model->ifo )->times->length;
932 gsl_matrix_view tsview = gsl_matrix_view_array( ts->data, dims->data[0], dims->data[1] );
934 REAL8 logprior = 0.;
935
936 rs->threads[0].model->params = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
937
938 /* for parameters with Gaussian priors reset them to be flat, with ranges over +/-5 sigma for training set generation if required */
939 LALInferenceVariables *priorcopy = NULL;
940 if ( LALInferenceGetProcParamVal( rs->commandLine, "--roq-uniform" ) ) {
941 priorcopy = XLALCalloc( 1, sizeof( LALInferenceVariables ) );
942 LALInferenceCopyVariables( rs->priorArgs, priorcopy );
944 UINT4 hascorrelated = 0; /* set if there is a correlated prior */
945 for ( ; item; item = item->next ) {
946 REAL8 mu = 0., sigma = 0., minval = 0., maxval = 0.;
947 if ( LALInferenceCheckGaussianPrior( rs->priorArgs, item->name ) ) {
948 LALInferenceGetGaussianPrior( rs->priorArgs, item->name, &mu, &sigma );
949 minval = mu - 5.*sigma;
950 maxval = mu + 5.*sigma;
951 LALInferenceRemoveGaussianPrior( rs->priorArgs, item->name ); /* remove prior */
952 } else if ( LALInferenceCheckCorrelatedPrior( rs->priorArgs, item->name ) ) {
953 gsl_matrix *cor = NULL, *invcor = NULL;
954 UINT4 idx = 0;
955 LALInferenceGetCorrelatedPrior( rs->priorArgs, item->name, &cor, &invcor, &mu, &sigma, &idx );
956 minval = mu - 5.*sigma;
957 maxval = mu + 5.*sigma;
958 hascorrelated = 1;
959 } else {
960 continue;
961 }
962
963 /* re-add prior as a uniform prior */
964 LALInferenceAddMinMaxPrior( rs->priorArgs, item->name, &minval, &maxval, LALINFERENCE_REAL8_t );
965 }
966 if ( hascorrelated ) {
967 LALInferenceRemoveCorrelatedPrior( rs->priorArgs ); /* remove correlated prior */
968 }
969 }
970
971 /* choose random variables values and fill in runState->threads[0].model->params */
972 while ( j < n ) {
973 /* copy values to model parameters */
975
976 /* draw from the prior distributions */
978
979 /* check prior is non-zero */
980 logprior = rs->prior( rs, rs->threads[0].model->params, rs->threads[0].model );
981 if ( logprior == -DBL_MAX || logprior == -INFINITY || isnan( logprior ) ) {
982 continue;
983 }
984
985 /* generate model */
986 rs->threads[0].model->templt( rs->threads[0].model );
987
988 /* place model*model^* into an array */
989 for ( k = 0; k < IFO_XTRA_DATA( rs->threads[0].model->ifo )->times->length; k++ ) {
990 COMPLEX16 cval = rs->threads[0].model->ifo->compTimeSignal->data->data[k];
991 gsl_matrix_set( &tsview.matrix, j, k, creal( cval * conj( cval ) ) );
992 }
993 j++;
994 }
995
997
998 /* reset priors if required */
999 if ( LALInferenceGetProcParamVal( rs->commandLine, "--roq-uniform" ) ) {
1001 LALInferenceCopyVariables( priorcopy, rs->priorArgs );
1002 LALInferenceClearVariables( priorcopy );
1003 }
1004
1005 return ts;
1006}
1007
1008
1009/*--------------- END OF ROQ FUNCTIONS ----------------------*/
#define __func__
log an I/O error, i.e.
REAL8 LALInferenceGenerateCOMPLEX16OrthonormalBasis(COMPLEX16Array **RBin, const REAL8Vector *delta, REAL8 tolerance, COMPLEX16Array **TS, UINT4Vector **greedypoints)
void LALInferenceRemoveCOMPLEXROQInterpolant(LALInferenceCOMPLEXROQInterpolant *a)
COMPLEX16Vector * LALInferenceGenerateCOMPLEX16LinearWeights(COMPLEX16Array *B, COMPLEX16Vector *data, REAL8Vector *vars)
REAL8 LALInferenceEnrichCOMPLEX16Basis(const REAL8Vector *delta, REAL8 tolerance, COMPLEX16Array **RB, UINT4Vector **greedypoints, const COMPLEX16Array *testmodels, COMPLEX16Array **testmodelsnew)
REAL8Vector * LALInferenceGenerateQuadraticWeights(REAL8Array *B, REAL8Vector *vars)
LALInferenceCOMPLEXROQInterpolant * LALInferenceGenerateCOMPLEXROQInterpolant(COMPLEX16Array *RB)
REAL8 LALInferenceGenerateREAL8OrthonormalBasis(REAL8Array **RBin, const REAL8Vector *delta, REAL8 tolerance, REAL8Array **TS, UINT4Vector **greedypoints)
void LALInferenceRemoveREALROQInterpolant(LALInferenceREALROQInterpolant *a)
REAL8 LALInferenceEnrichREAL8Basis(const REAL8Vector *delta, REAL8 tolerance, REAL8Array **RB, UINT4Vector **greedypoints, const REAL8Array *testmodels, REAL8Array **testmodelsnew)
LALInferenceREALROQInterpolant * LALInferenceGenerateREALROQInterpolant(REAL8Array *RB)
ProcessParamsTable * ppt
int j
int k
#define fprintf
void XLALDestroyREAL8Array(REAL8Array *)
COMPLEX16Array * XLALCreateCOMPLEX16Array(UINT4Vector *)
void XLALDestroyCOMPLEX16Array(COMPLEX16Array *)
REAL8Array * XLALCreateREAL8Array(UINT4Vector *)
#define LAL_PI
double complex COMPLEX16
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
LALInferenceThreadState * LALInferenceInitThreads(INT4 nthreads)
void LALInferenceRemoveVariable(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)
void LALInferenceClearVariables(LALInferenceVariables *vars)
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
LALINFERENCE_PARAM_FIXED
LALINFERENCE_REAL8_t
LALINFERENCE_REAL8Vector_t
LALINFERENCE_void_ptr_t
LALINFERENCE_UINT4_t
LALINFERENCE_UINT4Vector_t
void LALInferenceRemoveCorrelatedPrior(LALInferenceVariables *priorArgs)
void LALInferenceAddMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max, LALInferenceVariableType type)
void LALInferenceRemoveGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
int LALInferenceCheckCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceDrawFromPrior(LALInferenceVariables *output, LALInferenceVariables *priorArgs, gsl_rng *rdm)
int LALInferenceCheckGaussianPrior(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)
LIGOTimeGPSVector * XLALCreateTimestampVector(UINT4 len)
Allocate a LIGOTimeGPSVector.
Definition: SFTtimestamps.c:47
LIGOTimeGPSVector * XLALResizeTimestampVector(LIGOTimeGPSVector *vector, UINT4 length)
Resize a LIGOTimeGPSVector.
Definition: SFTtimestamps.c:85
void XLALDestroyTimestampVector(LIGOTimeGPSVector *vect)
De-allocate a LIGOTimeGPSVector.
Definition: SFTtimestamps.c:69
void XLALDestroyCOMPLEX16TimeSeries(COMPLEX16TimeSeries *series)
COMPLEX16TimeSeries * XLALCreateCOMPLEX16TimeSeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaT, const LALUnit *sampleUnits, size_t length)
COMPLEX16TimeSeries * XLALResizeCOMPLEX16TimeSeries(COMPLEX16TimeSeries *series, int first, size_t length)
const LALUnit lalSecondUnit
REAL8Vector * XLALResizeREAL8Vector(REAL8Vector *vector, UINT4 length)
void XLALDestroyUINT4Vector(UINT4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
COMPLEX16Vector * XLALCreateCOMPLEX16Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
void XLALDestroyCOMPLEX16Vector(COMPLEX16Vector *vector)
UINT4Vector * XLALCreateUINT4Vector(UINT4 length)
#define XLAL_ERROR_VOID(...)
#define XLAL_CHECK_VOID(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
XLAL_EFUNC
XLAL_EIO
float data[BLOCKSIZE]
Definition: hwinject.c:360
int gpstime
Definition: hwinject.c:365
list mu
n
ts
Header file for the signal models functions used in parameter estimation code for known pulsar search...
#define IFO_XTRA_DATA(ifo)
Definition: ppe_models.h:35
void generate_interpolant(LALInferenceRunState *runState)
Generate an orthonormal basis set of waveforms from a training set.
Definition: ppe_roq.c:82
REAL8 * chebyshev_gauss_lobatto_nodes(REAL8 freqmin, REAL8 freqmax, UINT4 nnodes)
Generate Chebyshev-Gauss-Lobatto nodes in frequency.
Definition: ppe_roq.c:46
COMPLEX16Array * generate_training_set(LALInferenceRunState *rs, UINT4 n)
Generate a training set of waveforms for the basis generation.
Definition: ppe_roq.c:829
REAL8Array * generate_training_set_quad(LALInferenceRunState *rs, UINT4 n)
Generate a training set of waveforms for the quadratic term basis generation.
Definition: ppe_roq.c:925
Header file for the reduced order quadrature generation used in parameter estimation code for known p...
#define ROQTOLERANCE
Definition: ppe_roq.h:37
void check_and_add_fixed_variable(LALInferenceVariables *vars, const char *name, void *value, LALInferenceVariableType type)
Add a variable, checking first if it already exists and is of type LALINFERENCE_PARAM_FIXED and if so...
Definition: ppe_utils.c:778
UINT4Vector * dimLength
COMPLEX16 * data
COMPLEX16Sequence * data
COMPLEX16 * data
struct tagLALInferenceIFOModel * next
LALDetector * detector
LALInferenceVariables * params
COMPLEX16TimeSeries * compTimeSignal
LALInferenceVariables * params
LALInferenceIFOModel * ifo
LALInferenceTemplateFunction templt
ProcessParamsTable * commandLine
LALInferenceVariables * algorithmParams
struct tagLALInferenceIFOData * data
LALInferenceVariables * priorArgs
LALInferenceThreadState * threads
LALInferencePriorFunction prior
LALInferenceVariables * currentParams
LALInferenceModel * model
char name[VARNAME_MAX]
struct tagVariableItem * next
LALInferenceVariableItem * head
A vector of 'timestamps' of type LIGOTimeGPS.
Definition: SFTfileIO.h:188
LIGOTimeGPS * data
array of timestamps
Definition: SFTfileIO.h:193
UINT4 length
number of timestamps
Definition: SFTfileIO.h:192
UINT4Vector * dimLength
REAL8 * data
REAL8 * data
UINT4 * data
double df