54 df = ( freqmax - freqmin ) / 2.;
55 fplus = ( freqmax + freqmin ) / 2.;
58 for (
i = 0;
i < nnodes;
i++ ) {
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;
91 UINT4 nstreams = 0, nchunks = 0;
92 FILE *fpin = NULL, *fpout = NULL;
98 struct timeval time1, time2;
100 UINT4 nquadtot = 0, nlineartot = 0, ndatatot = 0;
103 gettimeofday( &time1, NULL );
117 tolerance = atof(
ppt->value );
119 XLAL_CHECK_VOID( tolerance < 1. && tolerance > 0.,
XLAL_EFUNC,
"ROQ tolerence (%le) is not within allowed range.", tolerance );
124 ntraining = atoi(
ppt->value );
133 CHAR *outputweights =
ppt->value;
134 XLAL_CHECK_VOID( ( fpout = fopen( outputweights,
"wb" ) ) != NULL,
XLAL_EIO,
"Could not open weights file for output." );
145 nenrichmax = atoi(
ppt->value );
149 CHAR *inputweights =
ppt->value;
152 XLAL_CHECK_VOID( ( fpin = fopen( inputweights,
"rb" ) ) != NULL,
XLAL_EIO,
"Could not open weights file for reading." );
155 XLAL_CHECK_VOID( fread( (
void * )&nstreams,
sizeof(
UINT4 ), 1, fpin ) == 1,
XLAL_EIO,
"Could not read in first value from weights file\n" );
177 memcpy( freqsCopy->
data, freqFactors->
data,
sizeof(
REAL8 )*nfreqs );
190 REAL8 *mmweights = NULL;
191 UINT4 dmlength = 0, mmlength = 0;
196 REAL8Vector *ssbdelays = NULL, *bsbdelays = NULL, *glitchphase = NULL;
200 REAL8Vector *ssbnodes = NULL, *bsbnodes = NULL, *gpnodes = NULL;
216 XLAL_CHECK_VOID( fread( (
void * )&nchunks,
sizeof(
UINT4 ), 1, fpin ) == 1,
XLAL_EIO,
"Could not read chunk numbers from weights file\n" );
227 freqsTemp->
data[0] = freqsCopy->
data[counter % nfreqs];
231 for (
i = 0;
i < chunkLengths->
length;
i++ ) {
232 UINT4 tlen = chunkLengths->
data[
i], enrichcounts = 0, nbases0 = 0, nbases0quad = 0;
239 REAL8 maxprojerr = 0.;
277 if ( bsbdelays != NULL ) {
283 if ( glitchphase != NULL ) {
289 for (
j = 0;
j < tlen;
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];
296 if ( glitchphase != NULL ) {
297 thisglitchphase->
data[
j] = glitchphase->data[startidx +
j];
303 if ( bsbdelays != NULL ) {
306 if ( glitchphase != NULL ) {
314 fprintf( stderr,
"Data chunk no. %d of %d (length: %d)\n",
i + 1, chunkLengths->
length, tlen );
327 if ( nenrichmax > 0 && nbases->
data[
i] < tlen ) {
331 fprintf( stderr,
"Enriching linear basis (no. bases): %d", nbases->
data[
i] );
337 REAL8 newmaxprojerr = maxprojerr;
341 if ( newmaxprojerr != 0. ) {
342 maxprojerr = newmaxprojerr;
348 if ( maxprojerr < tolerance ) {
358 if ( nbases->
data[
i] >= tlen ) {
360 nbases->
data[
i] = tlen;
376 for (
UINT4 didx = 0; didx < ( dimstmp->
data[0]*dimstmp->
data[1] ); didx++ ) {
377 ts->data[didx] = tsenrich->
data[didx];
384 }
while ( enrichcounts < nenrichmax && conseccount < nconsec );
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 );
397 nbases0 = nbases->
data[
i];
398 nlineartot += nbases0;
401 if ( nbases0 <= tlen - 1 ) {
409 for (
j = 0;
j < tlen;
j++ ) {
427 if ( nenrichmax > 0 && nbasesquad->
data[
i] < tlen ) {
432 fprintf( stderr,
"Enriching quadratic basis (no. bases): %d", nbasesquad->
data[
i] );
437 REAL8 newmaxprojerr = maxprojerr;
441 if ( newmaxprojerr != 0. ) {
442 maxprojerr = newmaxprojerr;
448 if ( maxprojerr < tolerance ) {
458 if ( nbasesquad->
data[
i] >= tlen ) {
460 nbasesquad->
data[
i] = tlen;
472 for (
UINT4 didx = 0; didx < ( dimstmp->
data[0]*dimstmp->
data[1] ); didx++ ) {
473 tsquad->
data[didx] = tsenrich->
data[didx];
483 }
while ( enrichcounts < nenrichmax && conseccount < nconsec );
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 );
496 nbases0quad = nbasesquad->
data[
i];
497 nquadtot += nbases0quad;
500 if ( nbases0quad <= tlen - 1 ) {
505 interpquad->
B = NULL;
508 for (
j = 0;
j < tlen;
j++ ) {
529 datasub.
data = &
data->compTimeData->data->data[startidx];
532 if ( gaussianLike ) {
534 vari.
data = &
data->varTimeData->data->data[startidx];
538 varist->
data[0] = 1.;
544 if ( nbases0 <= tlen - 1 ) {
545 if ( gaussianLike ) {
554 for (
j = 0;
j < tlen;
j++ ) {
555 if ( gaussianLike ) {
563 if ( nbases0quad <= tlen - 1 ) {
564 if ( gaussianLike ) {
573 for (
j = 0;
j < tlen;
j++ ) {
574 if ( gaussianLike ) {
582 if ( !gaussianLike ) {
587 mmlength += nbases0quad;
593 memcpy( &dmweights[dmlength - nbases0], dmw->
data,
sizeof(
COMPLEX16 )*nbases0 );
594 memcpy( &mmweights[mmlength - nbases0quad], mmw->
data,
sizeof(
REAL8 )*nbases0quad );
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." );
614 fprintf( stderr,
"Number of linear reduced bases for ROQ generation is %d\n", nbases0 );
620 nbases->
data[
i] = nbases0;
622 nlineartot += nbases0;
625 interpquad->
B = NULL;
631 fprintf( stderr,
"Number of quadratic reduced bases for ROQ generation is %d\n", nbases0quad );
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;
648 tnlength = timenodes->
length + nbases0;
654 if ( bsbdelays != NULL ) {
657 if ( glitchphase != NULL ) {
661 for (
j = 0;
j < nbases0;
j++ ) {
665 if ( bsbdelays != NULL ) {
666 bsbnodes->data[
dlen +
j] = bsbdelays->data[startidx + interp->
nodes[
j]];
668 if ( glitchphase != NULL ) {
669 gpnodes->data[
dlen +
j] = glitchphase->data[startidx + interp->
nodes[
j]];
674 tnlength = timenodes->
length + nbases0quad;
681 if ( bsbdelays != NULL ) {
684 if ( glitchphase != NULL ) {
688 for (
j = 0;
j < nbases0quad;
j++ ) {
692 if ( bsbdelays != NULL ) {
693 bsbnodes->data[
dlen +
j] = bsbdelays->data[startidx + interpquad->
nodes[
j]];
695 if ( glitchphase != NULL ) {
696 gpnodes->data[
dlen +
j] = glitchphase->data[startidx + interpquad->
nodes[
j]];
729 if ( bsbdelays != NULL ) {
731 memcpy( bsbcopy->
data, bsbdelays->data,
sizeof(
REAL8 )*bsbdelays->length );
737 if ( glitchphase != NULL ) {
739 memcpy( glitchphasecopy->
data, glitchphase->data,
sizeof(
REAL8 )*glitchphase->length );
753 XLAL_CHECK_VOID( fread( (
void * )mmweights,
sizeof(
REAL8 ), mmlength, fpin ) == mmlength,
XLAL_EIO,
"Could not read in model-model product weights" );
758 XLAL_CHECK_VOID( fwrite( mmweights,
sizeof(
REAL8 ), mmlength, fpout ) == mmlength,
XLAL_EIO,
"Could not output model-model product weights" );
763 memcpy(
data->roq->weightsLinear, dmweights, dmlength *
sizeof(
COMPLEX16 ) );
767 memcpy(
data->roq->weightsQuadratic, mmweights, mmlength *
sizeof(
REAL8 ) );
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 );
795 gettimeofday( &time2, NULL );
799 tottime = (
REAL8 )( ( time2.tv_sec + time2.tv_usec * 1.e-6 ) - ( time1.tv_sec + time1.tv_usec * 1.e-6 ) );
811 fprintf( stdout,
"ROQ weights have been written to file.\nExiting program.\n" );
836 gsl_matrix_complex_view tsview = gsl_matrix_complex_view_array( (
double * )
ts->data, dims->
data[0], dims->
data[1] );
849 UINT4 hascorrelated = 0;
850 for ( ; item; item = item->
next ) {
851 REAL8 mu = 0., sigma = 0., minval = 0., maxval = 0.;
854 minval =
mu - 5.*sigma;
855 maxval =
mu + 5.*sigma;
858 gsl_matrix *cor = NULL, *invcor = NULL;
861 minval =
mu - 5.*sigma;
862 maxval =
mu + 5.*sigma;
871 if ( hascorrelated ) {
894 gsl_vector_complex_view cview;
896 gsl_matrix_complex_set_row( &tsview.matrix,
j, &cview.vector );
932 gsl_matrix_view tsview = gsl_matrix_view_array(
ts->data, dims->
data[0], dims->
data[1] );
944 UINT4 hascorrelated = 0;
945 for ( ; item; item = item->
next ) {
946 REAL8 mu = 0., sigma = 0., minval = 0., maxval = 0.;
949 minval =
mu - 5.*sigma;
950 maxval =
mu + 5.*sigma;
953 gsl_matrix *cor = NULL, *invcor = NULL;
956 minval =
mu - 5.*sigma;
957 maxval =
mu + 5.*sigma;
966 if ( hascorrelated ) {
991 gsl_matrix_set( &tsview.matrix,
j,
k, creal( cval * conj( cval ) ) );
#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)
void XLALDestroyREAL8Array(REAL8Array *)
COMPLEX16Array * XLALCreateCOMPLEX16Array(UINT4Vector *)
void XLALDestroyCOMPLEX16Array(COMPLEX16Array *)
REAL8Array * XLALCreateREAL8Array(UINT4Vector *)
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_REAL8Vector_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)
LIGOTimeGPSVector * XLALCreateTimestampVector(UINT4 len)
Allocate a LIGOTimeGPSVector.
LIGOTimeGPSVector * XLALResizeTimestampVector(LIGOTimeGPSVector *vector, UINT4 length)
Resize a LIGOTimeGPSVector.
void XLALDestroyTimestampVector(LIGOTimeGPSVector *vect)
De-allocate a LIGOTimeGPSVector.
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,...)
Header file for the signal models functions used in parameter estimation code for known pulsar search...
#define IFO_XTRA_DATA(ifo)
void generate_interpolant(LALInferenceRunState *runState)
Generate an orthonormal basis set of waveforms from a training set.
REAL8 * chebyshev_gauss_lobatto_nodes(REAL8 freqmin, REAL8 freqmax, UINT4 nnodes)
Generate Chebyshev-Gauss-Lobatto nodes in frequency.
COMPLEX16Array * generate_training_set(LALInferenceRunState *rs, UINT4 n)
Generate a training set of waveforms for the basis generation.
REAL8Array * generate_training_set_quad(LALInferenceRunState *rs, UINT4 n)
Generate a training set of waveforms for the quadratic term basis generation.
Header file for the reduced order quadrature generation used in parameter estimation code for known p...
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...
struct tagLALInferenceIFOModel * next
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
struct tagVariableItem * next
LALInferenceVariableItem * head
A vector of 'timestamps' of type LIGOTimeGPS.
LIGOTimeGPS * data
array of timestamps
UINT4 length
number of timestamps