70 INT4 gaussianLike = 0;
78 get_model->
templt( get_model );
98 REAL8 chunkLength = 0., logliketmp = 0., chiSquare = 0.;
106 REAL8 sumModel = 0., sumDataModel = 0.;
107 COMPLEX16 B = 0.,
M = 0., Mp = 0., Mc = 0., vari = 0.;
109 REAL8Vector *sumP = NULL, *sumC = NULL, *sumX = NULL, *sumY = NULL, *sumB = NULL, *sumL = NULL;
110 REAL8Vector *sumPC = NULL, *sumPX = NULL, *sumPY = NULL, *sumPB = NULL, *sumPL = NULL;
111 REAL8Vector *sumCX = NULL, *sumCY = NULL, *sumCB = NULL, *sumCL = NULL;
112 REAL8Vector *sumXY = NULL, *sumXB = NULL, *sumXL = NULL;
116 COMPLEX16Vector *sumDataP = NULL, *sumDataC = NULL, *sumDataX = NULL, *sumDataY = NULL, *sumDataB = NULL, *sumDataL = NULL;
162 for (
i = 0 ;
i < length ;
i += chunkLength ) {
166 if ( chunkLength < chunkMin ) {
174 cl =
i + (
INT4 )chunkLength;
177 for (
j =
i ;
j < cl ;
j++ ) {
182 if ( gaussianLike ) {
187 sumModel += ( creal(
M ) * creal(
M ) + cimag(
M ) * cimag(
M ) ) / vari;
190 sumDataModel += ( creal(
B ) * creal(
M ) + cimag(
B ) * cimag(
M ) ) / vari;
196 sumModel += sumP->
data[
count] * ( creal( Mp ) * creal( Mp ) + cimag( Mp ) * cimag( Mp ) ) +
197 sumC->data[
count] * ( creal( Mc ) * creal( Mc ) + cimag( Mc ) * cimag( Mc ) ) +
198 2.*sumPC->
data[
count] * ( creal( Mp ) * creal( Mc ) + cimag( Mp ) * cimag( Mc ) );
200 sumDataModel += creal( sumDataP->
data[
count] ) * creal( Mp ) + cimag( sumDataP->
data[
count] ) * cimag( Mp ) +
201 creal( sumDataC->data[
count] ) * creal( Mc ) + cimag( sumDataC->data[
count] ) * cimag( Mc );
204 COMPLEX16 Mx = 0., My = 0., Mb = 0., Ml = 0.;
211 sumModel += sumX->data[
count] * ( creal( Mx ) * creal( Mx ) + cimag( Mx ) * cimag( Mx ) ) +
212 sumY->data[
count] * ( creal( My ) * creal( My ) + cimag( My ) * cimag( My ) ) +
213 sumB->data[
count] * ( creal( Mb ) * creal( Mb ) + cimag( Mb ) * cimag( Mb ) ) +
214 sumL->data[
count] * ( creal( Ml ) * creal( Ml ) + cimag( Ml ) * cimag( Ml ) ) +
215 2.*( sumPX->data[
count] * ( creal( Mp ) * creal( Mx ) + cimag( Mp ) * cimag( Mx ) ) +
216 sumPY->data[
count] * ( creal( Mp ) * creal( My ) + cimag( Mp ) * cimag( My ) ) +
217 sumPB->data[
count] * ( creal( Mp ) * creal( Mb ) + cimag( Mp ) * cimag( Mb ) ) +
218 sumPL->data[
count] * ( creal( Mp ) * creal( Ml ) + cimag( Mp ) * cimag( Ml ) ) +
219 sumCX->
data[
count] * ( creal( Mc ) * creal( Mx ) + cimag( Mc ) * cimag( Mx ) ) +
220 sumCY->data[
count] * ( creal( Mc ) * creal( My ) + cimag( Mc ) * cimag( My ) ) +
221 sumCB->data[
count] * ( creal( Mc ) * creal( Mb ) + cimag( Mc ) * cimag( Mb ) ) +
222 sumCL->data[
count] * ( creal( Mc ) * creal( Ml ) + cimag( Mc ) * cimag( Ml ) ) +
223 sumXY->
data[
count] * ( creal( Mx ) * creal( My ) + cimag( Mx ) * cimag( My ) ) +
224 sumXB->data[
count] * ( creal( Mx ) * creal( Mb ) + cimag( Mx ) * cimag( Mb ) ) +
225 sumXL->data[
count] * ( creal( Mx ) * creal( Ml ) + cimag( Mx ) * cimag( Ml ) ) +
226 sumYB->
data[
count] * ( creal( My ) * creal( Mb ) + cimag( My ) * cimag( Mb ) ) +
227 sumYL->data[
count] * ( creal( My ) * creal( Ml ) + cimag( My ) * cimag( Ml ) ) +
228 sumBL->
data[
count] * ( creal( Mb ) * creal( Ml ) + cimag( Mb ) * cimag( Ml ) ) );
230 sumDataModel += creal( sumDataX->data[
count] ) * creal( Mx ) + cimag( sumDataX->data[
count] ) * cimag( Mx ) +
231 creal( sumDataY->data[
count] ) * creal( My ) + cimag( sumDataY->data[
count] ) * cimag( My ) +
232 creal( sumDataB->data[
count] ) * creal( Mb ) + cimag( sumDataB->data[
count] ) * cimag( Mb ) +
233 creal( sumDataL->data[
count] ) * creal( Ml ) + cimag( sumDataL->data[
count] ) * cimag( Ml );
237 chiSquare = sumDat->
data[
count] - 2.*sumDataModel + sumModel;
239 if ( !gaussianLike ) {
240 logliketmp += ( gsl_sf_lnfact( chunkLength - 1 ) -
LAL_LN2 - chunkLength *
LAL_LNPI );
241 logliketmp -= chunkLength *
log( chiSquare );
243 logliketmp -= 0.5 * chiSquare;
252 UINT4 vstart = 0, mstart = 0, dstart = 0;
255 for (
i = 0;
i < chunkLengths->
length;
i++ ) {
262 dmweights.
data = &tempdata->
roq->weightsLinear[vstart];
265 mmweights.
data = &tempdata->
roq->weightsQuadratic[mstart];
271 cmodel.length = numbases->
data[
i];
273 dstart += numbases->
data[
i];
277 for (
UINT4 idx = 0; idx < quadmodel->length; idx++ ) {
279 quadmodel->data[idx] = creal( qval * conj( qval ) );
281 dstart += numbasesquad->
data[
i];
288 chiSquare = sumDat->
data[
i] - 2.*creal( dm ) + mm;
290 if ( !gaussianLike ) {
291 logliketmp += ( gsl_sf_lnfact( chunkLength - 1 ) -
LAL_LN2 - chunkLength *
LAL_LNPI );
292 logliketmp -= chunkLength *
log( chiSquare );
294 logliketmp -= 0.5 * chiSquare;
298 vstart += numbases->
data[
i];
299 mstart += numbasesquad->
data[
i];
304 if ( gaussianLike ) {
306 logliketmp += logGaussianNorm;
311 loglike += logliketmp;
313 tempdata = tempdata->
next;
314 ifomodeltemp = ifomodeltemp->
next;
347 CHAR *Znoisefile = NULL;
348 ProcessParamsTable *
ppt;
349 ProcessParamsTable *commandLine = runState->
commandLine;
350 INT4 gaussianLike = 0;
355 fprintf( stderr,
"Error... not output file specified\n" );
365 CHAR *dotloc = strrchr( Znoisefile,
'.' );
366 CHAR *slashloc = strrchr( Znoisefile,
'/' );
367 if ( dotloc != NULL ) {
368 if ( slashloc != NULL ) {
369 if ( slashloc < dotloc ) {
378 if ( (
fp = fopen( Znoisefile,
"w" ) ) == NULL ) {
393 REAL8 chunkLength = 0.;
399 if ( !gaussianLike ) {
400 for (
i = 0;
i < chunkLengths->
length;
i++ ) {
402 logLtmp += ( gsl_sf_lnfact( chunkLength - 1 ) -
LAL_LN2 - chunkLength *
LAL_LNPI );
403 logLtmp -= chunkLength *
log( sumDat->
data[
i] );
408 logLtmp += logGaussianNorm;
409 logLtmp -= 0.5 * sumDat->
data[0];
412 data->nullloglikelihood = logLtmp;
457 REAL8 prior = 0, value = 0.;
468 REAL8 I31 = -INFINITY, I21 = -INFINITY;
472 REAL8 C21 = -INFINITY, C22 = -INFINITY;
474 for ( ; item; item = item->
next ) {
490 if ( !strcmp( item->
name,
"I21" ) ) {
493 if ( !strcmp( item->
name,
"I31" ) ) {
496 if ( !strcmp( item->
name,
"C21" ) ) {
499 if ( !strcmp( item->
name,
"C22" ) ) {
506 if ( !strcmp( item->
name,
"IOTA" ) || !strcmp( item->
name,
"THETA" ) ) {
509 if ( !strcmp( item->
name,
"I21" ) ) {
512 if ( !strcmp( item->
name,
"I31" ) ) {
515 if ( !strcmp( item->
name,
"C21" ) ) {
518 if ( !strcmp( item->
name,
"C22" ) ) {
527 gsl_matrix *cor = NULL, *invcor = NULL;
532 if ( corVals == NULL ) {
539 corVals->
data[cori] = ( value -
mu ) / sigma;
557 if ( I21 != -INFINITY && I31 != -INFINITY ) {
567 if ( C21 == -INFINITY ) {
570 if ( C22 == -INFINITY ) {
573 if ( ( C21 < 0. && C22 > 0. ) || ( C21 > 0. && C22 < 0. ) ) {
580 gsl_matrix *cor = NULL, *invcor = NULL;
581 gsl_vector_view
vals;
582 gsl_vector *vm = gsl_vector_alloc( corVals->
length );
593 XLAL_CALLGSL( gsl_blas_dgemv( CblasNoTrans, 1., invcor, &
vals.vector, 0., vm ) );
650 ProcessParamsTable *
ppt = NULL;
662 Npost = atoi(
ppt->value );
673 REAL8 log_tot_ev = -INFINITY;
682 REAL8 avg_log_like_end = -INFINITY;
685 for (
i = 0;
i < Nsamp->
data[
k];
i++ ) {
689 log_ws[
k]->
data[
i] = logL + log_vol + log_dvol;
691 log_vol += log_vol_factor;
693 avg_log_like_end =
LOGPLUS( avg_log_like_end, logL );
694 log_ws[
k]->
data[
i] = log_vol + logL;
711 log_cumsums->
data[0] = -INFINITY;
714 for (
i = 0;
i < Nsamp->
data[
k];
i++ ) {
724 for (
i = 1;
i < Nsamp->
data[
k] + 1;
i++ )
725 if ( log_cumsums->
data[
i - 1] < us && us <= log_cumsums->
data[
i] ) {
777 UINT4 nsamp = 0,
i = 0, cnt = 0;
780 REAL8 *low = NULL, *high = NULL;
781 REAL8 *lownew = NULL, *highnew = NULL;
809 REAL8 maxvaltmp = -INFINITY, minvaltmp = INFINITY;
810 REAL8 posthigh = 0., postlow = 0., difflh = 0.;
811 REAL8 lowr = 0., highr = 0.;
813 for (
UINT4 k = 0;
k < nsamp;
k++ ) {
816 if ( val < minvaltmp ) {
819 if ( val > maxvaltmp ) {
825 posthigh = maxvaltmp;
828 difflh = posthigh - postlow;
841 if ( posthigh > highr || posthigh < lowr ) {
842 fprintf( stderr,
"Error... prior samples are out of range!\n" );
844 }
else if ( posthigh + difflh / 2. > highr ) {
847 high[cnt] = posthigh + difflh / 2.;
851 if ( postlow > highr || postlow < lowr ) {
852 fprintf( stderr,
"Error... prior samples are out of range!\n" );
854 }
else if ( postlow - difflh / 2. < lowr ) {
857 low[cnt] = postlow - difflh / 2.;
862 low[cnt] = postlow - difflh / 2.;
863 high[cnt] = posthigh + difflh / 2.;
870 fprintf( stderr,
"Error... Prior type not specified!\n" );
901 lownew[cnt] = low[cnt];
902 highnew[cnt] = high[cnt];
911 ndim = ( size_t )cnt;
921 for (
i = 0;
i < nsamp;
i++ ) {
970 for ( ; item; item = item->
next ) {
978 if ( !strcmp( item->
name,
"H0" ) || !strcmp( item->
name,
"Q22" ) || !strcmp( item->
name,
"DIST" ) ||
979 !strcmp( item->
name,
"PX" ) || !strcmp( item->
name,
"CGW" ) || !strncmp( item->
name,
"ECC",
sizeof(
CHAR ) * 3 ) ||
980 !strncmp( item->
name,
"A1",
sizeof(
CHAR ) * 2 ) || !strcmp( item->
name,
"MTOT" ) || !strcmp( item->
name,
"M2" ) ) {
986 if ( fabs( val ) > 1. ) {
987 if ( !strncmp( item->
name,
"SIN",
sizeof(
CHAR ) * 3 ) || !strncmp( item->
name,
"COS",
sizeof(
CHAR ) * 3 ) ) {
COMPLEX16 LALInferenceROQCOMPLEX16DotProduct(COMPLEX16Vector *weights, COMPLEX16Vector *model)
REAL8 LALInferenceROQREAL8DotProduct(REAL8Vector *weights, REAL8Vector *model)
static double double delta
#define XLAL_CALLGSL(statement)
int LALInferenceKDAddPoint(LALInferenceKDTree *tree, REAL8 *pt)
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
void LALInferenceKDVariablesToREAL8(LALInferenceVariables *params, REAL8 *pt, LALInferenceVariables *templt)
REAL8 LALInferenceGetREAL8Variable(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)
LALInferenceKDTree * LALInferenceKDEmpty(REAL8 *lowerLeft, REAL8 *upperRight, size_t ndim)
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
LALINFERENCE_PARAM_OUTPUT
LALINFERENCE_PARAM_CIRCULAR
LALINFERENCE_PARAM_LINEAR
REAL8 LALInferenceGMMPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceAddMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max, LALInferenceVariableType type)
void LALInferenceRemoveGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
REAL8 LALInferenceLogUniformPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name)
REAL8 LALInferenceFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
int LALInferenceCheckGMMPrior(LALInferenceVariables *priorArgs, const char *name)
void LALInferenceGetMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max)
int LALInferenceCheckGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
int LALInferenceCheckFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name)
int LALInferenceCheckLogUniformPrior(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)
char char * XLALStringDuplicate(const char *s)
int char * XLALStringAppend(char *s, const char *append)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_REAL8(...)
REAL8 priorFunction(LALInferenceRunState *runState, LALInferenceVariables *params, UNUSED LALInferenceModel *model)
The prior function.
void create_kdtree_prior(LALInferenceRunState *runState)
Create a k-d tree from prior samples.
REAL8 noise_only_likelihood(LALInferenceRunState *runState)
Calculate the natural logarithm of the evidence that the data consists of only Gaussian noise The fun...
void ns_to_posterior(LALInferenceRunState *runState)
Convert an array of nested samples to posterior samples.
REAL8 theta_prior(REAL8 theta)
Prior for angle that is equivalent to an latitude value to give a uniform prior on a sphere.
UINT4 in_range(LALInferenceVariables *priors, LALInferenceVariables *params)
Check that any parameters with minimum and maximum ranges are within that range.
REAL8 pulsar_log_likelihood(LALInferenceVariables *vars, LALInferenceIFOData *data, LALInferenceModel *get_model)
The log likelihood function.
Header file for the likelihood and prior functions used in parameter estimation code for known pulsar...
LALStringVector * corlist
#define LOGPLUS(x, y)
Macro to perform addition of two values within logarithm space .
REAL8TimeSeries * varTimeData
struct tagLALInferenceROQData * roq
struct tagLALInferenceIFOData * next
COMPLEX16TimeSeries * compTimeData
struct tagLALInferenceIFOModel * next
LALInferenceVariables * params
COMPLEX16TimeSeries * compTimeSignal
REAL8 * ifo_loglikelihoods
LALInferenceVariables * params
LALInferenceIFOModel * ifo
LALInferenceTemplateFunction templt
ProcessParamsTable * commandLine
LALInferenceVariables * algorithmParams
struct tagLALInferenceIFOData * data
LALInferenceVariables * priorArgs
LALInferenceThreadState * threads
LALInferenceVariables * currentParams
LALInferenceModel * model
struct tagVariableItem * next
LALInferenceParamVaryType vary