26#include <lal/LALInspiral.h>
27#include <lal/DetResponse.h>
28#include <lal/SeqFactories.h>
30#include <lal/VectorOps.h>
31#include <lal/TimeFreqFFT.h>
32#include <lal/GenerateInspiral.h>
33#include <lal/TimeDelay.h>
34#include <lal/SkyCoordinates.h>
35#include <lal/LALInference.h>
36#include <lal/LALInferenceInit.h>
37#include <lal/LALInferencePrior.h>
38#include <lal/LALInferenceLikelihood.h>
39#include <lal/LALInferenceTemplate.h>
40#include <lal/LALInferenceProposal.h>
41#include <lal/LALDatatypes.h>
42#include <lal/FrequencySeries.h>
43#include <lal/LALSimInspiral.h>
44#include <lal/LALSimNoise.h>
45#include <lal/XLALError.h>
47#include <lal/LALStdlib.h>
48#include <lal/LALInferenceClusteredKDE.h>
49#include <lal/LALInferenceNestedSampler.h>
52#define UNUSED __attribute__ ((unused))
97static const char *
intrinsicNames[] = {
"chirpmass",
"q",
"eta",
"mass1",
"mass2",
"a_spin1",
"a_spin2",
"tilt_spin1",
"tilt_spin2",
"phi12",
"phi_jl",
"frequency",
"quality",
"duration",
"polar_angle",
"phase",
"polar_eccentricity",
"dchiMinus2",
"dchiMinus1",
"dchi0",
"dchi1",
"dchi2",
"dchi3",
"dchi3S",
"dchi3NS",
"dchi4",
"dchi4S",
"dchi4NS",
"dchi5",
"dchi5S",
"dchi5NS",
"dchi5l",
"dchi5lS",
"dchi5lNS",
"dchi6",
"dchi6S",
"dchi6NS",
"dchi6l",
"dchi7",
"dchi7S",
"dchi7NS",
"aPPE",
"alphaPPE",
"bPPE",
"betaPPE",
"betaStep",
"fStep",
"dxi1",
"dxi2",
"dxi3",
"dxi4",
"dxi5",
"dxi6",
"dalpha1",
"dalpha2",
"dalpha3",
"dalpha4",
"dalpha5",
"dbeta1",
"dbeta2",
"dbeta3",
"dsigma1",
"dsigma2",
"dsigma3",
"dsigma4",
"lambda1",
"lambda2",
"lambdaT",
"dlambdaT",
"logp1",
"gamma1",
"gamma2",
"gamma3",
"SDgamma0",
"SDgamma1",
"SDgamma2",
"SDgamma3",
"log10lambda_eff",
"lambda_eff",
"nonGR_alpha",
"LIV_A_sign",
"dQuadMon1",
"dQuadMon2",
"dQuadMonA",
"dQuadMonS",
"dchikappaS",
"dchikappaA",
"domega220",
"dtau220",
"domega210",
"dtau210",
"domega330",
"dtau330",
"domega440",
"dtau440",
"domega550",
"dtau550",
"db1",
"db2",
"db3",
"db4",
"dc1",
"dc2",
"dc4",
"dcl",
"damp21",
"damp33",NULL};
99static const char *
extrinsicNames[] = {
"rightascension",
"declination",
"cosalpha",
"azimuth",
"polarisation",
"distance",
100 "logdistance",
"time",
"costheta_jn",
"t0",
"theta",
"hrss",
"loghrss", NULL};
105 for (
i = 0;
i < 3;
i++) {
118 for (currentIFO =
data; currentIFO; currentIFO = currentIFO->
next) {
121 for (subsequentIFO = currentIFO->
next; subsequentIFO; subsequentIFO = subsequentIFO->
next) {
129 return nIFO - nCollision;
147 sprintf(offopt,
"--proposal-no-%s",
name);
148 sprintf(onopt,
"--proposal-%s",
name);
159 const char *fname =
"LALInferenceAddProposalToCycle";
167 if (cycle->
order == NULL) {
172 for (
i = cycle->
length; i < cycle->length + weight;
i++) {
192 for (
i = cycle->
length - 1;
i > 0;
i--) {
194 j = gsl_rng_uniform_int(rng,
i+1);
210 cycle = thread->
cycle;
224 REAL8 logPropRatio=-INFINITY;
233 while (proposedParams->
head == NULL);
261 INT4 cyclic_reflective_kde = 0;
265 INT4 singleadapt = 1;
331 INT4 marg_timephi = 0;
345 INT4 analytic_test = 0;
362 INT4 adapting = !noAdapt;
372 INT4 sampling_prior = 0;
398 cyclic_reflective_kde = 1;
428 if (nUniqueDet < 2) {
432 if (nUniqueDet != 3) {
436 if (nUniqueDet >= 3) {
484 const INT4 BIGWEIGHT = 20;
485 const INT4 SMALLWEIGHT = 5;
486 const INT4 TINYWEIGHT = 1;
600 REAL8 logPropRatio, sqrttemp,
mu, sigma;
616 varNr = 1 + gsl_rng_uniform_int(rng, dim);
621 fprintf(stderr,
"Attempting to set non-REAL8 parameter with numerical sigma (in %s, %d)\n",
628 fprintf(stderr,
"Attempting to draw single-parameter jump for %s but cannot find sigma!\nError in %s, line %d.\n",
629 param->
name,__FILE__, __LINE__);
639 if (sqrttemp == INFINITY) {
643 *((
REAL8 *)param->
value) += gsl_ran_ugaussian(rng) * sigma;
648 *((
REAL8 *)param->
value) += gsl_ran_ugaussian(rng) * (
max - min);
651 *((
REAL8 *)param->
value) += gsl_ran_ugaussian(rng) * sigma * sqrttemp;
677 REAL8 sigma, big_sigma;
685 if (gsl_ran_ugaussian(GSLrandom) < 1.0e-3)
687 if (gsl_ran_ugaussian(GSLrandom) < 1.0e-4)
693 varNr = 1 + gsl_rng_uniform_int(GSLrandom, dim);
699 if (!strcmp(param->
name,
"eta")) {
701 }
else if (!strcmp(param->
name,
"q")) {
703 }
else if (!strcmp(param->
name,
"chirpmass")) {
705 }
else if (!strcmp(param->
name,
"time")) {
707 }
else if (!strcmp(param->
name,
"t0")) {
709 }
else if (!strcmp(param->
name,
"phase")) {
711 }
else if (!strcmp(param->
name,
"distance")) {
713 }
else if (!strcmp(param->
name,
"declination")) {
715 }
else if (!strcmp(param->
name,
"azimuth")) {
717 }
else if (!strcmp(param->
name,
"cosalpha")) {
719 }
else if (!strcmp(param->
name,
"rightascension")) {
721 }
else if (!strcmp(param->
name,
"polarisation")) {
723 }
else if (!strcmp(param->
name,
"costheta_jn")) {
725 }
else if (!strcmp(param->
name,
"a_spin1")) {
727 }
else if (!strcmp(param->
name,
"a_spin2")) {
730 fprintf(stderr,
"Could not find parameter %s!", param->
name);
734 *(
REAL8 *)param->
value += gsl_ran_ugaussian(GSLrandom)*sigma;
736 if (!strcmp(param->
name,
"eta") || !strcmp(param->
name,
"q") || !strcmp(param->
name,
"time") || !strcmp(param->
name,
"t0") || !strcmp(param->
name,
"a_spin2") || !strcmp(param->
name,
"a_spin1")){
737 *(
REAL8 *)param->
value += gsl_ran_ugaussian(GSLrandom)*big_sigma*sigma*0.001;
738 }
else if (!strcmp(param->
name,
"polarisation") || !strcmp(param->
name,
"phase") || !strcmp(param->
name,
"costheta_jn")){
739 *(
REAL8 *)param->
value += gsl_ran_ugaussian(GSLrandom)*big_sigma*sigma*0.1;
741 *(
REAL8 *)param->
value += gsl_ran_ugaussian(GSLrandom)*big_sigma*sigma*0.01;
748 REAL8 logPropRatio = 0.0;
759 gsl_matrix *eigenvectors;
760 REAL8 jumpSize, tmp, inc;
761 REAL8 logPropRatio = 0.0;
774 i = gsl_rng_uniform_int(rng,
N);
775 jumpSize = sqrt(thread->
temperature * eigenvalues->
data[
i]) * gsl_ran_ugaussian(rng);
778 proposeIterator = proposedParams->
head;
779 if (proposeIterator == NULL) {
780 fprintf(stderr,
"Bad proposed params in %s, line %d\n",
789 inc = jumpSize * gsl_matrix_get(eigenvectors,
j,
i);
797 }
while ((proposeIterator = proposeIterator->
next) != NULL &&
j <
N);
809 REAL8 one_deg = 1.0 / (2.0*M_PI);
810 REAL8 logPropRatio = 0.0;
817 jumpX = sigma * gsl_ran_ugaussian(rng);
818 jumpY = sigma * gsl_ran_ugaussian(rng);
824 newDEC =
DEC + jumpY;
870 const char **names) {
871 size_t i,
N, Ndim, nPts;
873 REAL8 maxScale, Y, logmax, X, scale;
880 const char* local_names[
N];
886 while (item != NULL) {
897 for(Ndim=0,
i=0;
names[
i] != NULL;
i++ ) {
905 for(Ndim=0,
i=0;
names[
i] != NULL;
i++ ) {
913 if (dePts == NULL || nPts <= 1) {
920 i = gsl_rng_uniform_int(thread->
GSLrandom, nPts);
933 logmax = log(maxScale);
934 X = 2.0*logmax*Y - logmax;
937 for (
i = 0;
names[
i] != NULL;
i++) {
943 x = other + scale*(cur-other);
949 if (scale < maxScale && scale > (1.0/maxScale))
950 logPropRatio = log(scale)*((
REAL8)Ndim);
952 logPropRatio = -INFINITY;
983 const char **names) {
986 REAL8 logPropRatio = 0.0;
989 const char* local_names[
N];
995 while (item != NULL) {
1017 size_t sample_size=3;
1022 if (dePts == NULL || nPts <= 1) {
1024 return logPropRatio;
1029 UINT4 indices[sample_size];
1030 UINT4 all_indices[nPts];
1032 for (
i=0;
i<nPts;
i++) all_indices[
i]=
i;
1033 gsl_ran_choose(thread->
GSLrandom,indices, sample_size, all_indices, nPts,
sizeof(
UINT4));
1036 double univariate_normals[sample_size];
1037 for(
i=0;
i<sample_size;
i++) univariate_normals[
i] = gsl_ran_ugaussian(thread->
GSLrandom);
1043 REAL8 centre_of_mass=0.0;
1045 for(
i=0;
i<sample_size;
i++)
1050 for(
i=0,
w=0.0;
i<sample_size;
i++)
1060 return logPropRatio;
1066 const char **names) {
1067 size_t i,
j,
N, Ndim, nPts;
1071 REAL8 logPropRatio = 0.0;
1074 const char *localnames[
N];
1078 if (
names == NULL) {
1081 while (item != NULL) {
1083 localnames[
i] = item->
name;
1094 for (Ndim=0,
i=0;
names[
i] != NULL;
i++ ) {
1102 if (dePts == NULL || nPts <= 1)
1103 return logPropRatio;
1108 i = gsl_rng_uniform_int(rng, nPts);
1110 j = gsl_rng_uniform_int(rng, nPts);
1116 const REAL8 modeHoppingFrac = 0.5;
1119 if (gsl_rng_uniform(rng) < modeHoppingFrac) {
1124 scale = 2.38/sqrt(Ndim) * exp(log(0.1) + log(100.0) * gsl_rng_uniform(rng));
1127 for (
i = 0;
names[
i] != NULL;
i++) {
1140 return logPropRatio;
1163 return cbrt(
x*(dmax*dmax*dmax - dmin*dmin*dmin) + dmin*dmin*dmin);
1167 REAL8 logdmin, logdmax;
1171 REAL8 dmin=exp(logdmin);
1172 REAL8 dmax=exp(logdmax);
1176 return log(cbrt(
x*(dmax*dmax*dmax - dmin*dmin*dmin) + dmin*dmin*dmin));
1186 return acos(cos(min) -
x*(cos(min) - cos(
max)));
1196 return asin(
x*(sin(
max) - sin(min)) + sin(min));
1206 return min +
x*(
max - min);
1215 mMin56 = pow(min, 5.0/6.0);
1216 mMax56 = pow(
max, 5.0/6.0);
1218 delta = 1.0/mMin56 - 1.0/mMax56;
1222 return pow(1.0/(1.0/mMin56 -
u), 6.0/5.0);
1230 logP += -11.0/6.0*log(Mc);
1264 INT4 analytic_test,
i;
1265 REAL8 logBackwardJump = 0.0;
1271 const char *flat_params[] = {
"q",
"eta",
"t0",
"azimuth",
"cosalpha",
"time",
"phase",
"polarisation",
1272 "rightascension",
"costheta_jn",
"phi_jl",
1273 "phi12",
"a_spin1",
"a_spin2",
"logp1",
"gamma1",
"gamma2",
"gamma3",
1274 "SDgamma0",
"SDgamma1",
"SDgamma2",
"SDgamma3", NULL};
1280 if (analytic_test) {
1292 for (
i = 0; flat_params[
i] != NULL;
i++) {
1339 gsl_matrix_set(
eta,
i,
j,
x);
1345 if (analytic_test) {
1352 return logPropRatio;
1356 REAL8 logPropRatio = 0., tmp = 0.;
1369 return logPropRatio;
1373 x[0] =
y[1]*z[2]-
y[2]*z[1];
1374 x[1] =
y[2]*z[0]-
y[0]*z[2];
1375 x[2] =
y[0]*z[1]-
y[1]*z[0];
1379 return sqrt(
x[0]*
x[0] +
x[1]*
x[1] +
x[2]*
x[2]);
1396 return v[0]*
w[0] + v[1]*
w[1] + v[2]*
w[2];
1406 vproj[0] = what[0]*vdotw;
1407 vproj[1] = what[1]*vdotw;
1408 vproj[2] = what[2]*vdotw;
1412 diff[0] =
w[0] - v[0];
1413 diff[1] =
w[1] - v[1];
1414 diff[2] =
w[2] - v[2];
1419 REAL8 n[3], nhat[3], xy[3], xz[3],
pn[3], pnperp[3];
1446 cart[0] = cos(longi)*cos(lat);
1447 cart[1] = sin(longi)*cos(lat);
1452 *longi = atan2(cart[1], cart[0]);
1453 *lat = asin(cart[2] / sqrt(cart[0]*cart[0] + cart[1]*cart[1] + cart[2]*cart[2]));
1460 SkyPosition currentEqu, currentGeo, newEqu, newGeo;
1464 REAL8 currentLoc[3], newLoc[3];
1465 REAL8 newGeoLat, newGeoLongi;
1519 *newTime = oldTime + oldDt - newDt;
1528 REAL8 component_min,component_max;
1530 gsl_matrix *glitch_f, *glitch_Q, *glitch_A;
1534 prior -= log(component_max - component_min);
1538 prior -= log(component_max - component_min);
1542 prior -= log(component_max - component_min);
1546 prior -= log(component_max - component_min);
1553 A = gsl_matrix_get(glitch_A, ifo,
k);
1554 Q = gsl_matrix_get(glitch_Q, ifo,
k);
1555 f = gsl_matrix_get(glitch_f, ifo,
k);
1568 REAL8 SNRPEAK = 5.0;
1579 SNR = 20.0 * SNRPEAK * gsl_rng_uniform(
r);
1581 den = SNR/(SNRPEAK*SNRPEAK) * exp(-SNR/SNRPEAK);
1585 alpha = gsl_rng_uniform(
r);
1586 }
while (
alpha > den);
1588 return SNR/sqrt((PIterm*
Q/f));
1595 INT4 ifo, nifo, timeflag=0;
1596 REAL8 logPropRatio = 0.0;
1598 REAL8 baryTime, gmst;
1599 REAL8 newRA, newDec, newTime, newPsi;
1600 REAL8 intpart, decpart;
1601 REAL8 omega, cosomega, sinomega, c1momega;
1602 REAL8 IFO1[3], IFO2[3];
1605 REAL8 pForward, pReverse;
1635 intpart = (
INT4)gmst;
1636 decpart = gmst - (
REAL8)intpart;
1638 gmst = gmst < 0. ? gmst +
LAL_TWOPI : gmst;
1643 k[0] = cos(gmst-ra) * cos(dec);
1644 k[1] =-sin(gmst-ra) * cos(dec);
1652 IFO = gsl_matrix_alloc(nifo, 3);
1654 for(ifo=0; ifo<nifo; ifo++) {
1657 gsl_matrix_set(IFO, ifo,
i, IFOX[
i]);
1666 i=gsl_rng_uniform_int(rng, nifo);
1667 j=gsl_rng_uniform_int(rng, nifo);
1670 for(
l=0;
l<3;
l++) {
1671 IFO1[
l] = gsl_matrix_get(IFO,
i,
l);
1672 IFO2[
l] = gsl_matrix_get(IFO,
j,
l);
1679 for(
i=0;
i<3;
i++) {
1680 n[
i] = IFO1[
i] - IFO2[
i];
1681 normalize +=
n[
i] *
n[
i];
1683 normalize = 1./sqrt(normalize);
1690 omega =
LAL_TWOPI * gsl_rng_uniform(rng);
1691 cosomega = cos(omega);
1692 sinomega = sin(omega);
1693 c1momega = 1.0 - cosomega;
1698 kp[0] = (c1momega*
n[0]*
n[0] + cosomega) *
k[0]
1699 + (c1momega*
n[0]*
n[1] - sinomega*
n[2]) *
k[1]
1700 + (c1momega*
n[0]*
n[2] + sinomega*
n[1]) *
k[2];
1701 kp[1] = (c1momega*
n[0]*
n[1] + sinomega*
n[2]) *
k[0]
1702 + (c1momega*
n[1]*
n[1] + cosomega) *
k[1]
1703 + (c1momega*
n[1]*
n[2] - sinomega*
n[0]) *
k[2];
1704 kp[2] = (c1momega*
n[0]*
n[2] - sinomega*
n[1]) *
k[0]
1705 + (c1momega*
n[1]*
n[2] + sinomega*
n[0]) *
k[1]
1706 + (c1momega*
n[2]*
n[2] + cosomega) *
k[2];
1711 newDec = asin(kp[2]);
1712 newRA = atan2(kp[1], kp[0]) + gmst;
1724 for(
i=0;
i<3;
i++) {
1728 newTime = tx + baryTime - ty;
1737 newPsi =
LAL_PI * gsl_rng_uniform(rng);
1745 pForward = cos(newDec);
1746 pReverse = cos(dec);
1748 gsl_matrix_free(IFO);
1750 logPropRatio = log(pReverse/pForward);
1754 return logPropRatio;
1761 REAL8 ra, dec, baryTime;
1762 REAL8 newRA, newDec, newTime;
1763 REAL8 nRA, nDec, nTime;
1764 REAL8 refRA, refDec, refTime;
1765 REAL8 nRefRA, nRefDec, nRefTime;
1766 REAL8 pForward, pReverse;
1767 REAL8 logPropRatio = 0.0;
1775 static INT4 warningDelivered = 0;
1783 if (nUniqueDet != 3) {
1784 if (!warningDelivered) {
1785 fprintf(stderr,
"WARNING: trying to reflect through the decector plane with %d\n", nUniqueDet);
1786 fprintf(stderr,
"WARNING: geometrically independent locations,\n");
1787 fprintf(stderr,
"WARNING: but this proposal should only be used with exactly 3 independent detectors.\n");
1788 fprintf(stderr,
"WARNING: %s, line %d\n", __FILE__, __LINE__);
1789 warningDelivered = 1;
1792 return logPropRatio;
1809 const REAL8 epsTime = 6
e-6;
1810 const REAL8 epsAngle = 3
e-4;
1812 nRA = gsl_ran_ugaussian(rng);
1813 nDec = gsl_ran_ugaussian(rng);
1814 nTime = gsl_ran_ugaussian(rng);
1816 newRA += epsAngle*nRA;
1817 newDec += epsAngle*nDec;
1818 newTime += epsTime*nTime;
1826 nRefRA = (ra - refRA)/epsAngle;
1827 nRefDec = (dec - refDec)/epsAngle;
1828 nRefTime = (baryTime - refTime)/epsTime;
1830 pForward = gsl_ran_ugaussian_pdf(nRA) * gsl_ran_ugaussian_pdf(nDec) * gsl_ran_ugaussian_pdf(nTime);
1831 pReverse = gsl_ran_ugaussian_pdf(nRefRA) * gsl_ran_ugaussian_pdf(nRefDec) * gsl_ran_ugaussian_pdf(nRefTime);
1839 logPropRatio = log(pReverse/pForward);
1841 return logPropRatio;
1850 REAL8 logPropRatio = 0.0;
1866 for(
i=0;
i<nifo;
i++) {
1867 for(
j=0;
j<
N;
j++) {
1868 draw = gsl_matrix_get(
ny,
i,
j) + gsl_ran_ugaussian(thread->
GSLrandom) * var->
data[
j];
1869 gsl_matrix_set(
ny,
i,
j, draw);
1873 return logPropRatio;
1881 INT4 glitchLower, glitchUpper;
1886 REAL8 amparg, phiarg, Ai;
1889 gsl_matrix *glitch_f, *glitch_Q, *glitch_A;
1890 gsl_matrix *glitch_t, *glitch_p;
1920 Q = gsl_matrix_get(glitch_Q, ifo,
n);
1921 Amp = gsl_matrix_get(glitch_A, ifo,
n);
1922 t0 = gsl_matrix_get(glitch_t, ifo,
n);
1923 ph0 = gsl_matrix_get(glitch_p, ifo,
n);
1924 f0 = gsl_matrix_get(glitch_f, ifo,
n);
1928 glitchLower = (
INT4)floor((f0 - 1./tau)/
deltaF);
1929 glitchUpper = (
INT4)floor((f0 + 1./tau)/
deltaF);
1933 for(
i=lower;
i<=upper;
i++) {
1934 gsl_matrix_set(glitchFD, ifo, 2*
i, 0.0);
1935 gsl_matrix_set(glitchFD, ifo, 2*
i+1, 0.0);
1939 for (
i=glitchLower;
i<glitchUpper;
i++) {
1940 if (
i>=lower &&
i<=upper) {
1941 gRe = gsl_matrix_get(glitchFD, ifo, 2*
i);
1942 gIm = gsl_matrix_get(glitchFD, ifo, 2*
i+1);
1945 Ai = Amp*tau*0.5*sqrt(
LAL_PI)*exp(-amparg*amparg)*asd->
data->
data[
i]/sqrt(Tobs);
1950 gRe -= Ai*cos(phiarg);
1951 gIm -= Ai*sin(phiarg);
1955 gRe += Ai*cos(phiarg);
1956 gIm += Ai*sin(phiarg);
1960 gRe = Ai*cos(phiarg);
1961 gIm = Ai*sin(phiarg);
1969 gsl_matrix_set(glitchFD, ifo, 2*
i, gRe);
1970 gsl_matrix_set(glitchFD, ifo, 2*
i+1, gIm);
1988 REAL8 sqrt3 = 1.7320508;
1997 if(SNR < 5.0) SNR = 5.0;
2000 sigma_f0 = 2.0*f0/(
Q*SNR);
2001 sigma_Q = 2.0*
Q/(sqrt3*SNR);
2002 sigma_Amp = Amp/SNR;
2003 sigma_phi0 = 1.0/SNR;
2006 sigmas->
data[0] = sigma_t0;
2007 sigmas->
data[1] = sigma_f0;
2008 sigmas->
data[2] = sigma_Q;
2009 sigmas->
data[3] = sigma_Amp;
2010 sigmas->
data[4] = sigma_phi0;
2019 REAL8 logPropRatio = 0.0;
2034 gsl_matrix *glitchFD, *glitch_f, *glitch_Q, *glitch_A, *glitch_t, *glitch_p;
2068 if (gsize->
data[ifo]==0) {
2074 return logPropRatio;
2078 n = (
INT4)floor(gsl_rng_uniform(rng) * (
REAL8)(gsize->
data[ifo]));
2084 t0 = gsl_matrix_get(glitch_t, ifo,
n);
2085 f0 = gsl_matrix_get(glitch_f, ifo,
n);
2086 Q = gsl_matrix_get(glitch_Q, ifo,
n);
2087 Amp = gsl_matrix_get(glitch_A, ifo,
n);
2088 phi0 = gsl_matrix_get(glitch_p, ifo,
n);
2093 params_x->
data[1] = f0;
2094 params_x->
data[2] =
Q;
2095 params_x->
data[3] = Amp * (0.25*Anorm);
2096 params_x->
data[4] = phi0;
2104 params_y->
data[
i] = params_x->
data[
i] + gsl_ran_ugaussian(rng)*sigmas_x->
data[
i]*scale;
2109 f0 = params_y->
data[1];
2110 Q = params_y->
data[2];
2111 Amp = params_y->
data[3]/(0.25*Anorm);
2112 phi0 = params_y->
data[4];
2114 gsl_matrix_set(glitch_t, ifo,
n,
t0);
2115 gsl_matrix_set(glitch_f, ifo,
n, f0);
2116 gsl_matrix_set(glitch_Q, ifo,
n,
Q);
2117 gsl_matrix_set(glitch_A, ifo,
n, Amp);
2118 gsl_matrix_set(glitch_p, ifo,
n, phi0);
2134 for(
i=0;
i<5;
i++) {
2148 qyx = eyx - log(nyx);
2149 qxy = exy - log(nxy);
2151 logPropRatio = qxy-qyx;
2159 return logPropRatio;
2170 REAL8 t=0, f=0,
Q=0, A=0;
2175 REAL8 pForward = 0.0;
2176 REAL8 pReverse = 0.0;
2177 REAL8 logPropRatio = 0.0;
2179 gsl_matrix *
params = NULL;
2200 draw = gsl_rng_uniform(rng);
2210 if(ny<nmin || ny>=nmax) {
2211 logPropRatio = -INFINITY;
2212 return logPropRatio;
2219 t =
draw_flat(thread,
"morlet_t0_prior");
2220 f =
draw_flat(thread,
"morlet_f0_prior");
2224 gsl_matrix_set(
params, ifo,
nx, t);
2228 gsl_matrix_set(
params, ifo,
nx, f);
2232 val =
draw_flat(thread,
"morlet_Q_prior");
2233 gsl_matrix_set(
params, ifo,
nx, val);
2242 gsl_matrix_set(
params, ifo,
nx, A);
2246 val =
draw_flat(thread,
"morlet_phi_prior");
2247 gsl_matrix_set(
params, ifo,
nx, val);
2266 draw = gsl_rng_uniform(rng);
2274 f = gsl_matrix_get(
params, ifo,
n);
2276 t = gsl_matrix_get(
params, ifo,
n);
2278 Q = gsl_matrix_get(
params, ifo,
n);
2280 A = gsl_matrix_get(
params, ifo,
n);
2285 gsl_matrix_set(
params, ifo,
i, gsl_matrix_get(
params, ifo,
i+1));
2287 gsl_matrix_set(
params, ifo,
i, gsl_matrix_get(
params, ifo,
i+1));
2289 gsl_matrix_set(
params, ifo,
i, gsl_matrix_get(
params, ifo,
i+1));
2291 gsl_matrix_set(
params, ifo,
i, gsl_matrix_get(
params, ifo,
i+1));
2293 gsl_matrix_set(
params, ifo,
i, gsl_matrix_get(
params, ifo,
i+1));
2319 pForward = qxy + qx;
2320 pReverse = qyx + qy;
2322 logPropRatio = pForward-pReverse;
2324 return logPropRatio;
2330 REAL8 logPropRatio = 0.0;
2340 phi = fmod(phi, 2.0*M_PI);
2341 psi = fmod(psi, M_PI);
2346 return logPropRatio;
2355 REAL8 logPropRatio = 0.0;
2371 draw = gsl_rng_uniform(rng);
2378 psi = (
alpha + beta)*0.5;
2379 phi = (
alpha - beta)*0.5;
2387 return logPropRatio;
2395 REAL8 logPropRatio = 0.0;
2402 plusminus = gsl_rng_uniform(thread->
GSLrandom);
2403 if ( plusminus < 0.5 )
2410 return logPropRatio;
2420 REAL8 gmst, newGmst;
2421 REAL8 cosIota, cosIota2;
2422 REAL8 Fplus, Fcross, psi_temp;
2423 REAL8 x[4],
y[4], x2[4], y2[4];
2424 REAL8 newFplus[4], newFplus2[4], newFcross[4], newFcross2[4];
2426 REAL8 cosnewIota, cosnewIota2;
2428 INT4 nUniqueDet, det;
2444 cosIota = cos(iota);
2445 cosIota2 = cosIota*cosIota;
2449 for (det=0; det < nUniqueDet; det++) {
2464 y2[
i]=Fcross*Fcross;
2467 R2[
i] = (((1.0+cosIota2)*(1.0+cosIota2))/(4.0*dist2))*Fplus*Fplus
2468 + ((cosIota2)/(dist2))*Fcross*Fcross;
2473 a = (R2[3]*x2[2]*y2[1] - R2[2]*x2[3]*y2[1] - R2[3]*x2[1]*y2[2] + R2[1]*x2[3]*y2[2] + R2[2]*x2[1]*y2[3] -
2476 b = (-(R2[3]*
x[1]*x2[2]*
y[1]) + R2[2]*
x[1]*x2[3]*
y[1] + R2[3]*x2[1]*
x[2]*
y[2] - R2[1]*
x[2]*x2[3]*
y[2] +
2477 R2[3]*
x[2]*y2[1]*
y[2] - R2[3]*
x[1]*
y[1]*y2[2] - R2[2]*x2[1]*
x[3]*
y[3] + R2[1]*x2[2]*
x[3]*
y[3] - R2[2]*
x[3]*y2[1]*
y[3] + R2[1]*
x[3]*y2[2]*
y[3] +
2478 R2[2]*
x[1]*
y[1]*y2[3] - R2[1]*
x[2]*
y[2]*y2[3]);
2480 (*newPsi) = (2.*atan((b -
a*sqrt((
a2 + b*b)/(
a2)))/
a))/4.;
2482 while ((*newPsi)<0){
2483 (*newPsi)=(*newPsi)+
LAL_PI/4.0;
2486 while ((*newPsi)>
LAL_PI/4.0){
2487 (*newPsi)=(*newPsi)-
LAL_PI/4.0;
2490 for (
i = 1;
i < 4;
i++){
2491 newFplus[
i] =
x[
i]*cos(2.0*(*newPsi)) +
y[
i]*sin(2.0*(*newPsi));
2492 newFplus2[
i] = newFplus[
i] * newFplus[
i];
2494 newFcross[
i] =
y[
i]*cos(2.0*(*newPsi)) -
x[
i]*sin(2.0*(*newPsi));
2495 newFcross2[
i] = newFcross[
i] * newFcross[
i];
2498 c12 = -2.0*((R2[1]*(newFcross2[2])-R2[2]*(newFcross2[1]))
2499 /(R2[1]*(newFplus2[2])-R2[2]*(newFplus2[1])))-1.0;
2502 c12 = (3.0-c12)/(1.0+c12);
2503 (*newPsi) = (*newPsi)+
LAL_PI/4.0;
2505 for (
i = 1;
i < 4;
i++){
2506 newFplus[
i] =
x[
i]*cos(2.0*(*newPsi)) +
y[
i]*sin(2.0*(*newPsi));
2507 newFplus2[
i] = newFplus[
i] * newFplus[
i];
2509 newFcross[
i] =
y[
i]*cos(2.0*(*newPsi)) -
x[
i]*sin(2.0*(*newPsi));
2510 newFcross2[
i] = newFcross[
i] * newFcross[
i];
2520 cosnewIota2 = c12-sqrt(c12*c12-1.0);
2521 cosnewIota = sqrt(cosnewIota2);
2522 *newIota = acos(cosnewIota);
2525 ((((1.0+cosnewIota2)*(1.0+cosnewIota2))/(4.0))*newFplus2[1]
2526 + (cosnewIota2)*newFcross2[1])
2529 if (Fplus*newFplus[3]<0){
2530 (*newPsi)=(*newPsi)+
LAL_PI/2.;
2531 newFcross[3]=-newFcross[3];
2534 if (Fcross*cosIota*cosnewIota*newFcross[3]<0){
2535 (*newIota)=
LAL_PI-(*newIota);
2567 REAL8 d_inner_h = MatchedFilterSNR * OptimalSNR;
2570 REAL8 xmean = d_inner_h/(OptimalSNR*OptimalSNR*old_d);
2571 REAL8 xsigma = 1.0/(OptimalSNR*old_d);
2572 REAL8 old_x = 1.0/old_d;
2577 new_x = xmean + gsl_ran_gaussian(thread->
GSLrandom,xsigma);
2578 REAL8 new_d = 1.0/new_x;
2582 OptimalSNR *= new_x / old_x;
2586 const char *ifonames[5]={
"H1",
"L1",
"V1",
"I1",
"J1"};
2590 sprintf(pname,
"%s_optimal_snr",ifonames[
i]);
2607 logxdjac = 2.0*log(new_d) - 2.0*log(old_d);
2618 REAL8 new_logd = log(new_d);
2620 logxdjac = log(new_d) - log(old_d);
2624 REAL8 log_p_reverse = -0.5*(old_x-xmean)*(old_x-xmean)/(xsigma*xsigma);
2625 REAL8 log_p_forward = -0.5*(new_x-xmean)*(new_x-xmean)/(xsigma*xsigma);
2627 return(log_p_reverse - log_p_forward + logxdjac);
2639 REAL8 newRA, newDec, newTime, newDist, newIota, newPsi;
2640 REAL8 nRA, nDec, nTime, nDist, nIota, nPsi;
2641 REAL8 refRA, refDec, refTime, refDist, refIota, refPsi;
2642 REAL8 nRefRA, nRefDec, nRefTime, nRefDist, nRefIota, nRefPsi;
2643 REAL8 pForward, pReverse;
2646 REAL8 logPropRatio = 0.0;
2650 static INT4 warningDelivered = 0;
2659 if (nUniqueDet != 3) {
2660 if (!warningDelivered) {
2661 fprintf(stderr,
"WARNING: trying to reflect through the decector plane with %d\n", nUniqueDet);
2662 fprintf(stderr,
"WARNING: geometrically independent locations,\n");
2663 fprintf(stderr,
"WARNING: but this proposal should only be used with exactly 3 independent detectors.\n");
2664 fprintf(stderr,
"WARNING: %s, line %d\n", __FILE__, __LINE__);
2665 warningDelivered = 1;
2668 return logPropRatio;
2686 fprintf(stderr,
"LALInferenceExtrinsicParamProposal: No theta_jn parameter!\n");
2692 reflected_extrinsic_parameters(thread, ra, dec, baryTime,
dist, iota, psi, &newRA, &newDec, &newTime, &newDist, &newIota, &newPsi);
2695 const REAL8 epsDist = 1
e-8;
2696 const REAL8 epsTime = 1
e-8;
2697 const REAL8 epsAngle = 1
e-8;
2699 nRA = gsl_ran_ugaussian(rng);
2700 nDec = gsl_ran_ugaussian(rng);
2701 nTime = gsl_ran_ugaussian(rng);
2702 nDist = gsl_ran_ugaussian(rng);
2703 nIota = gsl_ran_ugaussian(rng);
2704 nPsi = gsl_ran_ugaussian(rng);
2706 newRA += epsAngle*nRA;
2707 newDec += epsAngle*nDec;
2708 newTime += epsTime*nTime;
2709 newDist += epsDist*nDist;
2710 newIota += epsAngle*nIota;
2711 newPsi += epsAngle*nPsi;
2715 reflected_extrinsic_parameters(thread, newRA, newDec, newTime, newDist, newIota, newPsi, &refRA, &refDec, &refTime, &refDist, &refIota, &refPsi);
2719 nRefRA = (ra - refRA)/epsAngle;
2720 nRefDec = (dec - refDec)/epsAngle;
2721 nRefTime = (baryTime - refTime)/epsTime;
2722 nRefDist = (
dist - refDist)/epsDist;
2723 nRefIota = (iota - refIota)/epsAngle;
2724 nRefPsi = (psi - refPsi)/epsAngle;
2726 cst = log(1./(sqrt(2.*
LAL_PI)));
2727 pReverse = 6*cst-0.5*(nRefRA*nRefRA+nRefDec*nRefDec+nRefTime*nRefTime+nRefDist*nRefDist+nRefIota*nRefIota+nRefPsi*nRefPsi);
2728 pForward = 6*cst-0.5*(nRA*nRA+nDec*nDec+nTime*nTime+nDist*nDist+nIota*nIota+nPsi*nPsi);
2735 REAL8 logNewDist = log(newDist);
2738 REAL8 newcosIota = cos(newIota);
2742 logPropRatio = pReverse - pForward;
2744 return logPropRatio;
2754 REAL8FFTPlan **plans;
2764 plans =
XLALCalloc(nDet,
sizeof(REAL8FFTPlan *));
2766 for (
i=0;
i<nDet;
i++) {
2770 asds[
i] =
data->noiseASD;
2771 psds[
i] =
data->oneSidedNoisePowerSpectrum;
2773 td_data[
i] =
data->timeData;
2774 fd_data[
i] =
data->freqData;
2776 plans[
i] =
data->freqToTimeFFTPlan;
2793 INT4 no_adapt, adapting;
2794 INT4 adaptTau, adaptableStep, adaptLength, adaptResetBuffer;
2795 REAL8 sigma, s_gamma;
2796 REAL8 logPAtAdaptStart = -INFINITY;
2800 for(
this=
params->head;
this;
this=this->next) {
2802 char *
name = this->name;
2804 if (!strcmp(
name,
"eta") || !strcmp(
name,
"q") || !strcmp(
name,
"time") || !strcmp(
name,
"a_spin2") || !strcmp(
name,
"a_spin1") || !strcmp(
name,
"t0")){
2806 }
else if (!strcmp(
name,
"polarisation") || !strcmp(
name,
"phase") || !strcmp(
name,
"costheta_jn")){
2827 adapting = !no_adapt;
2835 adaptLength = pow(10, adaptTau);
2836 adaptResetBuffer = 100;
2886 INT4 adaptableStep = 0;
2888 REAL8 priorMin, priorMax, dprior, s_gamma;
2889 REAL8 accept, propose, sigma;
2902 if (adaptableStep && adapting) {
2921 if (adaptableStep) {
2934 dprior = priorMax - priorMin;
2948 sigma += s_gamma * (dprior/100.0) * (1.0-targetAcceptance);
2950 sigma -= s_gamma * (dprior/100.0) * (targetAcceptance);
2953 sigma = (sigma > dprior ? dprior : sigma);
2954 sigma = (sigma < DBL_MIN ? DBL_MIN : sigma);
3001 for (
j=0;
j<nCols;
j++)
3005 for (
j=0;
j<nCols;
j++) {
3006 if (!strcmp(
"logl",
params[
j])) {
3011 char* internal_param_name =
XLALCalloc(512,
sizeof(
char));
3015 if (!strcmp(item->
name, internal_param_name) &&
3028 for (item = backwardClusterParams->
head; item; item = item->
next)
3043 if (acl_real8 == INFINITY)
3045 else if (acl_real8 < 1.0)
3048 acl = (
INT4)acl_real8;
3050 INT4 downsampled_size = ceil((
REAL8)nInSamps/acl);
3052 printf(
"Downsampling to achieve %i samples.\n", downsampled_size);
3053 for (
k=0;
k < downsampled_size;
k++) {
3054 for (
j=0;
j < nValidCols;
j++)
3055 downsampled_array[
k*nValidCols +
j] = sampleArray[
k*nValidCols*acl +
j];
3058 sampleArray = downsampled_array;
3059 nInSamps = downsampled_size;
3068 fprintf(stderr,
"\nERROR: Couldn't build kmeans clustering from the file specified.\n");
3105 INT4 cyclic_reflective,
3109 gsl_matrix_view mview;
3110 char outp_name[256];
3111 char outp_draws_name[256];
3118 mview = gsl_matrix_view_array(array, nSamps, dim);
3119 kde->
kmeans = (*cluster_method)(&mview.matrix, ntrials, thread->
GSLrandom);
3137 printf(
"Thread %i found %i clusters.\n", thread->
id, kde->
kmeans->
k);
3139 sprintf(outp_name,
"clustered_samples.%2.2d", thread->
id);
3140 sprintf(outp_draws_name,
"clustered_draws.%2.2d", thread->
id);
3162 outp = fopen(outp_name,
"w");
3190 outp = fopen(outp_name,
"w");
3194 for (
i=0;
i<nSamps;
i++) {
3225 if (!strcmp(existing_kde->
name, kde->
name)) {
3226 old_kde = existing_kde;
3230 while (existing_kde->
next != NULL) {
3232 if (!strcmp(existing_kde->
next->name, kde->
name)) {
3233 old_kde = existing_kde->
next;
3235 existing_kde->
next = kde;
3238 existing_kde = existing_kde->
next;
3242 existing_kde->
next=kde;
3261 if (proposal != NULL) {
3287 if (effSampleSize > 0)
3288 step = (
INT4) floor(bufferSize/effSampleSize);
3298 for (
i=0;
i < nPoints;
i++)
3299 DEsamples[
i] =
temp + (
i*nPar);
3336 for (item = backwardClusterParams->
head; item; item = item->
next)
3374 return logPropRatio;
3392 REAL8 cumulativeWeight, totalWeight;
3393 REAL8 logPropRatio = 0.0;
3400 return logPropRatio;
3411 totalWeight += kde->
weight;
3419 cumulativeWeight = kde->
weight;
3420 while(cumulativeWeight/totalWeight < randomDraw) {
3422 cumulativeWeight += kde->
weight;
3440 if (propDensity == NULL || *propDensity == -INFINITY)
3443 logCurrentP = *propDensity;
3447 logPropRatio = logCurrentP - logProposedP;
3449 if (propDensity != NULL)
3450 *propDensity = logProposedP;
3455 return logPropRatio;
3474 INT4 nPar, nPoints, nSkip;
3489 for (
i=0;
i < nPoints;
i++)
3490 DEarray[
i] =
temp + (
i*nPar);
3495 if (max_acl == INFINITY)
3497 else if (max_acl < 1.0)
3500 *maxACL = (
INT4)max_acl;
3533 INT4 par=0, lag=0,
i=0, imax;
3539 for (par=0; par<nPar; par++) {
3540 mean = gsl_stats_mean(array+par, nPar, nPoints);
3541 for (
i=0;
i<nPoints;
i++)
3542 array[
i*nPar + par] -=
mean;
3549 while (cumACF >=
s) {
3550 ACF = gsl_stats_correlation(array + par, nPar, array + lag*nPar + par, nPar, nPoints-lag);
3551 cumACF += 2.0 * ACF;
3562 else if (gsl_isnan(ACL))
3565 for (
i=0;
i<nPoints;
i++)
3566 array[
i*nPar + par] +=
mean;
3606 INT4 iEff = nPoints/acl;
3624 fprintf(
fp,
"%9.5f\t", exp(logPropRatio));
3635 for(det=thread->
parent->data;det;det=det->
next)
3646 for (
i = 0;
i < nspl;
i++) {
3649 fprintf(stderr,
"variable name too long\n"); abort();
3653 fprintf(stderr,
"variable name too long\n"); abort();
3658 amp += ampWidth*gsl_ran_ugaussian(thread->
GSLrandom)/sqrt(nifo*(
REAL8)nspl);
3663 ph += phaseWidth*gsl_ran_ugaussian(thread->
GSLrandom)/sqrt(nifo*(
REAL8)nspl);
void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans, LALInferenceVariables *params, LALInferenceVariables *priorArgs, INT4 cyclic_reflective)
Impose boundaries on individual KDEs.
REAL8 LALInferenceKmeansPDF(LALInferenceKmeans *kmeans, REAL8 *pt)
Evaluate the estimated (log) PDF from a clustered-KDE at a point.
LALInferenceKmeans * LALInferenceOptimizedKmeans(gsl_matrix *data, INT4 ntrials, gsl_rng *rng)
Kmeans cluster data, maximizing BIC assuming BIC(k) is concave-down.
void LALInferenceKmeansDestroy(LALInferenceKmeans *kmeans)
Destroy a kmeans instance.
REAL8 * LALInferenceKmeansDraw(LALInferenceKmeans *kmeans)
Draw a sample from a kmeans-KDE estimate of a distribution.
LALInferenceModel * LALInferenceInitCBCModel(LALInferenceRunState *state)
Initialise state variables needed for LALInferenceNest or LALInferenceMCMC to run on a CBC signal.
static REAL8 mean(REAL8 *array, int N)
static INT4 numDetectorsUniquePositions(LALInferenceIFOData *data)
static void UpdateWaveletSum(LALInferenceThreadState *thread, LALInferenceVariables *proposedParams, gsl_matrix *glitchFD, INT4 ifo, INT4 n, INT4 flag)
static REAL8 draw_colatitude(LALInferenceThreadState *thread, const char *name)
REAL8 LALInferenceDifferentialEvolutionNames(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams, const char **names)
static void MorletDiagonalFisherMatrix(REAL8Vector *params, REAL8Vector *sigmas)
static void cart_to_sph(const REAL8 cart[3], REAL8 *lat, REAL8 *longi)
static void reflected_position_and_time(LALInferenceThreadState *thread, const REAL8 ra, const REAL8 dec, const REAL8 oldTime, REAL8 *newRA, REAL8 *newDec, REAL8 *newTime)
static void reflected_extrinsic_parameters(LALInferenceThreadState *thread, const REAL8 ra, const REAL8 dec, const REAL8 baryTime, const REAL8 dist, const REAL8 iota, const REAL8 psi, REAL8 *newRA, REAL8 *newDec, REAL8 *newTime, REAL8 *newDist, REAL8 *newIota, REAL8 *newPsi)
static REAL8 draw_logdistance(LALInferenceThreadState *thread)
const char *const distanceLikelihoodProposalName
static const char * intrinsicNames[]
static void unit_vector(REAL8 v[3], const REAL8 w[3])
static REAL8 norm(const REAL8 x[3])
static const char * extrinsicNames[]
const char *const splineCalibrationProposalName
@ USES_LOG_DISTANCE_VARIABLE
static void cross_product(REAL8 x[3], const REAL8 y[3], const REAL8 z[3])
static REAL8 draw_flat(LALInferenceThreadState *thread, const char *name)
static void get_detectors(LALInferenceIFOData *data, LALDetector **detectors)
static REAL8 evaluate_morlet_proposal(LALInferenceThreadState *thread, LALInferenceVariables *proposedParams, INT4 ifo, INT4 k)
static REAL8 draw_chirp(LALInferenceThreadState *thread)
static REAL8 draw_distance(LALInferenceThreadState *thread)
static void project_along(REAL8 vproj[3], const REAL8 v[3], const REAL8 w[3])
static void vsub(REAL8 diff[3], const REAL8 w[3], const REAL8 v[3])
static void sph_to_cart(REAL8 cart[3], const REAL8 lat, const REAL8 longi)
static REAL8 draw_dec(LALInferenceThreadState *thread)
static INT4 same_detector_location(LALDetector *d1, LALDetector *d2)
static REAL8 approxLogPrior(LALInferenceVariables *params)
REAL8 LALInferencePolarizationPhaseJump(UNUSED LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
static REAL8 dot(const REAL8 v[3], const REAL8 w[3])
static void reflect_plane(REAL8 pref[3], const REAL8 p[3], const REAL8 x[3], const REAL8 y[3], const REAL8 z[3])
static REAL8 glitchAmplitudeDraw(REAL8 Q, REAL8 f, gsl_rng *r)
LALInferenceVariables currentParams
static double double delta
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
INT4 LALInferenceBufferToArray(LALInferenceThreadState *thread, REAL8 **DEarray)
INT4 LALInferenceThinnedBufferToArray(LALInferenceThreadState *thread, REAL8 **DEarray, INT4 step)
LALInferenceVariable buffer to array and vica versa.
void LALInferencePrintSampleNonFixed(FILE *fp, LALInferenceVariables *sample)
Output only non-fixed parameters.
void LALInferenceReadAsciiHeader(FILE *input, char params[][VARNAME_MAX], INT4 *nCols)
Read column names from an ASCII file.
LALInferenceVariableType LALInferenceGetVariableType(const LALInferenceVariables *vars, const char *name)
Get the LALInferenceVariableType of the parameter named name in vars.
void LALInferenceDiscardPTMCMCHeader(FILE *filestream)
Discard the standard header of a PTMCMC chain file.
int LALInferenceFprintParameterNonFixedHeaders(FILE *out, LALInferenceVariables *params)
Print the parameters which do not vary to a file as a tab-separated ASCII line.
UINT4 LALInferenceGetUINT4Variable(LALInferenceVariables *vars, const char *name)
INT4 LALInferenceGetVariableDimensionNonFixed(LALInferenceVariables *vars)
Get number of dimensions in vars which are not fixed to a certain value.
void LALInferenceAddREAL8VectorVariable(LALInferenceVariables *vars, const char *name, REAL8Vector *value, LALInferenceParamVaryType vary)
gsl_matrix * LALInferenceGetgslMatrixVariable(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)
void LALInferenceSetREAL8Variable(LALInferenceVariables *vars, const char *name, REAL8 value)
int LALInferenceCompareVariables(LALInferenceVariables *var1, LALInferenceVariables *var2)
Check for equality in two variables.
void LALInferenceAddstringVariable(LALInferenceVariables *vars, const char *name, const CHAR *value, LALInferenceParamVaryType vary)
LALInferenceVariableItem * LALInferenceGetItemNr(LALInferenceVariables *vars, int idx)
Return the list node for the idx-th item - do not rely on this Indexing starts at 1.
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
void LALInferenceBurninStream(FILE *filestream, INT4 burnin)
Burn-in a generic ASCII stream.
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...
REAL8Vector * LALInferenceGetREAL8VectorVariable(LALInferenceVariables *vars, const char *name)
void LALInferenceAddREAL8Variable(LALInferenceVariables *vars, const char *name, REAL8 value, LALInferenceParamVaryType vary)
INT4 LALInferenceGetINT4Variable(LALInferenceVariables *vars, const char *name)
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void LALInferenceAddINT4Variable(LALInferenceVariables *vars, const char *name, INT4 value, LALInferenceParamVaryType vary)
REAL8 * LALInferenceParseDelimitedAscii(FILE *input, INT4 nCols, INT4 *wantedCols, INT4 *nLines)
Utility for readling in delimited ASCII files.
void LALInferenceBurninPTMCMC(FILE *filestream, INT4 logl_idx, INT4 nPar)
Determine burnin cycle from delta-logl criteria.
INT4 LALInferenceGetVariableDimension(LALInferenceVariables *vars)
Get number of dimensions in variable vars.
REAL8(* LALInferenceProposalFunction)(struct tagLALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Jump proposal distribution Computes proposedParams based on currentParams and additional variables st...
const CHAR * LALInferenceGetstringVariable(LALInferenceVariables *vars, const char *name)
UINT4Vector * LALInferenceGetUINT4VectorVariable(LALInferenceVariables *vars, const char *name)
void LALInferenceClearVariables(LALInferenceVariables *vars)
Delete the variables in this structure.
INT4 LALInferenceFprintParameterNonFixedHeadersWithSuffix(FILE *out, LALInferenceVariables *params, const char *suffix)
Print the parameters which do not vary to a file as a tab-separated ASCII line, adding the given suff...
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
void LALInferenceTranslateExternalToInternalParamName(char *outName, const char *inName)
Converts between externally used parameter names and those internal.
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.
@ 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_LINEAR
@ LALINFERENCE_void_ptr_t
void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
NestedSamplingAlgorithm implements the nested sampling algorithm, see e.g.
int LALInferenceCheckMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
Check for types of standard prior.
void LALInferenceCyclicReflectiveBound(LALInferenceVariables *parameter, LALInferenceVariables *priorArgs)
Apply cyclic and reflective boundaries to parameter to bring it back within the allowed prior ranges ...
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 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 logGlitchAmplitudeDensity(REAL8 A, REAL8 Q, REAL8 f)
Return the log Prior for the glitch amplitude.
REAL8 LALInferenceEnsembleWalkNames(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams, const char **names)
REAL8 LALInferenceEnsembleStretchFull(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Ensemble stretch moves - see http://dx.doi.org/10.2140/camcos.2010.5.65.
const char *const singleAdaptProposalName
void LALInferenceDumpClusteredKDEDraws(LALInferenceClusteredKDE *kde, char *outp_name, INT4 nSamps)
Dump clustered KDE information to file.
const char *const polarizationPhaseJumpName
REAL8 LALInferenceSkyRingProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
const char *const GlitchMorletJumpName
void LALInferenceDestroyClusteredKDEProposal(LALInferenceClusteredKDE *proposal)
Destroy an existing clustered-KDE proposal.
REAL8 LALInferenceSkyLocWanderJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Jump around by 0.01 radians in angle on the sky.
const char *const frequencyBinJumpName
REAL8 LALInferenceEnsembleStretchIntrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
const char *const ensembleWalkIntrinsicName
const char *const singleProposalName
void LALInferenceSetupAdaptiveProposals(LALInferenceVariables *propArgs, LALInferenceVariables *params)
Setup adaptive proposals.
const char *const extrinsicParamProposalName
const char *const covarianceEigenvectorJumpName
const char *const ensembleStretchExtrinsicName
REAL8 LALInferenceEnsembleWalkFull(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceCovarianceEigenvectorJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Choose a random covariance matrix eigenvector to jump along.
const char *const cycleArrayName
void LALInferenceUpdateMaxAutoCorrLen(LALInferenceThreadState *thread)
Update the estimatate of the autocorrelation length.
REAL8 LALInferenceGlitchMorletProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceExtrinsicParamProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposal for the extrinsic parameters.
const char *const drawFlatPriorName
REAL8 LALInferenceGlitchMorletReverseJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
const char *const differentialEvolutionExtrinsicName
const char *const GlitchMorletReverseJumpName
REAL8 LALInferenceSplineCalibrationProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposes jumps in the spline calibration parameters, if present.
LALInferenceProposalCycle * LALInferenceSetupDefaultInspiralProposalCycle(LALInferenceVariables *propArgs)
A reasonable default proposal.
REAL8 LALInferenceSingleAdaptProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Like LALInferenceSingleProposal() but will use adaptation if the –adapt command-line flag given.
const char *const cycleArrayCounterName
const char *const ensembleStretchIntrinsicName
REAL8 LALInferenceComputeMaxAutoCorrLen(REAL8 *array, INT4 nPoints, INT4 nPar)
Compute the maximum single-parameter autocorrelation length.
const char *const PSDFitJumpName
REAL8 LALInferenceEnsembleWalkIntrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceDifferentialEvolutionExtrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Perform a differential evolution step on only the extrinsic parameters.
REAL8 LALInferenceStoredClusteredKDEProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams, REAL8 *propDensity)
An interface to the KDE proposal that avoids a KDE evaluation if possible.
const char *const skyRingProposalName
const char *const ensembleWalkExtrinsicName
const char *const clusteredKDEProposalName
REAL8 LALInferenceSingleProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Non-adaptive, sigle-variable update proposal with reasonable widths in each dimension.
void LALInferenceInitClusteredKDEProposal(LALInferenceThreadState *thread, LALInferenceClusteredKDE *kde, REAL8 *array, INT4 nSamps, LALInferenceVariables *params, const char *name, REAL8 weight, LALInferenceKmeans *(*cluster_method)(gsl_matrix *, INT4, gsl_rng *), INT4 cyclic_reflective, INT4 ntrials)
Initialize a clustered-KDE proposal.
REAL8 LALInferenceEnsembleStretchExtrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceDistanceLikelihoodProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposal which draws a sample from the distance likelihood function Requires the currentParams to hav...
void LALInferenceUpdateAdaptiveJumps(LALInferenceThreadState *thread, REAL8 targetAcceptance)
Update the adaptive proposal.
void LALInferenceAddProposalToCycle(LALInferenceProposalCycle *cycle, LALInferenceProposal *prop, INT4 weight)
Adds weight copies of the proposal prop to the end of the proposal cycle.
const char *const drawApproxPriorName
INT4 LALInferencePrintProposalTrackingHeader(FILE *fp, LALInferenceVariables *params)
Output proposal tracking header to file *fp.
LALInferenceVariables * LALInferenceParseProposalArgs(LALInferenceRunState *runState)
Go through all logic for deciding proposals to use.
void LALInferenceDeleteProposalCycle(LALInferenceProposalCycle *cycle)
Completely remove the current proposal cycle, freeing the associated memory.
const char *const polarizationCorrPhaseJumpName
void LALInferenceComputeMaxAutoCorrLenFromDE(LALInferenceThreadState *thread, INT4 *maxACL)
A wrapper for the KDE proposal that doesn't store KDE evaluations.
void LALInferenceTrackProposalAcceptance(LALInferenceThreadState *thread)
Update proposal statistics if tracking.
void LALInferenceSetupClusteredKDEProposalFromDEBuffer(LALInferenceThreadState *thread)
Setup a clustered-KDE proposal from the differential evolution buffer.
void LALInferencePrintProposalTracking(FILE *fp, LALInferenceProposalCycle *cycle, LALInferenceVariables *theta, LALInferenceVariables *theta_prime, REAL8 logPropRatio, INT4 accepted)
Output proposal tracking information to file *fp.
void LALInferenceDumpClusteredKDE(LALInferenceClusteredKDE *kde, char *outp_name, REAL8 *array)
Dump draws from a KDE to file.
void LALInferenceZeroProposalStats(LALInferenceProposalCycle *cycle)
INT4 LALInferenceComputeEffectiveSampleSize(LALInferenceThreadState *thread)
Determine the effective sample size based on the DE buffer.
void LALInferenceRegisterProposal(LALInferenceVariables *propArgs, const char *name, INT4 *flag, ProcessParamsTable *command_line)
Use a default flag and a check of the command-line to set proposal flags in proposal args.
void LALInferenceSetupClusteredKDEProposalsFromASCII(LALInferenceThreadState *thread, FILE *input, INT4 burnin, REAL8 weight, INT4 ptmcmc)
Setup all clustered-KDE proposals with samples read from file.
const char *const orbitalPhaseJumpName
REAL8 LALInferenceCorrPolarizationPhaseJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Polarization-phase correlation jump.
const char *const skyReflectDetPlaneName
const char *const skyLocWanderJumpName
const char *const ensembleWalkFullName
void LALInferenceAddClusteredKDEProposalToSet(LALInferenceVariables *propArgs, LALInferenceClusteredKDE *kde)
Add a KDE proposal to the KDE proposal set.
void LALInferenceRandomizeProposalCycle(LALInferenceProposalCycle *cycle, gsl_rng *rng)
Randomizes the order of the proposals in the proposal cycle.
REAL8 LALInferenceEnsembleStretchNames(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams, const char **names)
LALInferenceProposal * LALInferenceInitProposal(LALInferenceProposalFunction func, const char *name)
Creates a new proposal object from the given func pointer and name.
REAL8 LALInferenceDifferentialEvolutionFull(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Differential evolution, on all non-fixed, non-output parameters.
REAL8 LALInferenceDifferentialEvolutionIntrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Perform differential evolution on only the intrinsic parameters.
REAL8 LALInferenceDrawFlatPrior(LALInferenceThreadState *threadState, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Draws from a flat prior for all variables where are flat prior is specified.
const char *const differentialEvolutionIntrinsicName
LALInferenceProposalCycle * LALInferenceInitProposalCycle(void)
Create a new proposal cycle.
REAL8 LALInferenceCyclicProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposes a jump from the next proposal in the proposal cycle.
void LALInferenceSetupGlitchProposal(LALInferenceIFOData *data, LALInferenceVariables *propArgs)
Setup glitch-related stuff.
const char *const cycleArrayLengthName
const char *const ensembleStretchFullName
void LALInferenceSetupClusteredKDEProposalFromRun(LALInferenceThreadState *thread, REAL8 *samples, INT4 size, INT4 cyclic_reflective, INT4 ntrials)
Setup a clustered-KDE proposal from the parameters in a run.
REAL8 LALInferenceDrawApproxPrior(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Draws from an approximation to the true prior.
REAL8 LALInferencePSDFitJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceSkyReflectDetPlane(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Reflects the sky location through the plane formed by three detectors.
REAL8 LALInferenceEnsembleWalkExtrinsic(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
REAL8 LALInferenceClusteredKDEProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
A proposal based on the clustered kernal density estimate of a set of samples.
REAL8 LALInferenceFrequencyBinJump(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposal to jump in frequency by one frequency bin.
const char *const differentialEvolutionFullName
const char *const nullProposalName
void * XLALCalloc(size_t m, size_t n)
void * XLALRealloc(void *p, size_t n)
COORDINATESYSTEM_GEOGRAPHIC
COORDINATESYSTEM_EQUATORIAL
void LALEquatorialToGeographic(LALStatus *stat, SkyPosition *output, SkyPosition *input, LIGOTimeGPS *gpsTime)
void LALGeographicToEquatorial(LALStatus *stat, SkyPosition *output, SkyPosition *input, LIGOTimeGPS *gpsTime)
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_REAL8(...)
void XLALError(const char *func, const char *file, int line, int errnum)
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
LALDetector detectors[LAL_NUM_DETECTORS]
Struct to hold clustered-KDE estimates.
LALInferenceKmeans * kmeans
struct tagLALInferenceClusteredKDEProposal * next
LALInferenceVariables * params
Structure to contain IFO data.
LALDetector * detector
integration limits for overlap integral in F-domain
struct tagLALInferenceIFOData * next
ROQ data.
Structure for performing the kmeans clustering algorithm on a set of samples.
INT4 npts
Number of points being clustered.
INT4 * assignments
Cluster assignments.
INT4 k
Number of clusters.
REAL8 * weights
Fraction of data points in each cluster.
INT4 dim
Dimension of data.
Structure to constain a model and its parameters.
LALInferenceVariables * params
Structure for holding a proposal cycle.
LALInferenceProposal ** proposals
char last_proposal_name[VARNAME_MAX]
Counter for cycling through proposals.
INT4 * order
Array of proposals (one per proposal function)
INT4 nProposals
Length of cycle.
Structure for holding a LALInference proposal, along with name and stats.
LALInferenceProposalFunction func
Structure containing inference run state This includes pointers to the function types required to run...
ProcessParamsTable * commandLine
LALInferenceVariables * proposalArgs
The data from the interferometers.
LALInferenceVariables * algorithmParams
Any special arguments for the prior function.
struct tagLALInferenceIFOData * data
Log sample, i.e.
LALInferenceAlgorithm algorithm
A function that returns a new set of variables for the model.
Structure containing chain-specific variables.
LALInferenceVariables * currentParams
Prior boundaries, etc.
struct tagLALInferenceRunState * parent
LALInferenceVariables * priorArgs
Stope things such as output arrays.
LALInferenceModel * model
Cycle of proposals to call.
INT4 accepted
This should be removed, can be given as an algorithmParams entry.
size_t differentialPointsLength
Array of points for differential evolution.
LALInferenceProposalCycle * cycle
The proposal cycle.
LALInferenceVariables * proposalArgs
REAL8 temperature
Array containing multiple proposal densities.
size_t differentialPointsSkip
Size of the differentialPoints memory block (must be >= length of differential points).
LALInferenceVariables ** differentialPoints
Parameters proposed.
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]
struct tagProcessParamsTable * next