23 #include <lal/LALInferencePrior.h>
24 #include <lal/LALInferenceLikelihood.h>
26 #include <gsl/gsl_integration.h>
27 #include <gsl/gsl_cdf.h>
28 #include <gsl/gsl_errno.h>
29 #include <gsl/gsl_roots.h>
30 #include <lal/LALSimBurst.h>
31 #include <lal/XLALGSL.h>
36 #define UNUSED __attribute__ ((unused))
55 ----------------------------------------------\n\
56 --- Prior Arguments --------------------------\n\
57 ----------------------------------------------\n\
58 (--distance-prior-uniform) Impose uniform prior on distance and not volume (False)\n\
59 (--distance-prior-comoving-volume) Impose uniform prior on source-frame comoving volume (False)\n\
60 (--malmquistprior) Impose selection effects on the prior (False)\n\
61 (--malmquist-loudest-snr) Threshold SNR in the loudest detector (0.0)\n\
62 (--malmquist-second-loudest-snr) Threshold SNR in the second loudest detector (5.0)\n\
63 (--malmquist-network-snr) Threshold network SNR (0.0)\n\
64 (--analyticnullprior) Use analytic null prior\n\
65 (--nullprior) Use null prior in the sampled parameters\n\
66 (--alignedspin-zprior) Use prior on z component of spin that corresponds to fully precessing model\n\
67 (--spin-volumetricprior) Use prior on spin components that is uniform inside the sphere\n\
95 INT4 uniform_distance = 0;
96 INT4 src_comove_volume_distance = 0;
101 src_comove_volume_distance = 1;
104 "uniform_distance", &uniform_distance,
109 "src_comove_volume_distance", &src_comove_volume_distance,
117 REAL8 malmquist_loudest = 0.0;
118 REAL8 malmquist_second_loudest = 5.0;
119 REAL8 malmquist_network = 0.0;
122 "--malmquist-loudest-snr");
126 "--malmquist-second-loudest-snr");
127 if (
ppt) malmquist_second_loudest = atof(
ppt->
value);
130 "--malmquist-network-snr");
134 "malmquist", &malmquist,
139 "malmquist_loudest_snr",
145 "malmquist_second_loudest_snr",
146 &malmquist_second_loudest,
151 "malmquist_network_snr",
167 fprintf(stderr,
"Error: You cannot use both --alignedspin-zprior and --spin-volumetricprior\n");
172 fprintf(stderr,
"Error: You cannot use both --distance-prior-comoving-volume and --distance-prior-uniform\n");
204 REAL8 ampWidth = -1.0;
205 REAL8 phaseWidth = -1.0;
206 REAL8 logPrior = 0.0;
214 ifo = runState->
data;
224 fprintf(stderr,
"variable name too long\n"); exit(1);
227 logPrior += -0.5*log(2.0*M_PI) - log(ampWidth) - 0.5*amp*amp/ampWidth/ampWidth;
237 fprintf(stderr,
"variable name too long\n"); exit(1);
240 logPrior += -0.5*log(2.0*M_PI) - log(phaseWidth) - 0.5*phase*phase/phaseWidth/phaseWidth;
253 REAL8 ampWidth = -1.0;
254 REAL8 phaseWidth = -1.0;
261 ifo = runState->
data;
273 fprintf(stderr,
"variable name too long\n"); exit(1);
288 fprintf(stderr,
"variable name too long\n"); exit(1);
314 SNR = A*sqrt( (PIterm*
Q/f) );
315 return log(SNR/(SNRPEAK*SNRPEAK))+(-SNR/SNRPEAK);
325 UINT4 glitchFlag = 0;
338 gsl_matrix *gparams = NULL;
340 REAL8 component_min=0.0;
341 REAL8 component_max=0.0;
352 for(nglitch=0; nglitch<gsize->
data[nifo]; nglitch++)
354 A = gsl_matrix_get(glitch_A,nifo,nglitch);
355 Q = gsl_matrix_get(glitch_Q,nifo,nglitch);
356 f = gsl_matrix_get(glitch_f,nifo,nglitch);
362 for(;item;item=item->
next){
363 if(!strcmp(item->
name,
"morlet_f0" ) || !strcmp(item->
name,
"morlet_Q" ) || !strcmp(item->
name,
"morlet_t0" ) || !strcmp(item->
name,
"morlet_phi") )
365 gparams = *((gsl_matrix **)(item->
value));
367 sprintf(priormin,
"%s_prior_min",item->
name);
368 sprintf(priormax,
"%s_prior_max",item->
name);
376 val = gsl_matrix_get(gparams,
i,
j);
379 if(val<component_min || val>component_max)
return -INFINITY;
380 else logPrior -= log(component_max-component_min);
421 for(
i=0;
i<(
UINT4)nparams->size1;
i++)
424 for(
j=0;
j<(
UINT4)nparams->size2;
j++)
427 val = gsl_matrix_get(nparams,
i,
j);
430 if(val < component_min || val > component_max)
return -INFINITY;
431 else if(psdGaussianPrior) logPrior += -0.5*( (
mean-val)*(
mean-val)/var + log(2.0*
LAL_PI*var) );
454 REAL8 c0=1.012306,
c1=1.136740,
c2=0.262462, c3=0.016732, c4=0.000387;
481 logPrior+= -0.5*(
mean-val)*(
mean-val)/stdev/stdev - 0.5*log(
LAL_TWOPI) - log(stdev);
498 REAL8 dist_Gpc = exp(log_dist)/1000.0;
499 REAL8 dist_Gpc2= dist_Gpc*dist_Gpc;
500 REAL8 dist_Gpc3= dist_Gpc2*dist_Gpc;
501 REAL8 dist_Gpc4= dist_Gpc3*dist_Gpc;
502 REAL8 denominator =
c0+
c1*dist_Gpc+
c2*dist_Gpc2+c3*dist_Gpc3+c4*dist_Gpc4;
503 logPrior+=3.0* log_dist-log(denominator);
506 logPrior+=3.0* log_dist;
515 REAL8 dist_Gpc2= dist_Gpc*dist_Gpc;
516 REAL8 dist_Gpc3= dist_Gpc2*dist_Gpc;
517 REAL8 dist_Gpc4= dist_Gpc3*dist_Gpc;
518 REAL8 denominator =
c0+
c1*dist_Gpc+
c2*dist_Gpc2+c3*dist_Gpc3+c4*dist_Gpc4;
519 logPrior+=2.0*log(
dist)-log(denominator);
522 logPrior+=2.0*log(
dist);
550 logPrior+=log(
m1*
m1);
603 REAL8 V = (4./3.)*
LAL_PI * (a_max*a_max*a_max - a_min*a_min*a_min);
604 logPrior+=log(fabs(
a*
a))-log(fabs(
V));
619 logPrior+=log(fabs((3./4.)*(a_max*a_max -
a*
a)))-log(fabs(
V));
632 REAL8 V = (4./3.)*
LAL_PI * (a_max*a_max*a_max - a_min*a_min*a_min);
633 logPrior+=log(fabs(
a*
a))-log(fabs(
V));
647 logPrior+=log(fabs((3./4.)*(a_max*a_max -
a*
a)))-log(fabs(
V));
663 logPrior += -log(2.0) - log(R) + log(-log(fabs(z) / R));
669 logPrior += -log(2.0) - log(R) + log(-log(fabs(z) / R));
713 char **info = (
char **)context;
714 char *timeID = &info[2][0];
720 double azimuth, cosalpha, lat, longitude,
t0,
tc;
758 lat = asin(2.0 * Cube[
i] - 1.0);
815 sprintf(timeID,
"%d",
i);
831 sprintf(timeID,
"%d",
i);
839 double mc = 0.0,
eta = 0.0,
q = 0.0,
m1 = 0.0,
m2 = 0.0,
m = 0.0;
874 if(
m1 == 0.0 &&
m2 == 0.0 )
881 if( m1_min == m1_max && m2_min==m2_max)
914 double logmc = log(
mc);
937 min = exp(min);
max = exp(
max);
939 double logdist = log(
dist);
1051 if (ScaleTest==0 || ConstCalib==0 )
return 0;
1053 for(;item;item=item->
next)
1118 if (parameter == NULL || priorArgs == NULL)
1125 for (paraHead=parameter->
head; paraHead; paraHead=paraHead->
next) {
1140 if (val == INFINITY)
1144 if ((val >= min) && (val <=
max))
1173 offset = fmod(offset,
delta);
1188 offset = fmod(offset,
delta);
1206 if (parameter == NULL)
1212 UINT4 idx1 = 0, idx2 = 0;
1214 for(paraHead=parameter->
head;paraHead;paraHead=paraHead->
next){
1216 !strcmp(paraHead->
name,
"psi") ){
1229 !strcmp(paraHead->
name,
"phi0") ){
1235 if ( idx2 == 0 ) paraPhi0 = paraPhi0->
next;
1238 if ( idx1 == 2 )
break;
1241 if( rotphi0 != 0. ) *(
REAL8 *)paraPhi0->
value += rotphi0;
1251 static int SkyLocPriorWarning = 0;
1259 if (!SkyLocPriorWarning ) {
1260 SkyLocPriorWarning = 1;
1261 fprintf(stderr,
"SkyLocalization priors are being used. (in %s, line %d)\n", __FILE__, __LINE__);
1281 logPrior+= -0.5*(
mean-val)*(
mean-val)/stdev/stdev - 0.5*log(
LAL_TWOPI) - log(stdev);
1326 logPrior+=log(
m1*
m1);
1377 UINT4 psdGaussianPrior;
1387 for(
i=0;
i<(
UINT4)nparams->size1;
i++)
1389 for(
j=0;
j<(
UINT4)nparams->size2;
j++)
1392 val = gsl_matrix_get(nparams,
i,
j);
1394 if(val < min || val >
max)
return -INFINITY;
1395 else if(psdGaussianPrior)prior += -0.5*( (
mean-val)*(
mean-val)/var + log(2.0*
LAL_PI*var) );
1413 char **info = (
char **)context;
1414 char *timeID = &info[2][0];
1421 double azimuth, cosalpha, lat, longitude,
t0,
tc;
1459 lat = asin(2.0 * Cube[
i] - 1.0);
1516 sprintf(timeID,
"%d",
i);
1532 sprintf(timeID,
"%d",
i);
1539 double mc = 0.0,
eta = 0.0,
q = 0.0,
m1 = 0.0,
m2 = 0.0,
m = 0.0;
1572 if(
m1 == 0.0 &&
m2 == 0.0 )
1578 if( m1_min == m1_max && m2_min == m2_max)
1611 double logmc = log(
mc);
1634 min = exp(min);
max = exp(
max);
1636 double logdist = log(
dist);
1749 if (ScaleTest==0 || ConstCalib==0 )
return 0;
1751 for(;item;item=item->
next)
1815 double Mc = pow(M2*iData->
M1, 3.0/5.0)/pow(M2+iData->
M1, 1.0/5.0);
1816 double q = M2/iData->
M1;
1817 if (Mc < iData->McMin || Mc > iData->
McMax || q < iData->massRatioMin ||
q > iData->
massRatioMax) {
1820 return pow(Mc, -11.0/6.0);
1824 #define LALINFERENCE_PRIOR_SQR(x) ((x)*(x))
1828 double Mc = pow(M2*iData->
M1, 3.0/5.0)/pow(M2+iData->
M1, 1.0/5.0);
1830 if (Mc < iData->McMin || Mc > iData->
McMax || eta < iData->massRatioMin ||
eta > iData->
massRatioMax) {
1833 return pow(Mc, -11.0/6.0);
1837 #undef LALINFERENCE_PRIOR_SQR
1853 #define LALINFERENCE_PRIOR_MIN(x, y) ((x) < (y) ? (x) : (y))
1878 #undef LALINFERENCE_PRIOR_MIN
1881 const double McMin,
const double McMax,
1882 const double massRatioMin,
const double massRatioMax,
const char *massRatioName) {
1883 const double epsabs = 1
e-8;
1884 const double epsrel = 1
e-8;
1885 const size_t wsSize = 10000;
1892 else if(!strcmp(massRatioName,
"q"))
1894 else if(!strcmp(massRatioName,
"eta"))
1900 gsl_error_handler_t *oldHandler = gsl_set_error_handler_off();
1902 gsl_integration_workspace *wsOuter = gsl_integration_workspace_alloc(wsSize);
1903 gsl_integration_workspace *wsInner = gsl_integration_workspace_alloc(wsSize);
1907 oData.
McMin = McMin;
1908 oData.
McMax = McMax;
1919 int status = gsl_integration_qag(&f, MMin,
MMax, epsabs, epsrel, wsSize, GSL_INTEG_GAUSS61, wsOuter,
1925 gsl_set_error_handler(oldHandler);
1927 gsl_integration_workspace_free(wsOuter);
1928 gsl_integration_workspace_free(wsInner);
1941 sprintf(minName,
"%s_min",
name);
1942 sprintf(maxName,
"%s_max",
name);
1954 sprintf(minName,
"%s_min",
name);
1955 sprintf(maxName,
"%s_max",
name);
1967 sprintf(minName,
"%s_min",
name);
1968 sprintf(maxName,
"%s_max",
name);
1979 sprintf(minName,
"%s_min",
name);
1980 sprintf(maxName,
"%s_max",
name);
1997 sprintf(meanName,
"%s_gaussian_mean",
name);
1998 sprintf(sigmaName,
"%s_gaussian_sigma",
name);
2009 sprintf(meanName,
"%s_gaussian_mean",
name);
2010 sprintf(sigmaName,
"%s_gaussian_sigma",
name);
2022 sprintf(meanName,
"%s_gaussian_mean",
name);
2023 sprintf(sigmaName,
"%s_gaussian_sigma",
name);
2039 sprintf(meanName,
"%s_gaussian_mean",
name);
2040 sprintf(sigmaName,
"%s_gaussian_sigma",
name);
2055 const char *name, gsl_matrix **cor,
2063 sprintf(corName,
"correlation_matrix");
2064 sprintf(invName,
"inverse_correlation_matrix");
2071 gsl_matrix *thiscor = NULL, *usecor = NULL;
2073 usecor = gsl_matrix_alloc( thiscor->size1, thiscor->size2 );
2076 gsl_matrix *invcor = gsl_matrix_alloc( usecor->size1, usecor->size2 );
2077 gsl_permutation *
p = gsl_permutation_alloc( usecor->size1 );
2094 sprintf(meanName,
"%s_correlation_mean",
name);
2095 sprintf(sigmaName,
"%s_correlation_sigma",
name);
2096 sprintf(idxName,
"%s_index",
name);
2107 const char *name, gsl_matrix **cor, gsl_matrix **invcor,
2116 sprintf(corName,
"correlation_matrix");
2117 sprintf(invName,
"inverse_correlation_matrix");
2118 sprintf(meanName,
"%s_correlation_mean",
name);
2119 sprintf(sigmaName,
"%s_correlation_sigma",
name);
2120 sprintf(idxName,
"%s_index",
name);
2123 if (
ptr ) *cor = *(gsl_matrix **)
ptr;
2127 if (
ptr ) *invcor = *(gsl_matrix **)
ptr;
2153 sprintf(corName,
"correlation_matrix");
2154 sprintf(invName,
"inverse_correlation_matrix");
2155 sprintf(meanName,
"_correlation_mean");
2156 sprintf(sigmaName,
"_correlation_sigma");
2157 sprintf(idxName,
"_index");
2164 for( ; item; item = item->
next ){
2165 if ( strstr(item->
name, meanName) != NULL && strstr(item->
name, sigmaName) != NULL && strstr(item->
name, idxName) != NULL ){
2184 sprintf(corName,
"correlation_matrix");
2185 sprintf(invName,
"inverse_correlation_matrix");
2186 sprintf(meanName,
"%s_correlation_mean",
name);
2187 sprintf(sigmaName,
"%s_correlation_sigma",
name);
2188 sprintf(idxName,
"%s_index",
name);
2206 char gmmParsName[
VARNAME_MAX] =
"gmm_parameter_lists";
2230 sprintf(musName,
"%s_gmm_sigmas",
name);
2231 sprintf(sigmasName,
"%s_gmm_mus",
name);
2232 sprintf(weightsName,
"%s_gmm_weights",
name);
2233 sprintf(corName,
"%s_gmm_cors",
name);
2234 sprintf(invcorName,
"%s_gmm_invcors",
name);
2235 sprintf(detName,
"%s_gmm_dets",
name);
2236 sprintf(minName,
"%s_gmm_min",
name);
2237 sprintf(maxName,
"%s_gmm_max",
name);
2246 if ( !mus[0][0] || !covs[0][0] || !
weights[0] ){
2257 gsl_matrix **cormat =
XLALCalloc(nmodes,
sizeof(gsl_matrix *));
2258 gsl_matrix **invcor =
XLALCalloc(nmodes,
sizeof(gsl_matrix *));
2260 for (
j = 0;
j < nmodes;
j++ ){
2262 cormat[
j] = gsl_matrix_calloc(npars, npars);
2263 gsl_matrix *invSig = gsl_matrix_calloc(npars, npars);
2264 gsl_matrix *tmpMat = gsl_matrix_calloc(npars, npars);
2266 if ( covs[0][
j]->size1 != covs[0][
j]->size2 || covs[0][
j]->size1 != npars ){
2270 for (
i = 0;
i < npars;
i++ ){
2271 sigmas[
j]->
data[
i] = sqrt(gsl_matrix_get(covs[0][
j],
i,
i));
2272 gsl_matrix_set(invSig,
i,
i, 1./sigmas[
j]->
data[
i]);
2275 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, invSig, covs[0][
j], 0., tmpMat);
2276 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, tmpMat, invSig, 0., cormat[
j]);
2278 gsl_matrix_free(invSig);
2283 invcor[
j] = gsl_matrix_alloc( npars, npars );
2284 gsl_permutation *
p = gsl_permutation_alloc( npars );
2297 dets->
data[
j] = gsl_linalg_LU_det( tmpMat,
s );
2311 REAL8 weightsum = 0.;
2318 if ( !minrange[0] ){
2320 for (
i = 0;
i < npars;
i++ ){ minrange[0]->
data[
i] = -INFINITY; }
2322 if ( !maxrange[0] ){
2324 for (
i = 0;
i < npars;
i++ ){ maxrange[0]->
data[
i] = INFINITY; }
2327 for (
i = 0;
i < npars;
i++ ){
2328 if ( minrange[0]->
data[
i] > maxrange[0]->
data[
i] ){
2346 char gmmParsName[
VARNAME_MAX] =
"gmm_parameter_lists";
2353 for (
i = 0;
i < numlists;
i++ ){
2364 if (
found ){
break; }
2368 *fullname = parLists->
data[
i];
2380 sprintf(musName,
"%s_gmm_sigmas", parLists->
data[
i]);
2381 sprintf(sigmasName,
"%s_gmm_mus", parLists->
data[
i]);
2382 sprintf(weightsName,
"%s_gmm_weights", parLists->
data[
i]);
2383 sprintf(corName,
"%s_gmm_cors", parLists->
data[
i]);
2384 sprintf(invcorName,
"%s_gmm_invcors", parLists->
data[
i]);
2385 sprintf(detName,
"%s_gmm_dets", parLists->
data[
i]);
2386 sprintf(minName,
"%s_gmm_min", parLists->
data[
i]);
2387 sprintf(maxName,
"%s_gmm_max",parLists->
data[
i]);
2402 if (
ptr ){ *cors = *(gsl_matrix ***)
ptr; }
2406 if (
ptr ){ *invcors = *(gsl_matrix ***)
ptr; }
2425 char gmmParsName[
VARNAME_MAX] =
"gmm_parameter_lists";
2434 if ( numlists == 0 ){
return 0; }
2437 for (
i = 0;
i < numlists;
i++ ){
2447 if (
found ){
break; }
2450 if ( !
found ){
return 0; }
2462 sprintf(musName,
"%s_gmm_sigmas", parLists->
data[
i]);
2463 sprintf(sigmasName,
"%s_gmm_mus", parLists->
data[
i]);
2464 sprintf(weightsName,
"%s_gmm_weights", parLists->
data[
i]);
2465 sprintf(corName,
"%s_gmm_cors", parLists->
data[
i]);
2466 sprintf(invcorName,
"%s_gmm_invcors", parLists->
data[
i]);
2467 sprintf(detName,
"%s_gmm_dets", parLists->
data[
i]);
2468 sprintf(minName,
"%s_gmm_min", parLists->
data[
i]);
2469 sprintf(maxName,
"%s_gmm_max", parLists->
data[
i]);
2486 char gmmParsName[
VARNAME_MAX] =
"gmm_parameter_lists";
2493 for (
i = 0;
i < numlists;
i++ ){
2494 if ( !strcmp(
name, parLists->
data[
i]) ){
2507 if (
found ){
break; }
2510 if ( !
found ){
return; }
2521 sprintf(musName,
"%s_gmm_sigmas", parLists->
data[
i]);
2522 sprintf(sigmasName,
"%s_gmm_mus", parLists->
data[
i]);
2523 sprintf(weightsName,
"%s_gmm_weights", parLists->
data[
i]);
2524 sprintf(corName,
"%s_gmm_cors", parLists->
data[
i]);
2525 sprintf(invcorName,
"%s_gmm_invcors", parLists->
data[
i]);
2526 sprintf(detName,
"%s_gmm_dets", parLists->
data[
i]);
2527 sprintf(minName,
"%s_gmm_min", parLists->
data[
i]);
2528 sprintf(maxName,
"%s_gmm_max", parLists->
data[
i]);
2539 if ( numlists == 1 ){
2543 parLists->
data[
i][0] =
'\0';
2555 sprintf(rName,
"%s_fermi_r",
name);
2556 sprintf(sigmaName,
"%s_fermi_sigma",
name);
2567 sprintf(rName,
"%s_fermi_r",
name);
2568 sprintf(sigmaName,
"%s_fermi_sigma",
name);
2580 sprintf(rName,
"%s_fermi_r",
name);
2581 sprintf(sigmaName,
"%s_fermi_sigma",
name);
2596 sprintf(rName,
"%s_fermi_r",
name);
2597 sprintf(sigmaName,
"%s_fermi_sigma",
name);
2618 sprintf(xminName,
"%s_loguniform_xmin",
name);
2619 sprintf(xmaxName,
"%s_loguniform_xmax",
name);
2630 if (*xmin >= *xmax || *xmin < 0. ){
2631 XLAL_ERROR_VOID(
XLAL_EINVAL,
"Minimum must be less than maximum (and minumum must be greater than zero), but %f >= %f.", *xmin, *xmax);
2637 sprintf(xminName,
"%s_loguniform_xmin",
name);
2638 sprintf(xmaxName,
"%s_loguniform_xmax",
name);
2654 sprintf(xminName,
"%s_loguniform_xmin",
name);
2655 sprintf(xmaxName,
"%s_loguniform_xmax",
name);
2670 sprintf(xminName,
"%s_loguniform_xmin",
name);
2671 sprintf(xmaxName,
"%s_loguniform_xmax",
name);
2693 if (
output == NULL || priorArgs == NULL || rdm == NULL)
2706 "kDTreePriorTemplate");
2722 for(;item;item=item->
next){
2740 if (
output == NULL || priorArgs == NULL ||
name == NULL || rdm == NULL)
2750 tmp =
mu + gsl_ran_gaussian(rdm, (
double)sigma);
2757 tmp = min + (
max-min)*gsl_rng_uniform( rdm );
2767 cp = gsl_rng_uniform( rdm );
2768 tmp = log(-exp(-
r) + pow(1. + exp(
r), -
cp) + exp(-
r)*pow(1. + exp(
r), -
cp));
2770 }
while ( tmp < 0. );
2774 REAL8 xmin = 0., xmax = 0.,
cp;
2780 }
else if( xmax < xmin ) {
2785 cp = gsl_rng_uniform( rdm );
2789 tmp = xmin * pow(xmax/xmin,
cp);
2793 gsl_matrix *cor = NULL, *invcor = NULL;
2795 UINT4 idx = 0, dims = 0;
2806 "multivariate_deviates");
2810 UINT4 randomseed = gsl_rng_get(rdm);
2829 tmp =
mu + sigma*tmps->
data[idx];
2837 gsl_matrix **cor, UNUSED **invcor;
2838 REAL8Vector **mus, **sigmas, *
weights = NULL, *minrange = NULL, *maxrange = NULL, UNUSED *dets = NULL;
2839 REAL8 cp = 0., cumweights = 0.;
2841 UINT4 idx = 0, dims = 0;
2842 CHAR *fullname = NULL;
2844 LALInferenceGetGMMPrior( priorArgs,
name, &mus, &sigmas, &cor, &invcor, &
weights, &minrange, &maxrange, &dets, &idx, &fullname );
2846 dims = cor[0]->size1;
2851 sprintf(gmmmvd,
"%s_gmm_mvd", fullname);
2852 sprintf(gmmmode,
"%s_gmm_mode", fullname);
2861 cp = gsl_rng_uniform( rdm );
2862 cumweights =
weights->data[0];
2864 while(
cp > cumweights ){
2866 cumweights +=
weights->data[thismode];
2870 UINT4 randomseed = gsl_rng_get(rdm);
2883 tmp = mus[thismode]->
data[idx] + sigmas[thismode]->
data[idx]*tmps->
data[idx];
2888 sprintf(nparsdonename,
"%s_gmm_npars", fullname);
2899 if ( npars == dims ){
2954 while (ifo != NULL) {
2960 REAL8 loudest_snr=0.0, second_loudest_snr=0.0;
2961 for (
i=0;
i<nifo;
i++) {
2962 if (model->
ifo_SNRs[
i] > second_loudest_snr) {
2964 second_loudest_snr = loudest_snr;
2967 second_loudest_snr = model->
ifo_SNRs[
i];
2976 if (loudest_snr < malmquist_loudest
2977 || second_loudest_snr < malmquist_second_loudest
2978 || model->
SNR < malmquist_network)
2996 logPrior+=log(
m1*
m1);
3026 char **info = (
char **)context;
3027 char *timeID = &info[2][0];
3164 sprintf(timeID,
"%d",
i);
3179 sprintf(timeID,
"%d",
i);
3214 if (ScaleTest==0 || ConstCalib==0 )
return 0;
3254 UINT4 psdGaussianPrior;
3264 for(
i=0;
i<(
UINT4)nparams->size1;
i++)
3266 for(
j=0;
j<(
UINT4)nparams->size2;
j++)
3269 if (psdGaussianPrior)
3275 gsl_matrix_set(nparams,
i,
j,val);
3280 for(
i=0;
i<(
UINT4)nparams->size1;
i++)
3282 for(
j=0;
j<(
UINT4)nparams->size2;
j++)
3285 val = gsl_matrix_get(nparams,
i,
j);
3286 if(val < min || val >
max)
return 0;
3304 for(;item;item=item->
next)
3332 return x1 +
r * ( x2 - x1 );
3344 return exp( lx1 +
r * ( lx2 - lx1 ) );
3353 double pp =
p + 1.0;
3354 return pow(
r * pow(x2,
pp) + (1.0 -
r) * pow(x1,
pp), 1.0 /
pp);
3363 return gsl_cdf_gaussian_Pinv(
r,sigma) +
mean;
3372 return acos((1.0-
r)*cos(x1)+
r*cos(x2));
3389 REAL8 r = 0., sigma = 0.;
3392 if ( value < 0. ){
return -INFINITY; }
3393 else{
return -
logaddexp((value/sigma)-
r, 0.); }
3400 REAL8 logPrior = 0.0;
3406 char gmmParsName[
VARNAME_MAX] =
"gmm_parameter_lists";
3414 for (
i = 0;
i < numlists;
i++ ){
3422 if (
found ){
break; }
3427 sprintf(parname,
"%s_gmm_value",
name);
3434 for (
j = 0;
j < npars;
j++ ){
3435 sprintf(parname,
"%s_gmm_value", toks->
tokens[
j]);
3445 REAL8Vector **gmmsigmas = NULL, **gmmmus = NULL, *gmmweights = NULL, *gmmdets = NULL;
3446 gsl_matrix **cor, **invcor;
3449 CHAR *fullname = NULL;
3452 LALInferenceGetGMMPrior( priorArgs,
name, &gmmmus, &gmmsigmas, &cor, &invcor, &gmmweights, &gmmlow, &gmmhigh, &gmmdets, &idx, &fullname );
3455 for (
j = 0;
j < npars;
j++ ){
3456 if ( allvalues->
data[
j] < gmmlow->
data[
j] || allvalues->
data[
j] > gmmhigh->data[
j] ){
3457 logPrior = -INFINITY;
3462 if ( isfinite( logPrior ) ){
3463 REAL8 thisGauss = 0.;
3464 logPrior = -INFINITY;
3465 for (
i = 0;
i < gmmweights->length;
i++ ){
3467 gsl_vector *vmu = gsl_vector_calloc( npars );
3468 gsl_matrix *invcov = gsl_matrix_calloc( npars, npars );
3469 gsl_matrix *tmpMat = gsl_matrix_calloc( npars, npars );
3470 for (
j = 0;
j < npars;
j++ ){
3472 gsl_vector_set(vmu,
j, (allvalues->
data[
j]-gmmmus[
i]->data[
j])/gmmsigmas[
i]->
data[
j]);
3476 gsl_vector *tmpVec = gsl_vector_calloc( npars );
3477 gsl_blas_dgemv (CblasNoTrans, 1.0, invcor[
i], vmu, 0.0, tmpVec);
3478 gsl_blas_ddot( vmu, tmpVec, &thisGauss );
3481 thisGauss += log(gmmweights->data[
i]);
3483 logPrior =
logaddexp(logPrior, thisGauss);
3485 gsl_matrix_free( invcov );
3486 gsl_matrix_free( tmpMat );
3487 gsl_vector_free( vmu );
3488 gsl_vector_free( tmpVec );
3493 for (
j = 0;
j < npars;
j++ ){
3494 sprintf(parname,
"%s_gmm_value", toks->
tokens[
j]);
3509 REAL8 min = 0.,
max = 0., lrat = 0.;
3512 if ( value < 0. || value < min || value >
max ){
return -INFINITY; }
3513 lrat = log(
max/min);
3515 return -log(value*lrat);
int XLALCheckBurstApproximantFromString(const CHAR *inString)
static REAL8 mean(REAL8 *array, int N)
#define LALINFERENCE_PRIOR_MIN(x, y)
static double outerIntegrand(double M1, void *voData)
static double qInnerIntegrand(double M2, void *viData)
UINT4 LALInferenceCubeToConstantCalibrationPrior(LALInferenceRunState *runState, LALInferenceVariables *params, INT4 *idx, double *Cube, void UNUSED *context)
REAL8 LALInferenceInspiralSkyLocPrior(LALInferenceRunState *runState, LALInferenceVariables *params, UNUSED LALInferenceModel *model)
REAL8 LALInferenceAnalyticNullPrior(LALInferenceRunState UNUSED *runState, LALInferenceVariables *params, LALInferenceModel UNUSED *model)
static REAL8 LALInferenceGlitchPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
static double etaInnerIntegrand(double M2, void *viData)
static REAL8 REAL8max(REAL8 a, REAL8 b)
UINT4 LALInferenceCubeToPSDScaleParams(LALInferenceVariables *priorParams, LALInferenceVariables *params, INT4 *idx, double *Cube, void UNUSED *context)
static REAL8 LALInferenceConstantCalibrationPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
UINT4 LALInferenceAnalyticCubeToPrior(LALInferenceRunState *runState, LALInferenceVariables *params, UNUSED LALInferenceModel *model, double *Cube, void *context)
REAL8 LALInferenceNullPrior(LALInferenceRunState UNUSED *runState, LALInferenceVariables UNUSED *params, LALInferenceModel UNUSED *model)
#define LALINFERENCE_PRIOR_SQR(x)
UINT4 LALInferenceInspiralSkyLocCubeToPrior(LALInferenceRunState *runState, LALInferenceVariables *params, UNUSED LALInferenceModel *model, double *Cube, void *context)
static REAL8 LALInferencePSDPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
static double double delta
#define XLAL_CALLGSL(statement)
void LALInferenceMcQ2Masses(double mc, double q, double *m1, double *m2)
Convert from Mc, q space to m1, m2 space (q = m2/m1, with m1 > m2).
UINT4 LALInferenceGetUINT4Variable(LALInferenceVariables *vars, const char *name)
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
Add a variable named name to vars with initial value referenced by value.
REAL8 LALInferenceGetREAL8Variable(LALInferenceVariables *vars, const char *name)
int LALInferenceEOSPhysicalCheck(LALInferenceVariables *params, ProcessParamsTable *commandLine)
Check for causality violation and mass conflict given masses and eos.
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
LALInferenceParamVaryType
An enumerated type for denoting the topology of a parameter.
INT4 LALInferenceGetINT4Variable(LALInferenceVariables *vars, const char *name)
void LALInferenceKDDrawEigenFrame(gsl_rng *rng, LALInferenceKDTree *tree, REAL8 *pt, size_t Npts)
Draws a pt uniformly from a randomly chosen cell of tree.
UINT4 LALInferenceCheckPositiveDefinite(gsl_matrix *matrix, UINT4 dim)
Check matrix is positive definite.
void LALInferenceMcEta2Masses(double mc, double eta, double *m1, double *m2)
Convert from Mc, eta space to m1, m2 space (note m1 > m2).
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
Return a pointer to the memory the variable vars is stored in specified by name User must cast this p...
void XLALMultiNormalDeviates(REAL4Vector *vector, gsl_matrix *matrix, UINT4 dim, RandomParams *randParam)
Draw a random multivariate vector from Gaussian distr given covariance matrix.
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
LALInferenceVariableType
An enumerated type for denoting the type of a variable.
LALInferenceParamVaryType LALInferenceGetVariableVaryType(LALInferenceVariables *vars, const char *name)
Get the LALInferenceParamVaryType of the parameter named name in vars see the declaration of LALInfer...
LALInferenceVariableItem * LALInferenceGetItem(const LALInferenceVariables *vars, const char *name)
Return the list node for "name" - do not rely on this.
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
Set a variable named name in vars with a value.
int LALInferenceCheckVariableNonFixed(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars and having type LINEAR or CIRCULAR.
void LALInferenceKDREAL8ToVariables(LALInferenceVariables *params, REAL8 *pt, LALInferenceVariables *templt)
Fills in the non-fixed variables in params from the given REAL8 array.
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
@ LALINFERENCE_PARAM_CIRCULAR
A parameter that simply has a maximum and a minimum.
@ LALINFERENCE_PARAM_LINEAR
@ LALINFERENCE_REAL8Vector_t
@ LALINFERENCE_void_ptr_t
@ LALINFERENCE_gslMatrix_t
void LALInferenceNetworkSNR(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
Calculate the SNR across the network.
void LALInferenceRemoveCorrelatedPrior(LALInferenceVariables *priorArgs)
Remove the correlation coefficient matrix and index for a parameter from the priorArgs list.
REAL8 LALInferenceGMMPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
Calculate the log probability for the Gaussian Mixture Model prior.
void LALInferenceAddGaussianPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *mu, REAL8 *sigma, LALInferenceVariableType type)
Function to add the mu and sigma values for the Gaussian prior onto the priorArgs.
REAL8 LALInferenceComputePriorMassNorm(const double MMin, const double MMax, const double MTotMax, const double McMin, const double McMax, const double massRatioMin, const double massRatioMax, const char *massRatioName)
Computes the numerical normalization of the mass prior applying all cuts in the mass plane implied b...
REAL8 LALInferenceInspiralPrior(LALInferenceRunState *runState, LALInferenceVariables *params, LALInferenceModel *model)
Return the logarithmic prior density of the variables specified, for the non-spinning/spinning inspir...
REAL8 LALInferenceFlatBoundedPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
Prior that checks for minimum and maximum prior range specified in runState->priorArgs and returns 0....
int LALInferenceCheckMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
Check for types of standard prior.
REAL8 LALInferenceCubeToPowerPrior(double p, double r, double x1, double x2)
Prior that converts from a Cube parameter in [0,1] to the power prior bounded by x1 and x2 with power...
void LALInferenceAddGMMPrior(LALInferenceVariables *priorArgs, const char *name, REAL8Vector ***mus, gsl_matrix ***covs, REAL8Vector **weights, REAL8Vector **minrange, REAL8Vector **maxrange)
Add a Gaussian Mixture Model prior.
void LALInferenceDrawNameFromPrior(LALInferenceVariables *output, LALInferenceVariables *priorArgs, char *name, LALInferenceVariableType type, gsl_rng *rdm)
Draw an individual variable from its prior range.
void LALInferenceAddMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max, LALInferenceVariableType type)
Function to add the minimum and maximum values for the uniform prior onto the priorArgs.
void LALInferenceInitCBCPrior(LALInferenceRunState *runState)
Initialize the prior based on command line arguments.
void LALInferenceRemoveFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the r and sigma values for the Fermi-Dirac prior onto the priorArgs.
void LALInferenceRemoveMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the minimum and maximum values for the uniform prior onto the priorArgs.
REAL8 LALInferenceCubeToLogFlatPrior(double r, double x1, double x2)
Prior that converts from a Cube parameter in [0,1] to the flat in log prior bounded by x1 and x2.
REAL8 LALInferenceSineGaussianPrior(LALInferenceRunState *runState, LALInferenceVariables *params, LALInferenceModel *model)
REAL8 LALInferenceCubeToSinPrior(double r, double x1, double x2)
Prior that converts from a Cube parameter in [0,1] to the sine prior with given min (x1) and max (x2)...
void LALInferenceAddLogUniformPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *xmin, REAL8 *xmax, LALInferenceVariableType type)
Add a log-uniform prior.
void LALInferenceRemoveGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the mu and sigma values for the Gaussian prior onto the priorArgs.
REAL8 LALInferenceLogUniformPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
void LALInferenceCyclicReflectiveBound(LALInferenceVariables *parameter, LALInferenceVariables *priorArgs)
Apply cyclic and reflective boundaries to parameter to bring it back within the allowed prior ranges ...
void LALInferenceRotateInitialPhase(LALInferenceVariables *parameter)
Rotate initial phase if polarisation angle is cyclic around ranges.
int LALInferenceCheckCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name)
Check for the existance of a correlation coefficient matrix and index for a parameter from the priorA...
void LALInferenceDrawFromPrior(LALInferenceVariables *output, LALInferenceVariables *priorArgs, gsl_rng *rdm)
Draw variables from the prior ranges.
void LALInferenceInitLIBPrior(LALInferenceRunState *runState)
Initialize the LIB prior based on command line arguments.
REAL8 LALInferenceFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 value)
Return the Fermi-Dirac distribution log prior.
int LALInferenceCheckGMMPrior(LALInferenceVariables *priorArgs, const char *name)
Check for a Gaussian Mixture Model prior.
void LALInferenceGetLogUniformPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *xmin, REAL8 *xmax)
Get the xmin and xmax values of the log-uniform prior from the priorArgs list, given a name.
void LALInferenceGetMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max)
Get the minimum and maximum values of the uniform prior from the priorArgs list, given a name.
int LALInferenceCheckGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
Check for a Gaussian prior (with a mean and variance)
void LALInferenceGetGMMPrior(LALInferenceVariables *priorArgs, const char *name, REAL8Vector ***mus, REAL8Vector ***sigmas, gsl_matrix ***cors, gsl_matrix ***invcors, REAL8Vector **weights, REAL8Vector **minrange, REAL8Vector **maxrange, REAL8Vector **dets, UINT4 *idx, CHAR **fullname)
Get the parameters defining a Gaussian Mixture Model prior.
int LALInferenceCheckFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name)
Check for a Fermi-Dirac prior (with a r and sigma parameter)
int LALInferenceCheckLogUniformPrior(LALInferenceVariables *priorArgs, const char *name)
Check for a log-uniform prior (with xmin and xmax parameters)
UINT4 within_malmquist(LALInferenceRunState *runState, LALInferenceVariables *params, LALInferenceModel *model)
void LALInferenceGetGaussianPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *mu, REAL8 *sigma)
Get the mu and sigma values of the Gaussian prior from the priorArgs list, given a name.
REAL8 LALInferenceCubeToGaussianPrior(double r, double mean, double sigma)
Prior that converts from a Cube parameter in [0,1] to the Gaussian prior with given mean and standard...
REAL8 logGlitchAmplitudeDensity(REAL8 A, REAL8 Q, REAL8 f)
Return the log Prior for the glitch amplitude.
void LALInferenceRemoveGMMPrior(LALInferenceVariables *priorArgs, const char *name)
Remove a Gaussian Mixture Model prior.
UINT4 LALInferenceInspiralCubeToPrior(LALInferenceRunState *runState, LALInferenceVariables *params, LALInferenceModel *model, double *Cube, void *context)
Convert the hypercube parameter to physical parameters, for the non-spinning/spinning inspiral signal...
void LALInferenceAddCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name, gsl_matrix **cor, REAL8 *mu, REAL8 *sigma, UINT4 *idx)
Function to add a correlation matrix and parameter index for a prior defined as part of a multivariat...
void LALInferenceRemoveLogUniformPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the min and max values for the log-uniform prior from the priorArgs.
REAL8 LALInferenceCubeToFlatPrior(double r, double x1, double x2)
Prior that converts from a Cube parameter in [0,1] to the flat prior bounded by x1 and x2.
void LALInferenceAddFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *sigma, REAL8 *r, LALInferenceVariableType type)
Add a Fermi-Dirac prior.
void LALInferenceGetCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name, gsl_matrix **cor, gsl_matrix **invcor, REAL8 *mu, REAL8 *sigma, UINT4 *idx)
Get the correlation coefficient matrix and index for a parameter from the priorArgs list.
void LALInferenceGetFermiDiracPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *sigma, REAL8 *r)
Get the r and sigma values of the Fermi-Dirac prior from the priorArgs list, given a name.
void * XLALCalloc(size_t m, size_t n)
RandomParams * XLALCreateRandomParams(INT4 seed)
void XLALDestroyRandomParams(RandomParams *params)
LALStringVector * XLALAppendString2Vector(LALStringVector *vect, const CHAR *string)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_REAL8(...)
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
static double logaddexp(double x, double y)
Structure to contain IFO data.
struct tagLALInferenceIFOData * next
ROQ data.
The kD trees in LALInference are composed of cells.
size_t dim
Size of the pts buffer.
Structure to constain a model and its parameters.
REAL8 * ifo_SNRs
Array of single-IFO likelihoods at params
REAL8 SNR
Likelihood value at params
Structure containing inference run state This includes pointers to the function types required to run...
ProcessParamsTable * commandLine
LALInferenceCubeToPriorFunction CubeToPrior
The prior for the parameters.
struct tagLALInferenceIFOData * data
Log sample, i.e.
LALInferenceVariables * priorArgs
Common arguments needed by proposals, to be copied to thread->cycle.
LALInferencePriorFunction prior
The algorithm's single iteration function.
The LALInferenceVariableItem list node structure This should only be accessed using the accessor func...
LALInferenceVariableType type
struct tagVariableItem * next
LALInferenceParamVaryType vary
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
LALInferenceVariableItem * head
CHAR value[LIGOMETA_VALUE_MAX]
gsl_function innerIntegrand
gsl_integration_workspace * wsInner