LALInference 4.1.10.1-bf6a62b
LALInferenceProposal.c
Go to the documentation of this file.
1/*
2 * LALInferenceProposal.c: Bayesian Followup, jump proposals.
3 *
4 * Copyright (C) 2011 Ilya Mandel, Vivien Raymond, Christian Roever,
5 * Marc van der Sluys, John Veitch, Will M. Farr, Ben Farr
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with with program; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA
22 */
23
24#include <stdio.h>
25#include <stdlib.h>
26#include <lal/LALInspiral.h>
27#include <lal/DetResponse.h>
28#include <lal/SeqFactories.h>
29#include <lal/Date.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>
46
47#include <lal/LALStdlib.h>
48#include <lal/LALInferenceClusteredKDE.h>
49#include <lal/LALInferenceNestedSampler.h>
50
51#ifdef __GNUC__
52#define UNUSED __attribute__ ((unused))
53#else
54#define UNUSED
55#endif
56
57typedef enum {
61
62const char *const cycleArrayName = "Proposal Cycle";
63const char *const cycleArrayLengthName = "Proposal Cycle Length";
64const char *const cycleArrayCounterName = "Proposal Cycle Counter";
65
66/* Proposal Names */
67const char *const nullProposalName = "NULL";
68const char *const singleAdaptProposalName = "Single";
69const char *const singleProposalName = "Single";
70const char *const orbitalPhaseJumpName = "OrbitalPhase";
71const char *const covarianceEigenvectorJumpName = "CovarianceEigenvector";
72const char *const skyLocWanderJumpName = "SkyLocWander";
73const char *const differentialEvolutionFullName = "DifferentialEvolutionFull";
74const char *const differentialEvolutionIntrinsicName = "DifferentialEvolutionIntrinsic";
75const char *const differentialEvolutionExtrinsicName = "DifferentialEvolutionExtrinsic";
76const char *const ensembleStretchFullName = "EnsembleStretchFull";
77const char *const ensembleStretchIntrinsicName = "EnsembleStretchIntrinsic";
78const char *const ensembleStretchExtrinsicName = "EnsembleStretchExtrinsic";
79const char *const drawApproxPriorName = "DrawApproxPrior";
80const char *const drawFlatPriorName = "DrawFlatPrior";
81const char *const skyReflectDetPlaneName = "SkyReflectDetPlane";
82const char *const skyRingProposalName = "SkyRingProposal";
83const char *const PSDFitJumpName = "PSDFitJump";
84const char *const polarizationPhaseJumpName = "PolarizationPhase";
85const char *const polarizationCorrPhaseJumpName = "CorrPolarizationPhase";
86const char *const extrinsicParamProposalName = "ExtrinsicParamProposal";
87const char *const frequencyBinJumpName = "FrequencyBin";
88const char *const GlitchMorletJumpName = "glitchMorletJump";
89const char *const GlitchMorletReverseJumpName = "glitchMorletReverseJump";
90const char *const ensembleWalkFullName = "EnsembleWalkFull";
91const char *const ensembleWalkIntrinsicName = "EnsembleWalkIntrinsic";
92const char *const ensembleWalkExtrinsicName = "EnsembleWalkExtrinsic";
93const char *const clusteredKDEProposalName = "ClusteredKDEProposal";
94const char *const splineCalibrationProposalName = "SplineCalibration";
95const char *const distanceLikelihoodProposalName = "DistanceLikelihood";
96
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};
98
99static const char *extrinsicNames[] = {"rightascension", "declination", "cosalpha", "azimuth", "polarisation", "distance",
100 "logdistance", "time", "costheta_jn", "t0", "theta","hrss", "loghrss", NULL};
101
103 INT4 i;
104
105 for (i = 0; i < 3; i++) {
106 if (d1->location[i] != d2->location[i])
107 return 0;
108 }
109
110 return 1;
111}
112
114 INT4 nIFO = 0;
115 INT4 nCollision = 0;
116 LALInferenceIFOData *currentIFO = NULL;
117
118 for (currentIFO = data; currentIFO; currentIFO = currentIFO->next) {
119 LALInferenceIFOData *subsequentIFO = NULL;
120 nIFO++;
121 for (subsequentIFO = currentIFO->next; subsequentIFO; subsequentIFO = subsequentIFO->next) {
122 if (same_detector_location(subsequentIFO->detector, currentIFO->detector)) {
123 nCollision++;
124 break;
125 }
126 }
127 }
128
129 return nIFO - nCollision;
130}
131
133{
135 proposal->func = func;
136 proposal->proposed = 0;
137 proposal->accepted = 0;
138 strcpy(proposal->name, name);
139 return proposal;
140}
141
142
143void LALInferenceRegisterProposal(LALInferenceVariables *propArgs, const char *name, INT4 *flag, ProcessParamsTable *command_line) {
144 char offopt[VARNAME_MAX+15];
145 char onopt[VARNAME_MAX+12];
146
147 sprintf(offopt, "--proposal-no-%s", name);
148 sprintf(onopt, "--proposal-%s", name);
149
150 if (LALInferenceGetProcParamVal(command_line, offopt))
151 *flag = 0;
152 else if (LALInferenceGetProcParamVal(command_line, onopt))
153 *flag = 1;
154
156}
157
159 const char *fname = "LALInferenceAddProposalToCycle";
160 INT4 i;
161
162 /* Quit without doing anything if weight = 0. */
163 if (weight == 0)
164 return;
165
166 cycle->order = XLALRealloc(cycle->order, (cycle->length + weight)*sizeof(INT4));
167 if (cycle->order == NULL) {
168 XLALError(fname, __FILE__, __LINE__, XLAL_ENOMEM);
169 abort();
170 }
171
172 for (i = cycle->length; i < cycle->length + weight; i++) {
173 cycle->order[i] = cycle->nProposals;
174 }
175
176 cycle->nProposals += 1;
177 cycle->proposals = XLALRealloc(cycle->proposals, (cycle->nProposals)*sizeof(LALInferenceProposal));
178 if (cycle->proposals == NULL) {
179 XLALError(fname, __FILE__, __LINE__, XLAL_ENOMEM);
180 abort();
181 }
182 cycle->proposals[cycle->nProposals-1] = prop;
183
184 cycle->length += weight;
185}
186
187
188
190 INT4 i, j, temp;
191
192 for (i = cycle->length - 1; i > 0; i--) {
193 /* Fill in array from right to left, chosen randomly from remaining proposals. */
194 j = gsl_rng_uniform_int(rng, i+1);
195
196 temp = cycle->order[j];
197 cycle->order[j] = cycle->order[i];
198 cycle->order[i] = temp;
199 }
200}
201
202
205 LALInferenceVariables *proposedParams) {
206 INT4 i = 0;
207 LALInferenceProposalCycle *cycle=NULL;
208
209 /* Must have cycle array and cycle array length in propArgs. */
210 cycle = thread->cycle;
211 if (cycle == NULL) {
212 XLALError("LALInferenceCyclicProposal()",__FILE__,__LINE__,XLAL_FAILURE);
213 abort();
214 }
215
216 if (cycle->counter >= cycle->length) {
217 XLALError("LALInferenceCyclicProposal()",__FILE__,__LINE__,XLAL_FAILURE);
218 abort();
219 }
220
221 /* One instance of each proposal object is stored in cycle->proposals.
222 cycle->order is a list of elements to call from the proposals */
223
224 REAL8 logPropRatio=-INFINITY;
225 do
226 {
227 i = cycle->order[cycle->counter];
228 logPropRatio = cycle->proposals[i]->func(thread, currentParams, proposedParams);
229 strcpy(cycle->last_proposal_name, cycle->proposals[i]->name);
230 cycle->counter = (cycle->counter + 1) % cycle->length;
231 }
232 /* Call proposals until one succeeds */
233 while (proposedParams->head == NULL);
234
235 return logPropRatio;
236}
237
240 strcpy(cycle->last_proposal_name, nullProposalName);
241
242 return cycle;
243}
244
246 XLALFree(cycle->proposals);
247 XLALFree(cycle->order);
248}
249
252 LALInferenceIFOData *ifo = runState->data;
253
254 /* This will copy any existing arguments over from runState. I (John) don't think this should be necessary
255 * as this function is used to initialise these arguments in the first place. */
257 if(runState->proposalArgs && runState->proposalArgs->dimension>0) LALInferenceCopyVariables(runState->proposalArgs, propArgs);
258
259 INT4 Nskip = 1;
260 INT4 noise_only = 0;
261 INT4 cyclic_reflective_kde = 0;
262
263 /* Flags for proposals, initialized with the MCMC defaults */
264
265 INT4 singleadapt = 1; /* Disabled for bug checking */
266 INT4 psiphi = 1;
267 INT4 ext_param = 1;
268 INT4 skywander = 1;
269 INT4 skyreflect = 1;
270 INT4 drawprior = 1;
271 INT4 covjump = 0;
272 INT4 diffevo = 1;
273 INT4 stretch = 0;
274 INT4 walk = 0;
275 INT4 skyring = 1;
276 INT4 distance = 1;
277 INT4 kde = 0;
278 INT4 spline_cal = 0;
279 INT4 psdfit = 0;
280 INT4 glitchfit = 0;
281
283 singleadapt = 0;
284 psiphi = 0;
285 ext_param = 0;
286 skywander = 0;
287 skyreflect = 0;
288 drawprior = 0;
289 covjump = 1;
290 diffevo = 1;
291 stretch = 1;
292 walk = 1;
293 skyring = 0;
294 distance = 1;
295 kde = 0;
296 spline_cal = 0;
297 psdfit = 0;
298 glitchfit = 0;
299 }
300 if (LALInferenceCheckVariable(runState->algorithmParams, "LIB"))
301 distance=0;
302
303 ProcessParamsTable *command_line = runState->commandLine;
304
305 if(LALInferenceGetProcParamVal(command_line, "--margdist")
306 ||LALInferenceGetProcParamVal(command_line,"--margdist-comoving"))
307 distance=0;
308
309 INT4 verbose = 0;
310 if (LALInferenceGetProcParamVal(command_line, "--verbose"))
311 verbose = 1;
313
314 /* Determine the number of iterations between each entry in the DE buffer */
315 if (LALInferenceCheckVariable(runState->algorithmParams, "Nskip"))
316 Nskip = LALInferenceGetINT4Variable(runState->algorithmParams, "Nskip");
317 LALInferenceAddINT4Variable(propArgs, "Nskip", Nskip, LALINFERENCE_PARAM_FIXED);
318
319 /* Count the number of IFOs and uniquely-located IFOs to decide which sky-related proposals to use */
320 INT4 nDet = 0;
321 ifo=runState->data;
322 while (ifo) {
323 nDet++;
324 ifo = ifo->next;
325 }
327
328 INT4 nUniqueDet = numDetectorsUniquePositions(runState->data);
329 LALInferenceAddINT4Variable(propArgs, "nUniqueDet", nUniqueDet, LALINFERENCE_PARAM_FIXED);
330
331 INT4 marg_timephi = 0;
332 if (LALInferenceGetProcParamVal(command_line, "--margtimephi"))
333 marg_timephi = 1;
334
335 INT4 marg_time = 0;
336 if (marg_timephi || LALInferenceGetProcParamVal(command_line, "--margtime"))
337 marg_time = 1;
338 LALInferenceAddINT4Variable(propArgs, "marg_time", marg_time, LALINFERENCE_PARAM_FIXED);
339
340 INT4 marg_phi = 0;
341 if (marg_timephi || LALInferenceGetProcParamVal(command_line, "--margphi"))
342 marg_phi = 1;
343 LALInferenceAddINT4Variable(propArgs, "marg_phi", marg_phi, LALINFERENCE_PARAM_FIXED);
344
345 INT4 analytic_test = 0;
346 if (LALInferenceGetProcParamVal(command_line, "--correlatedGaussianLikelihood") ||
347 LALInferenceGetProcParamVal(command_line, "--bimodalGaussianLikelihood") ||
348 LALInferenceGetProcParamVal(command_line, "--rosenbrockLikelihood")) {
349 analytic_test = 1;
350 distance = 0;
351 }
352 LALInferenceAddINT4Variable(propArgs, "analytical_test", analytic_test, LALINFERENCE_PARAM_FIXED);
353
354 INT4 skyframe = 1;
355 if (LALInferenceGetProcParamVal(command_line, "--no-sky-frame"))
356 skyframe = 0;
357
358 INT4 noAdapt = 0;
359 if (LALInferenceGetProcParamVal(command_line, "--no-adapt") ||
360 LALInferenceGetProcParamVal(command_line, "--noiseonly"))
361 noAdapt = 1;
362 INT4 adapting = !noAdapt;
363 LALInferenceAddINT4Variable(propArgs, "no_adapt", noAdapt, LALINFERENCE_PARAM_LINEAR);
364 LALInferenceAddINT4Variable(propArgs, "adapting", adapting, LALINFERENCE_PARAM_LINEAR);
365
366 INT4 tau = 5;
367 ppt = LALInferenceGetProcParamVal(command_line, "--adapt-tau");
368 if (ppt)
369 tau = atof(ppt->value);
370 LALInferenceAddINT4Variable(propArgs, "adaptTau", tau, LALINFERENCE_PARAM_FIXED);
371
372 INT4 sampling_prior = 0;
373 ppt = LALInferenceGetProcParamVal(command_line, "--zerologlike");
374 if (ppt)
375 sampling_prior = 1;
376 LALInferenceAddINT4Variable(propArgs, "sampling_prior", sampling_prior, LALINFERENCE_PARAM_FIXED);
377
378 if (LALInferenceGetProcParamVal(command_line, "--enable-spline-calibration"))
379 spline_cal = 1;
380
381 ppt = LALInferenceGetProcParamVal(command_line, "--psd-fit");
382 if (!ppt)
383 ppt = LALInferenceGetProcParamVal(command_line, "--psdFit");
384 if (ppt)
385 psdfit = 1;
386
387 if (LALInferenceGetProcParamVal(command_line, "--glitch-fit"))
388 glitchfit = 1;
389
390 /* Convenience option for turning off ensemble moves */
391 if (LALInferenceGetProcParamVal(command_line, "--proposal-no-ensemble")) {
392 stretch = 0;
393 walk = 0;
394 }
395
396 /* Check if imposing cyclic reflective bounds */
397 if (LALInferenceGetProcParamVal(runState->commandLine, "--cyclic-reflective-kde"))
398 cyclic_reflective_kde = 1;
399 LALInferenceAddINT4Variable(propArgs, "cyclic_reflective_kde", cyclic_reflective_kde, LALINFERENCE_PARAM_FIXED);
400
401 if (LALInferenceGetProcParamVal(command_line, "--noiseonly"))
402 noise_only = 1;
403 LALInferenceAddINT4Variable(propArgs, "noiseonly", noise_only, LALINFERENCE_PARAM_FIXED);
404
405 /* Turn off signal proposals if no signal is in the model */
406 if (noise_only) {
407 singleadapt = 0;
408 psiphi = 0;
409 ext_param = 0;
410 skywander = 0;
411 skyreflect = 0;
412 drawprior = 0;
413 covjump = 0;
414 diffevo = 0;
415 stretch = 0;
416 walk = 0;
417 distance = 0;
418 skyring = 0;
419 spline_cal = 0;
420 }
421
422 /* Turn off phi-related proposals if marginalizing over phi in likelihood */
423 if (marg_phi) {
424 psiphi = 0;
425 }
426
427 /* Disable proposals that won't work with the current number of unique detectors */
428 if (nUniqueDet < 2) {
429 skyring = 0;
430 }
431
432 if (nUniqueDet != 3) {
433 skyreflect = 0;
434 }
435
436 if (nUniqueDet >= 3) {
437 ext_param = 0;
438 }
439
440 /* Turn off ra-dec related proposals when using the sky-frame coordinate system */
441 if (skyframe) {
442 ext_param = 0;
443 skywander = 0;
444 skyreflect = 0;
445 skyring = 0;
446 }
447
448 /* Register all proposal functions, check for explicit command-line requests */
449 LALInferenceRegisterProposal(propArgs, "single-adapt", &singleadapt, command_line);
450 LALInferenceRegisterProposal(propArgs, "psiphi", &psiphi, command_line);
451 LALInferenceRegisterProposal(propArgs, "extrinsic-param", &ext_param, command_line);
452 LALInferenceRegisterProposal(propArgs, "sky-wander", &skywander, command_line);
453 LALInferenceRegisterProposal(propArgs, "sky-reflect", &skyreflect, command_line);
454 LALInferenceRegisterProposal(propArgs, "draw-prior", &drawprior, command_line);
455 LALInferenceRegisterProposal(propArgs, "eigenvectors", &covjump, command_line);
456 LALInferenceRegisterProposal(propArgs, "differential-evolution", &diffevo, command_line);
457 LALInferenceRegisterProposal(propArgs, "ensemble-stretch", &stretch, command_line);
458 LALInferenceRegisterProposal(propArgs, "ensemble-walk", &walk, command_line);
459 LALInferenceRegisterProposal(propArgs, "sky-ring", &skyring, command_line);
460 LALInferenceRegisterProposal(propArgs, "distance", &distance, command_line);
461 LALInferenceRegisterProposal(propArgs, "kde", &kde, command_line);
462 LALInferenceRegisterProposal(propArgs, "spline_cal", &spline_cal, command_line);
463 LALInferenceRegisterProposal(propArgs, "psdfit", &psdfit, command_line);
464 LALInferenceRegisterProposal(propArgs, "glitchfit", &glitchfit, command_line);
465
466 /* Setup adaptive proposals */
467 if (singleadapt){
470 XLALFree(model);
471 }
472
473 /* Setup now since we need access to the data */
474 if (glitchfit)
475 LALInferenceSetupGlitchProposal(runState->data, propArgs);
476
477 return propArgs;
478}
479
480
483
484 const INT4 BIGWEIGHT = 20;
485 const INT4 SMALLWEIGHT = 5;
486 const INT4 TINYWEIGHT = 1;
487
489
490 if (LALInferenceGetINT4Variable(propArgs, "single-adapt")) {
492 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
493 }
494
495 if (LALInferenceGetINT4Variable(propArgs, "psiphi")) {
497 LALInferenceAddProposalToCycle(cycle, prop, TINYWEIGHT);
498 }
499
500 if (LALInferenceGetINT4Variable(propArgs, "extrinsic-param")) {
502 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
503 }
504
505 if (LALInferenceGetINT4Variable(propArgs, "sky-wander")) {
507 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
508 }
509
510 if (LALInferenceGetINT4Variable(propArgs, "sky-reflect")) {
512 LALInferenceAddProposalToCycle(cycle, prop, TINYWEIGHT);
513 }
514
515 if (LALInferenceGetINT4Variable(propArgs, "draw-prior")) {
517 LALInferenceAddProposalToCycle(cycle, prop, TINYWEIGHT);
518 }
519
520 if (LALInferenceGetINT4Variable(propArgs, "eigenvectors")) {
522 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
523 }
524
525 if (LALInferenceGetINT4Variable(propArgs, "differential-evolution")) {
527 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
528
530 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
531
533 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
534 }
535
536 if (LALInferenceGetINT4Variable(propArgs, "ensemble-stretch")) {
538 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
539
541 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
542
544 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
545 }
546
547 if (LALInferenceGetINT4Variable(propArgs, "ensemble-walk")) {
549 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
550
552 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
553
555 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
556 }
557
558 if (LALInferenceGetINT4Variable(propArgs, "sky-ring")) {
560 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
561 }
562
563 /* Distance proposal */
564 if (LALInferenceGetINT4Variable(propArgs, "distance")) {
566 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
567 }
568
569 if (LALInferenceGetINT4Variable(propArgs, "kde")) {
571 LALInferenceAddProposalToCycle(cycle, prop, BIGWEIGHT);
572 }
573
574 if (LALInferenceGetINT4Variable(propArgs, "spline_cal")) {
576 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
577 }
578
579 if (LALInferenceGetINT4Variable(propArgs, "psdfit")) {
581 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
582 }
583
584 if (LALInferenceGetINT4Variable(propArgs, "glitchfit")) {
586 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
587
589 LALInferenceAddProposalToCycle(cycle, prop, SMALLWEIGHT);
590 }
591
592 return cycle;
593}
594
595
598 LALInferenceVariables *proposedParams) {
599 INT4 dim, varNr;
600 REAL8 logPropRatio, sqrttemp, mu, sigma;
601 char tmpname[MAX_STRLEN] = "";
602 LALInferenceVariableItem *param = NULL;
603
606 gsl_rng *rng = thread->GSLrandom;
607
608 if (!LALInferenceGetINT4Variable(args, "no_adapt")) {
609 if (!LALInferenceCheckVariable(args, "adapting"))
611
612 sqrttemp = sqrt(thread->temperature);
613 dim = proposedParams->dimension;
614
615 do {
616 varNr = 1 + gsl_rng_uniform_int(rng, dim);
617 param = LALInferenceGetItemNr(proposedParams, varNr);
618 } while (!LALInferenceCheckVariableNonFixed(proposedParams, param->name) || param->type != LALINFERENCE_REAL8_t);
619
620 if (param->type != LALINFERENCE_REAL8_t) {
621 fprintf(stderr, "Attempting to set non-REAL8 parameter with numerical sigma (in %s, %d)\n",
622 __FILE__, __LINE__);
623 abort();
624 }
625
626 sprintf(tmpname,"%s_%s",param->name,ADAPTSUFFIX);
627 if (!LALInferenceCheckVariable(thread->proposalArgs, tmpname)) {
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__);
630 abort();
631 }
632
633 sigma = LALInferenceGetREAL8Variable(thread->proposalArgs, tmpname);
634
635 /* Save the name of the proposed variable */
636 LALInferenceAddstringVariable(args, "proposedVariableName", param->name, LALINFERENCE_PARAM_OUTPUT);
637
638 /* If temperature is infinite, scale sigma to the prior width */
639 if (sqrttemp == INFINITY) {
640 if (LALInferenceCheckGaussianPrior(thread->priorArgs, param->name)) {
641 LALInferenceGetGaussianPrior(thread->priorArgs, param->name, &mu, &sigma);
642
643 *((REAL8 *)param->value) += gsl_ran_ugaussian(rng) * sigma;
644 } else {
645 REAL8 min, max;
646 LALInferenceGetMinMaxPrior(thread->priorArgs, param->name, &min, &max);
647
648 *((REAL8 *)param->value) += gsl_ran_ugaussian(rng) * (max - min);
649 }
650 } else
651 *((REAL8 *)param->value) += gsl_ran_ugaussian(rng) * sigma * sqrttemp;
652
653 LALInferenceCyclicReflectiveBound(proposedParams, thread->priorArgs);
654
655 /* Set the log of the proposal ratio to zero, since this is a
656 symmetric proposal. */
657 logPropRatio = 0.0;
658
659 INT4 as = 1;
660 LALInferenceSetVariable(args, "adaptableStep", &as);
661
662 } else {
663 /* We are not adaptive, or for some reason don't have a sigma
664 vector---fall back on old proposal. */
665 logPropRatio = LALInferenceSingleProposal(thread, currentParams, proposedParams);
666 }
667
668 return logPropRatio;
669}
670
673 LALInferenceVariables *proposedParams) {
674 LALInferenceVariableItem *param=NULL;
676 gsl_rng * GSLrandom = thread->GSLrandom;
677 REAL8 sigma, big_sigma;
678 INT4 dim, varNr;
679
681
682 sigma = 0.1 * sqrt(thread->temperature); /* Adapt step to temperature. */
683 big_sigma = 1.0;
684
685 if (gsl_ran_ugaussian(GSLrandom) < 1.0e-3)
686 big_sigma = 1.0e1; //Every 1e3 iterations, take a 10x larger jump in a parameter
687 if (gsl_ran_ugaussian(GSLrandom) < 1.0e-4)
688 big_sigma = 1.0e2; //Every 1e4 iterations, take a 100x larger jump in a parameter
689
690 dim = proposedParams->dimension;
691
692 do {
693 varNr = 1 + gsl_rng_uniform_int(GSLrandom, dim);
694 param = LALInferenceGetItemNr(proposedParams, varNr);
695 } while (!LALInferenceCheckVariableNonFixed(proposedParams, param->name) || param->type != LALINFERENCE_REAL8_t);
696
697 /* Scale jumps proposal appropriately for prior sampling */
698 if (LALInferenceGetINT4Variable(args, "sampling_prior")) {
699 if (!strcmp(param->name, "eta")) {
700 sigma = 0.02;
701 } else if (!strcmp(param->name, "q")) {
702 sigma = 0.08;
703 } else if (!strcmp(param->name, "chirpmass")) {
704 sigma = 1.0;
705 } else if (!strcmp(param->name, "time")) {
706 sigma = 0.02;
707 } else if (!strcmp(param->name, "t0")) {
708 sigma = 0.02;
709 } else if (!strcmp(param->name, "phase")) {
710 sigma = 0.6;
711 } else if (!strcmp(param->name, "distance")) {
712 sigma = 10.0;
713 } else if (!strcmp(param->name, "declination")) {
714 sigma = 0.3;
715 } else if (!strcmp(param->name, "azimuth")) {
716 sigma = 0.6;
717 } else if (!strcmp(param->name, "cosalpha")) {
718 sigma = 0.1;
719 } else if (!strcmp(param->name, "rightascension")) {
720 sigma = 0.6;
721 } else if (!strcmp(param->name, "polarisation")) {
722 sigma = 0.6;
723 } else if (!strcmp(param->name,"costheta_jn")) {
724 sigma = 0.3;
725 } else if (!strcmp(param->name, "a_spin1")) {
726 sigma = 0.1;
727 } else if (!strcmp(param->name, "a_spin2")) {
728 sigma = 0.1;
729 } else {
730 fprintf(stderr, "Could not find parameter %s!", param->name);
731 abort();
732 }
733
734 *(REAL8 *)param->value += gsl_ran_ugaussian(GSLrandom)*sigma;
735 } else {
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;
740 } else {
741 *(REAL8 *)param->value += gsl_ran_ugaussian(GSLrandom)*big_sigma*sigma*0.01;
742 }
743 }
744
745 LALInferenceCyclicReflectiveBound(proposedParams, thread->priorArgs);
746
747 /* Symmetric Proposal. */
748 REAL8 logPropRatio = 0.0;
749
750 return logPropRatio;
751}
752
753
756 LALInferenceVariables *proposedParams) {
757 LALInferenceVariableItem *proposeIterator;
758 REAL8Vector *eigenvalues;
759 gsl_matrix *eigenvectors;
760 REAL8 jumpSize, tmp, inc;
761 REAL8 logPropRatio = 0.0;
762 INT4 N, i, j;
763
765
767 gsl_rng *rng = thread->GSLrandom;
768
769 eigenvalues = LALInferenceGetREAL8VectorVariable(args, "covarianceEigenvalues");
770 eigenvectors = LALInferenceGetgslMatrixVariable(args, "covarianceEigenvectors");
771
772 N = eigenvalues->length;
773
774 i = gsl_rng_uniform_int(rng, N);
775 jumpSize = sqrt(thread->temperature * eigenvalues->data[i]) * gsl_ran_ugaussian(rng);
776
777 j = 0;
778 proposeIterator = proposedParams->head;
779 if (proposeIterator == NULL) {
780 fprintf(stderr, "Bad proposed params in %s, line %d\n",
781 __FILE__, __LINE__);
782 abort();
783 }
784
785 do {
786 if (LALInferenceCheckVariableNonFixed(proposedParams, proposeIterator->name) &&
787 proposeIterator->type==LALINFERENCE_REAL8_t) {
788 tmp = LALInferenceGetREAL8Variable(proposedParams, proposeIterator->name);
789 inc = jumpSize * gsl_matrix_get(eigenvectors, j, i);
790
791 tmp += inc;
792
793 LALInferenceSetVariable(proposedParams, proposeIterator->name, &tmp);
794
795 j++;
796 }
797 } while ((proposeIterator = proposeIterator->next) != NULL && j < N);
798
799 return logPropRatio;
800}
801
804 LALInferenceVariables *proposedParams) {
805 REAL8 sigma;
806 REAL8 jumpX, jumpY;
807 REAL8 RA, DEC;
808 REAL8 newRA, newDEC;
809 REAL8 one_deg = 1.0 / (2.0*M_PI);
810 REAL8 logPropRatio = 0.0;
811
813
814 gsl_rng *rng = thread->GSLrandom;
815
816 sigma = sqrt(thread->temperature) * one_deg;
817 jumpX = sigma * gsl_ran_ugaussian(rng);
818 jumpY = sigma * gsl_ran_ugaussian(rng);
819
820 RA = LALInferenceGetREAL8Variable(proposedParams, "rightascension");
821 DEC = LALInferenceGetREAL8Variable(proposedParams, "declination");
822
823 newRA = RA + jumpX;
824 newDEC = DEC + jumpY;
825
826 LALInferenceSetVariable(proposedParams, "rightascension", &newRA);
827 LALInferenceSetVariable(proposedParams, "declination", &newDEC);
828
829
830 return logPropRatio;
831}
832
835 LALInferenceVariables *proposedParams) {
836 return(LALInferenceDifferentialEvolutionNames(thread, currentParams, proposedParams, NULL));
837}
838
841 LALInferenceVariables *proposedParams) {
842 return(LALInferenceEnsembleStretchNames(thread, currentParams, proposedParams, NULL));
843}
844
845
848 LALInferenceVariables *proposedParams) {
849
850 return(LALInferenceEnsembleStretchNames(thread, currentParams, proposedParams, intrinsicNames));
851
852}
853
856 LALInferenceVariables *proposedParams) {
857 REAL8 logPropRatio;
858
859 logPropRatio = LALInferenceEnsembleStretchNames(thread, currentParams, proposedParams, extrinsicNames);
860
861 return logPropRatio;
862}
863
864/* This jump uses the current sample 'A' and another randomly
865 * drawn 'B' from the ensemble of live points, and proposes
866 * C = B+Z(A-B) where Z is a scale factor */
869 LALInferenceVariables *proposedParams,
870 const char **names) {
871 size_t i, N, Ndim, nPts;
872 REAL8 logPropRatio;
873 REAL8 maxScale, Y, logmax, X, scale;
874 REAL8 cur, other, x;
876 LALInferenceVariables **dePts;
878
879 N = LALInferenceGetVariableDimension(currentParams) + 1; /* More names than we need. */
880 const char* local_names[N];
881 if (names == NULL) {
882 names = local_names;
883
884 item = currentParams->head;
885 i = 0;
886 while (item != NULL) {
888 names[i] = item->name;
889 i++;
890 }
891 item = item->next;
892 }
893 names[i]=NULL; /* Terminate */
894 }
895
896 Ndim = 0;
897 for(Ndim=0,i=0; names[i] != NULL; i++ ) {
899 Ndim++;
900 }
901
903
904 Ndim = 0;
905 for(Ndim=0, i=0; names[i] != NULL; i++ ) {
906 if (LALInferenceCheckVariableNonFixed(proposedParams, names[i]))
907 Ndim++;
908 }
909
910 dePts = thread->differentialPoints;
911 nPts = thread->differentialPointsLength;
912
913 if (dePts == NULL || nPts <= 1) {
914 logPropRatio = 0.0;
915 return logPropRatio; /* Quit now, since we don't have any points to use. */
916 }
917
918 /* Choose a different sample */
919 do {
920 i = gsl_rng_uniform_int(thread->GSLrandom, nPts);
921 } while (!LALInferenceCompareVariables(currentParams, dePts[i]));
922
923 ptI = dePts[i];
924
925 /* Scale z is chosen according to be symmetric under z -> 1/z */
926 /* so p(x) \propto 1/z between 1/a and a */
927
928 /* TUNABLE PARAMETER (a), must be >1. Larger value -> smaller acceptance */
929 maxScale=3.0;
930
931 /* Draw sample between 1/max and max */
932 Y = gsl_rng_uniform(thread->GSLrandom);
933 logmax = log(maxScale);
934 X = 2.0*logmax*Y - logmax;
935 scale = exp(X);
936
937 for (i = 0; names[i] != NULL; i++) {
938 /* Ignore variable if it's not in each of the params. */
939 if (LALInferenceCheckVariableNonFixed(proposedParams, names[i]) &&
941 cur = LALInferenceGetREAL8Variable(proposedParams, names[i]);
943 x = other + scale*(cur-other);
944
945 LALInferenceSetVariable(proposedParams, names[i], &x);
946 }
947 }
948
949 if (scale < maxScale && scale > (1.0/maxScale))
950 logPropRatio = log(scale)*((REAL8)Ndim);
951 else
952 logPropRatio = -INFINITY;
953
954 return logPropRatio;
955}
956
957
960 LALInferenceVariables *proposedParams) {
961 return(LALInferenceEnsembleWalkNames(thread, currentParams, proposedParams, NULL));
962}
963
964
967 LALInferenceVariables *proposedParams) {
968
969 return(LALInferenceEnsembleWalkNames(thread, currentParams, proposedParams, intrinsicNames));
970
971}
972
975 LALInferenceVariables *proposedParams) {
976 return(LALInferenceEnsembleWalkNames(thread, currentParams, proposedParams, extrinsicNames));
977}
978
979
982 LALInferenceVariables *proposedParams,
983 const char **names) {
984 size_t i;
986 REAL8 logPropRatio = 0.0;
987
988 size_t N = LALInferenceGetVariableDimension(currentParams) + 1; /* More names than we need. */
989 const char* local_names[N];
990 if (names == NULL) {
991 names = local_names;
992
993 item = currentParams->head;
994 i = 0;
995 while (item != NULL) {
997 names[i] = item->name;
998 i++;
999 }
1000
1001 item = item->next;
1002 }
1003 names[i]=NULL; /* Terminate */
1004 }
1005
1006
1007 /*
1008 size_t Ndim = 0;
1009 for(Ndim=0,i=0; names[i] != NULL; i++ ) {
1010 if(LALInferenceCheckVariableNonFixed(currentParams,names[i]))
1011 Ndim++;
1012 }
1013 */
1014
1015 LALInferenceVariables **pointsPool = thread->differentialPoints;
1016 size_t k=0;
1017 size_t sample_size=3;
1018
1019 LALInferenceVariables **dePts = thread->differentialPoints;
1020 size_t nPts = thread->differentialPointsLength;
1021
1022 if (dePts == NULL || nPts <= 1) {
1023 logPropRatio = 0.0;
1024 return logPropRatio; /* Quit now, since we don't have any points to use. */
1025 }
1026
1028
1029 UINT4 indices[sample_size];
1030 UINT4 all_indices[nPts];
1031
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));
1034
1035 double w=0.0;
1036 double univariate_normals[sample_size];
1037 for(i=0;i<sample_size;i++) univariate_normals[i] = gsl_ran_ugaussian(thread->GSLrandom);
1038
1039 /* Note: Simplified this loop on master 2015-08-12, take this version when rebasing */
1040 for(k=0;names[k]!=NULL;k++)
1041 {
1042 if(!LALInferenceCheckVariableNonFixed(proposedParams,names[k]) || LALInferenceGetVariableType(proposedParams,names[k])!=LALINFERENCE_REAL8_t) continue;
1043 REAL8 centre_of_mass=0.0;
1044 /* Compute centre of mass */
1045 for(i=0;i<sample_size;i++)
1046 {
1047 centre_of_mass+=LALInferenceGetREAL8Variable(pointsPool[indices[i]],names[k])/((REAL8)sample_size);
1048 }
1049 /* Compute offset */
1050 for(i=0,w=0.0;i<sample_size;i++)
1051 {
1052 w+= univariate_normals[i] * (LALInferenceGetREAL8Variable(pointsPool[indices[i]],names[k]) - centre_of_mass);
1053 }
1054 REAL8 tmp = LALInferenceGetREAL8Variable(proposedParams,names[k]) + w;
1055 LALInferenceSetVariable(proposedParams,names[k],&tmp);
1056 }
1057
1058 logPropRatio = 0.0;
1059
1060 return logPropRatio;
1061}
1062
1065 LALInferenceVariables *proposedParams,
1066 const char **names) {
1067 size_t i, j, N, Ndim, nPts;
1069 LALInferenceVariables **dePts;
1070 LALInferenceVariables *ptI, *ptJ;
1071 REAL8 logPropRatio = 0.0;
1072 REAL8 scale, x;
1073 N = LALInferenceGetVariableDimension(currentParams) + 1; /* More names than we need. */
1074 const char *localnames[N];
1075
1076 gsl_rng *rng = thread->GSLrandom;
1077
1078 if (names == NULL) {
1079 item = currentParams->head;
1080 i = 0;
1081 while (item != NULL) {
1083 localnames[i] = item->name;
1084 i++;
1085 }
1086
1087 item = item->next;
1088 }
1089 localnames[i]=NULL; /* Terminate */
1090 names = localnames;
1091 }
1092
1093 Ndim = 0;
1094 for (Ndim=0, i=0; names[i] != NULL; i++ ) {
1096 Ndim++;
1097 }
1098
1099 dePts = thread->differentialPoints;
1100 nPts = thread->differentialPointsLength;
1101
1102 if (dePts == NULL || nPts <= 1)
1103 return logPropRatio; /* Quit now, since we don't have any points to use. */
1104
1106
1107
1108 i = gsl_rng_uniform_int(rng, nPts);
1109 do {
1110 j = gsl_rng_uniform_int(rng, nPts);
1111 } while (j == i);
1112
1113 ptI = dePts[i];
1114 ptJ = dePts[j];
1115
1116 const REAL8 modeHoppingFrac = 0.5;
1117 /* Some fraction of the time, we do a "mode hopping" jump,
1118 where we jump exactly along the difference vector. */
1119 if (gsl_rng_uniform(rng) < modeHoppingFrac) {
1120 scale = 1.0;
1121 } else {
1122 /* Otherwise scale is chosen uniform in log between 0.1 and 10 times the
1123 desired jump size. */
1124 scale = 2.38/sqrt(Ndim) * exp(log(0.1) + log(100.0) * gsl_rng_uniform(rng));
1125 }
1126
1127 for (i = 0; names[i] != NULL; i++) {
1131 /* Ignore variable if it's not in each of the params. */
1132 } else {
1134 x += scale * LALInferenceGetREAL8Variable(ptJ, names[i]);
1135 x -= scale * LALInferenceGetREAL8Variable(ptI, names[i]);
1136 LALInferenceSetVariable(proposedParams, names[i], &x);
1137 }
1138 }
1139
1140 return logPropRatio;
1141}
1142
1145 LALInferenceVariables *proposedParams) {
1146
1148}
1149
1152 LALInferenceVariables *proposedParams) {
1154}
1155
1157 REAL8 dmin, dmax, x;
1158
1159 LALInferenceGetMinMaxPrior(thread->priorArgs, "distance", &dmin, &dmax);
1160
1161 x = gsl_rng_uniform(thread->GSLrandom);
1162
1163 return cbrt(x*(dmax*dmax*dmax - dmin*dmin*dmin) + dmin*dmin*dmin);
1164}
1165
1167 REAL8 logdmin, logdmax;
1168
1169 LALInferenceGetMinMaxPrior(thread->priorArgs, "logdistance", &logdmin, &logdmax);
1170
1171 REAL8 dmin=exp(logdmin);
1172 REAL8 dmax=exp(logdmax);
1173
1174 REAL8 x = gsl_rng_uniform(thread->GSLrandom);
1175
1176 return log(cbrt(x*(dmax*dmax*dmax - dmin*dmin*dmin) + dmin*dmin*dmin));
1177}
1178
1179static REAL8 draw_colatitude(LALInferenceThreadState *thread, const char *name) {
1180 REAL8 min, max, x;
1181
1182 LALInferenceGetMinMaxPrior(thread->priorArgs, name, &min, &max);
1183
1184 x = gsl_rng_uniform(thread->GSLrandom);
1185
1186 return acos(cos(min) - x*(cos(min) - cos(max)));
1187}
1188
1190 REAL8 min, max, x;
1191
1192 LALInferenceGetMinMaxPrior(thread->priorArgs, "declination", &min, &max);
1193
1194 x = gsl_rng_uniform(thread->GSLrandom);
1195
1196 return asin(x*(sin(max) - sin(min)) + sin(min));
1197}
1198
1199static REAL8 draw_flat(LALInferenceThreadState *thread, const char *name) {
1200 REAL8 min, max, x;
1201
1202 LALInferenceGetMinMaxPrior(thread->priorArgs, name, &min, &max);
1203
1204 x = gsl_rng_uniform(thread->GSLrandom);
1205
1206 return min + x*(max - min);
1207}
1208
1210 REAL8 min, max, delta;
1211 REAL8 mMin56, mMax56, u;
1212
1213 LALInferenceGetMinMaxPrior(thread->priorArgs, "chirpmass", &min, &max);
1214
1215 mMin56 = pow(min, 5.0/6.0);
1216 mMax56 = pow(max, 5.0/6.0);
1217
1218 delta = 1.0/mMin56 - 1.0/mMax56;
1219
1220 u = delta*gsl_rng_uniform(thread->GSLrandom);
1221
1222 return pow(1.0/(1.0/mMin56 - u), 6.0/5.0);
1223}
1224
1226 REAL8 logP = 0.0;
1227
1228 if(LALInferenceCheckVariable(params, "chirpmass")) {
1229 REAL8 Mc = *(REAL8 *)LALInferenceGetVariable(params, "chirpmass");
1230 logP += -11.0/6.0*log(Mc);
1231 }
1232
1233 /* Flat in time, ra, psi, phi. */
1234
1235 if(LALInferenceCheckVariable(params,"logdistance"))
1236 logP += 3.0* *(REAL8 *)LALInferenceGetVariable(params,"logdistance");
1237 else if(LALInferenceCheckVariable(params,"distance"))
1238 logP += 2.0*log(*(REAL8 *)LALInferenceGetVariable(params,"distance"));
1239
1240 if(LALInferenceCheckVariable(params,"declination"))
1241 logP += log(cos(*(REAL8 *)LALInferenceGetVariable(params, "declination")));
1242
1243 if (LALInferenceCheckVariable(params, "tilt_spin1")) {
1244 logP += log(fabs(sin(*(REAL8 *)LALInferenceGetVariable(params, "tilt_spin1"))));
1245 }
1246
1247 if (LALInferenceCheckVariable(params, "tilt_spin2")) {
1248 logP += log(fabs(sin(*(REAL8 *)LALInferenceGetVariable(params, "tilt_spin2"))));
1249 }
1250
1251 return logP;
1252}
1253
1254/* WARNING: If you add any non-flat draws to this proposal, you MUST
1255 update the above approxLogPrior function with the corresponding
1256 density. The proposal ratio is calculated using approxLogPrior, so
1257 non-flat proposals that do not have a corresponding density term in
1258 approxLogPrior will result in a failure to sample from the
1259 posterior density! */
1262 LALInferenceVariables *proposedParams) {
1263 REAL8 tmp = 0.0;
1264 INT4 analytic_test, i;
1265 REAL8 logBackwardJump = 0.0;
1266 REAL8 logPropRatio;
1268
1270
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};
1275
1277
1278 analytic_test = LALInferenceGetINT4Variable(args, "analytical_test");
1279
1280 if (analytic_test) {
1282 while (ptr!=NULL) {
1284 tmp = draw_flat(thread, ptr->name);
1285 LALInferenceSetVariable(proposedParams, ptr->name, &tmp);
1286 }
1287 ptr=ptr->next;
1288 }
1289 } else {
1290 logBackwardJump = approxLogPrior(currentParams);
1291
1292 for (i = 0; flat_params[i] != NULL; i++) {
1293 if (LALInferenceCheckVariableNonFixed(proposedParams, flat_params[i])) {
1294 REAL8 val = draw_flat(thread, flat_params[i]);
1295 LALInferenceSetVariable(proposedParams, flat_params[i], &val);
1296 }
1297 }
1298
1299 if (LALInferenceCheckVariableNonFixed(proposedParams, "chirpmass")) {
1300 REAL8 Mc = draw_chirp(thread);
1301 LALInferenceSetVariable(proposedParams, "chirpmass", &Mc);
1302 }
1303
1304 if (LALInferenceCheckVariableNonFixed(proposedParams, "logdistance")) {
1305 REAL8 logdist = draw_logdistance(thread);
1306 LALInferenceSetVariable(proposedParams, "logdistance", &logdist);
1307 } else if (LALInferenceCheckVariableNonFixed(proposedParams, "distance")) {
1308 REAL8 dist = draw_distance(thread);
1309 LALInferenceSetVariable(proposedParams, "distance", &dist);
1310 }
1311
1312 if (LALInferenceCheckVariableNonFixed(proposedParams, "declination")) {
1313 REAL8 dec = draw_dec(thread);
1314 LALInferenceSetVariable(proposedParams, "declination", &dec);
1315 }
1316
1317 if (LALInferenceCheckVariableNonFixed(proposedParams, "tilt_spin1")) {
1318 REAL8 tilt1 = draw_colatitude(thread, "tilt_spin1");
1319 LALInferenceSetVariable(proposedParams, "tilt_spin1", &tilt1);
1320 }
1321
1322 if (LALInferenceCheckVariableNonFixed(proposedParams, "tilt_spin2")) {
1323 REAL8 tilt2 = draw_colatitude(thread, "tilt_spin2");
1324 LALInferenceSetVariable(proposedParams, "tilt_spin2", &tilt2);
1325 }
1326
1327 if (LALInferenceCheckVariableNonFixed(proposedParams, "psdscale")) {
1328 REAL8 x, min, max;
1329 INT4 j;
1330
1331 min=0.10;
1332 max=10.0;
1333
1334 gsl_matrix *eta = LALInferenceGetgslMatrixVariable(proposedParams, "psdscale");
1335
1336 for(i=0; i<(INT8)eta->size1; i++) {
1337 for(j=0; j<(INT8)eta->size2; j++) {
1338 x = min + gsl_rng_uniform(thread->GSLrandom) * (max - min);
1339 gsl_matrix_set(eta, i, j, x);
1340 }
1341 }
1342 }//end if(psdscale)
1343 }
1344
1345 if (analytic_test) {
1346 /* Flat in every variable means uniform jump probability. */
1347 logPropRatio = 0.0;
1348 } else {
1349 logPropRatio = logBackwardJump - approxLogPrior(proposedParams);
1350 }
1351
1352 return logPropRatio;
1353}
1354
1356 REAL8 logPropRatio = 0., tmp = 0.;
1357
1360
1361 while(ptr!=NULL) {
1362 if(ptr->vary != LALINFERENCE_PARAM_FIXED && LALInferenceCheckMinMaxPrior(threadState->priorArgs, ptr->name ) ) {
1363 tmp = draw_flat(threadState, ptr->name);
1364 LALInferenceSetVariable(proposedParams, ptr->name, &tmp);
1365 }
1366 ptr=ptr->next;
1367 }
1368
1369 return logPropRatio;
1370}
1371
1372static void cross_product(REAL8 x[3], const REAL8 y[3], const REAL8 z[3]) {
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];
1376}
1377
1378static REAL8 norm(const REAL8 x[3]) {
1379 return sqrt(x[0]*x[0] + x[1]*x[1] + x[2]*x[2]);
1380}
1381
1382static void unit_vector(REAL8 v[3], const REAL8 w[3]) {
1383 REAL8 n = norm(w);
1384
1385 if (n == 0.0) {
1386 XLALError("unit_vector", __FILE__, __LINE__, XLAL_FAILURE);
1387 abort();
1388 } else {
1389 v[0] = w[0] / n;
1390 v[1] = w[1] / n;
1391 v[2] = w[2] / n;
1392 }
1393}
1394
1395static REAL8 dot(const REAL8 v[3], const REAL8 w[3]) {
1396 return v[0]*w[0] + v[1]*w[1] + v[2]*w[2];
1397}
1398
1399static void project_along(REAL8 vproj[3], const REAL8 v[3], const REAL8 w[3]) {
1400 REAL8 what[3];
1401 REAL8 vdotw;
1402
1403 unit_vector(what, w);
1404 vdotw = dot(v, w);
1405
1406 vproj[0] = what[0]*vdotw;
1407 vproj[1] = what[1]*vdotw;
1408 vproj[2] = what[2]*vdotw;
1409}
1410
1411static void vsub(REAL8 diff[3], const REAL8 w[3], const REAL8 v[3]) {
1412 diff[0] = w[0] - v[0];
1413 diff[1] = w[1] - v[1];
1414 diff[2] = w[2] - v[2];
1415}
1416
1417static void reflect_plane(REAL8 pref[3], const REAL8 p[3],
1418 const REAL8 x[3], const REAL8 y[3], const REAL8 z[3]) {
1419 REAL8 n[3], nhat[3], xy[3], xz[3], pn[3], pnperp[3];
1420
1421 vsub(xy, y, x);
1422 vsub(xz, z, x);
1423
1424 cross_product(n, xy, xz);
1425 unit_vector(nhat, n);
1426
1427 project_along(pn, p, nhat);
1428 vsub(pnperp, p, pn);
1429
1430 vsub(pref, pnperp, pn);
1431}
1432
1433static void get_detectors(LALInferenceIFOData *data, LALDetector **detectors) {
1434 INT4 i;
1435 INT4 nDet = 0;
1437 for (i=0,ifo=data; ifo; i++,ifo=ifo->next)
1438 nDet++;
1439
1440 *detectors = XLALCalloc(nDet, sizeof(LALDetector));
1441 for (i=0,ifo=data; ifo; i++,ifo=ifo->next)
1442 *detectors[i] = *(ifo->detector);
1443}
1444
1445static void sph_to_cart(REAL8 cart[3], const REAL8 lat, const REAL8 longi) {
1446 cart[0] = cos(longi)*cos(lat);
1447 cart[1] = sin(longi)*cos(lat);
1448 cart[2] = sin(lat);
1449}
1450
1451static void cart_to_sph(const REAL8 cart[3], REAL8 *lat, REAL8 *longi) {
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]));
1454}
1455
1456static void reflected_position_and_time(LALInferenceThreadState *thread, const REAL8 ra, const REAL8 dec,
1457 const REAL8 oldTime, REAL8 *newRA, REAL8 *newDec, REAL8 *newTime) {
1459 memset(&status, 0, sizeof(status));
1460 SkyPosition currentEqu, currentGeo, newEqu, newGeo;
1463 REAL8 x[3], y[3], z[3];
1464 REAL8 currentLoc[3], newLoc[3];
1465 REAL8 newGeoLat, newGeoLongi;
1466 REAL8 oldDt, newDt;
1467 LALDetector xD, yD, zD;
1468
1469 currentEqu.latitude = dec;
1470 currentEqu.longitude = ra;
1473
1474 epoch = thread->parent->data->epoch;
1475 get_detectors(thread->parent->data, &detectors);
1476
1477 LALEquatorialToGeographic(&status, &currentGeo, &currentEqu, &epoch);
1478
1479 /* This function should only be called when we know that we have
1480 three detectors, or the following will crash. */
1481 xD = detectors[0];
1482 memcpy(x, xD.location, 3*sizeof(REAL8));
1483
1484 INT4 det = 1;
1485 yD = detectors[det];
1486 while (same_detector_location(&yD, &xD)) {
1487 det++;
1488 yD = detectors[det];
1489 }
1490 memcpy(y, yD.location, 3*sizeof(REAL8));
1491 det++;
1492
1493 zD = detectors[det];
1494 while (same_detector_location(&zD, &yD) || same_detector_location(&zD, &xD)) {
1495 det++;
1496 zD = detectors[det];
1497 }
1498 memcpy(z, zD.location, 3*sizeof(REAL8));
1499
1500 sph_to_cart(currentLoc, currentGeo.latitude, currentGeo.longitude);
1501
1502 reflect_plane(newLoc, currentLoc, x, y, z);
1503
1504 cart_to_sph(newLoc, &newGeoLat, &newGeoLongi);
1505
1506 newGeo.latitude = newGeoLat;
1507 newGeo.longitude = newGeoLongi;
1510 LALGeographicToEquatorial(&status, &newEqu, &newGeo, &epoch);
1511
1512 oldDt = XLALTimeDelayFromEarthCenter(detectors[0].location, currentEqu.longitude,
1513 currentEqu.latitude, &epoch);
1514 newDt = XLALTimeDelayFromEarthCenter(detectors[0].location, newEqu.longitude,
1515 newEqu.latitude, &epoch);
1516
1517 *newRA = newEqu.longitude;
1518 *newDec = newEqu.latitude;
1519 *newTime = oldTime + oldDt - newDt;
1520
1522}
1523
1525 LALInferenceVariables *proposedParams,
1526 INT4 ifo, INT4 k) {
1527 REAL8 prior = 0.0;
1528 REAL8 component_min,component_max;
1529 REAL8 A, f, Q, Anorm;
1530 gsl_matrix *glitch_f, *glitch_Q, *glitch_A;
1531
1532 component_min = LALInferenceGetREAL8Variable(thread->priorArgs,"morlet_f0_prior_min");
1533 component_max = LALInferenceGetREAL8Variable(thread->priorArgs,"morlet_f0_prior_max");
1534 prior -= log(component_max - component_min);
1535
1536 component_min = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_Q_prior_min");
1537 component_max = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_Q_prior_max");
1538 prior -= log(component_max - component_min);
1539
1540 component_min = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_t0_prior_min");
1541 component_max = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_t0_prior_max");
1542 prior -= log(component_max - component_min);
1543
1544 component_min = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_phi_prior_min");
1545 component_max = LALInferenceGetREAL8Variable(thread->priorArgs, "morlet_phi_prior_max");
1546 prior -= log(component_max - component_min);
1547
1548 //"Malmquist" prior on A
1549 glitch_f = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
1550 glitch_Q = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
1551 glitch_A = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
1552
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);
1556
1557 Anorm = LALInferenceGetREAL8Variable(thread->priorArgs, "glitch_norm");
1558
1559 prior += logGlitchAmplitudeDensity(A*Anorm, Q, f);
1560
1561 return prior;
1562}
1563
1564
1565static REAL8 glitchAmplitudeDraw(REAL8 Q, REAL8 f, gsl_rng *r) {
1566 REAL8 SNR;
1567 REAL8 PIterm = 0.5*LAL_2_SQRTPI*LAL_SQRT1_2;
1568 REAL8 SNRPEAK = 5.0;
1569
1570 REAL8 den=0.0, alpha=1.0;
1571 REAL8 max= 1.0/(SNRPEAK*LAL_E);;
1572
1573 // x/a^2 exp(-x/a) prior on SNR. Peaks at x = a. Good choice is a=5
1574
1575 // rejection sample. Envelope function on runs out to ten times the peak
1576 // don't even bother putting in this minute correction to the normalization
1577 // (it is a 5e-4 correction).
1578 do {
1579 SNR = 20.0 * SNRPEAK * gsl_rng_uniform(r);
1580
1581 den = SNR/(SNRPEAK*SNRPEAK) * exp(-SNR/SNRPEAK);
1582
1583 den /= max;
1584
1585 alpha = gsl_rng_uniform(r);
1586 } while (alpha > den);
1587
1588 return SNR/sqrt((PIterm*Q/f));
1589}
1590
1593 LALInferenceVariables *proposedParams) {
1594 INT4 i, j, l;
1595 INT4 ifo, nifo, timeflag=0;
1596 REAL8 logPropRatio = 0.0;
1597 REAL8 ra, dec;
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];
1603 REAL8 IFOX[3], k[3];
1604 REAL8 normalize;
1605 REAL8 pForward, pReverse;
1606 REAL8 n[3];
1607 REAL8 kp[3];
1608 LIGOTimeGPS GPSlal, epoch;
1610 gsl_matrix *IFO;
1611
1613
1615 gsl_rng *rng = thread->GSLrandom;
1616
1617 epoch = thread->parent->data->epoch;
1618 get_detectors(thread->parent->data, &detectors);
1619
1620 ra = LALInferenceGetREAL8Variable(proposedParams, "rightascension");
1621 dec = LALInferenceGetREAL8Variable(proposedParams, "declination");
1622
1623 if (LALInferenceCheckVariable(proposedParams, "time")){
1624 baryTime = LALInferenceGetREAL8Variable(proposedParams, "time");
1625 timeflag = 1;
1626 } else {
1627 baryTime = XLALGPSGetREAL8(&epoch);
1628 }
1629
1630 XLALGPSSetREAL8(&GPSlal, baryTime);
1631 gmst = XLALGreenwichMeanSiderealTime(&GPSlal);
1632
1633 //remap gmst back to [0:2pi]
1634 gmst /= LAL_TWOPI;
1635 intpart = (INT4)gmst;
1636 decpart = gmst - (REAL8)intpart;
1637 gmst = decpart*LAL_TWOPI;
1638 gmst = gmst < 0. ? gmst + LAL_TWOPI : gmst;
1639
1640 /*
1641 line-of-sight vector
1642 */
1643 k[0] = cos(gmst-ra) * cos(dec);
1644 k[1] =-sin(gmst-ra) * cos(dec);
1645 k[2] = sin(dec);
1646
1647 /*
1648 Store location for each detector
1649 */
1650 nifo = LALInferenceGetINT4Variable(args, "nDet");
1651
1652 IFO = gsl_matrix_alloc(nifo, 3);
1653
1654 for(ifo=0; ifo<nifo; ifo++) {
1655 memcpy(IFOX, detectors[ifo].location, 3*sizeof(REAL8));
1656 for (i=0; i<3; i++)
1657 gsl_matrix_set(IFO, ifo, i, IFOX[i]);
1658 }
1659
1660 /*
1661 Randomly select two detectors from the network
1662 -this assumes there are no co-located detectors
1663 */
1664 i = j = 0;
1665 while (i==j) {
1666 i=gsl_rng_uniform_int(rng, nifo);
1667 j=gsl_rng_uniform_int(rng, nifo);
1668 }
1669
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);
1673 }
1674
1675 /*
1676 detector axis
1677 */
1678 normalize=0.0;
1679 for(i=0; i<3; i++) {
1680 n[i] = IFO1[i] - IFO2[i];
1681 normalize += n[i] * n[i];
1682 }
1683 normalize = 1./sqrt(normalize);
1684 for(i=0; i<3; i++)
1685 n[i] *= normalize;
1686
1687 /*
1688 rotation angle
1689 */
1690 omega = LAL_TWOPI * gsl_rng_uniform(rng);
1691 cosomega = cos(omega);
1692 sinomega = sin(omega);
1693 c1momega = 1.0 - cosomega;
1694
1695 /*
1696 rotate k' = Rk
1697 */
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];
1707
1708 /*
1709 convert k' back to ra' and dec'
1710 */
1711 newDec = asin(kp[2]);
1712 newRA = atan2(kp[1], kp[0]) + gmst;
1713 if (newRA < 0.0)
1714 newRA += LAL_TWOPI;
1715 else if (newRA >= LAL_TWOPI)
1716 newRA -= LAL_TWOPI;
1717 /*
1718 compute new geocenter time using
1719 fixed arrival time at IFO1 (arbitrary)
1720 */
1721 REAL8 tx; //old time shift = k * n
1722 REAL8 ty; //new time shift = k'* n
1723 tx=ty=0;
1724 for(i=0; i<3; i++) {
1725 tx += -IFO1[i]*k[i] /LAL_C_SI;
1726 ty += -IFO1[i]*kp[i]/LAL_C_SI;
1727 }
1728 newTime = tx + baryTime - ty;
1729
1730 XLALGPSSetREAL8(&GPSlal, newTime);
1731
1732 /*
1733 draw new polarisation angle uniformally
1734 for now
1735 MARK: Need to be smarter about psi in sky-ring jump
1736 */
1737 newPsi = LAL_PI * gsl_rng_uniform(rng);
1738
1739 LALInferenceSetVariable(proposedParams, "polarisation", &newPsi);
1740 LALInferenceSetVariable(proposedParams, "rightascension", &newRA);
1741 LALInferenceSetVariable(proposedParams, "declination", &newDec);
1742 if (timeflag)
1743 LALInferenceSetVariable(proposedParams, "time", &newTime);
1744
1745 pForward = cos(newDec);
1746 pReverse = cos(dec);
1747
1748 gsl_matrix_free(IFO);
1749
1750 logPropRatio = log(pReverse/pForward);
1751
1753
1754 return logPropRatio;
1755}
1756
1759 LALInferenceVariables *proposedParams) {
1760 INT4 timeflag=0;
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;
1768 INT4 nUniqueDet;
1770
1771
1772 /* Find the number of distinct-position detectors. */
1773 /* Exit with same parameters (with a warning the first time) if
1774 there are not three detectors. */
1775 static INT4 warningDelivered = 0;
1776
1778 gsl_rng *rng = thread->GSLrandom;
1779
1780 epoch = thread->parent->data->epoch;
1781 nUniqueDet = LALInferenceGetINT4Variable(args, "nUniqueDet");
1782
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;
1790 }
1791
1792 return logPropRatio;
1793 }
1795
1796 ra = LALInferenceGetREAL8Variable(currentParams, "rightascension");
1797 dec = LALInferenceGetREAL8Variable(currentParams, "declination");
1798
1800 baryTime = LALInferenceGetREAL8Variable(currentParams, "time");
1801 timeflag=1;
1802 } else {
1803 baryTime = XLALGPSGetREAL8(&epoch);
1804 }
1805
1806 reflected_position_and_time(thread, ra, dec, baryTime, &newRA, &newDec, &newTime);
1807
1808 /* Unit normal deviates, used to "fuzz" the state. */
1809 const REAL8 epsTime = 6e-6; /* 1e-1 / (16 kHz) */
1810 const REAL8 epsAngle = 3e-4; /* epsTime*c/R_Earth */
1811
1812 nRA = gsl_ran_ugaussian(rng);
1813 nDec = gsl_ran_ugaussian(rng);
1814 nTime = gsl_ran_ugaussian(rng);
1815
1816 newRA += epsAngle*nRA;
1817 newDec += epsAngle*nDec;
1818 newTime += epsTime*nTime;
1819
1820 /* And the doubly-reflected position (near the original, but not
1821 exactly due to the fuzzing). */
1822 reflected_position_and_time(thread, newRA, newDec, newTime, &refRA, &refDec, &refTime);
1823
1824 /* The Gaussian increments required to shift us back to the original
1825 position from the doubly-reflected position. */
1826 nRefRA = (ra - refRA)/epsAngle;
1827 nRefDec = (dec - refDec)/epsAngle;
1828 nRefTime = (baryTime - refTime)/epsTime;
1829
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);
1832
1833 LALInferenceSetVariable(proposedParams, "rightascension", &newRA);
1834 LALInferenceSetVariable(proposedParams, "declination", &newDec);
1835
1836 if (timeflag)
1837 LALInferenceSetVariable(proposedParams, "time", &newTime);
1838
1839 logPropRatio = log(pReverse/pForward);
1840
1841 return logPropRatio;
1842}
1843
1846 LALInferenceVariables *proposedParams) {
1847 INT4 i,j;
1848 INT4 N, nifo;
1849 REAL8 draw=0.0;
1850 REAL8 logPropRatio = 0.0;
1851 REAL8Vector *var;
1852 gsl_matrix *ny;
1853
1855
1856 var = LALInferenceGetREAL8VectorVariable(thread->proposalArgs, "psdsigma");
1857
1858 //Get current state of chain into workable form
1859 ny = LALInferenceGetgslMatrixVariable(proposedParams, "psdscale");
1860
1861 //Get size of noise parameter array
1862 nifo = (INT4)ny->size1;
1863 N = (INT4)ny->size2;
1864
1865 //perturb noise parameter
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);
1870 }
1871 }
1872
1873 return logPropRatio;
1874}
1875
1877 LALInferenceVariables *proposedParams,
1878 gsl_matrix *glitchFD, INT4 ifo, INT4 n, INT4 flag) {
1879 INT4 i=0;
1880 INT4 lower, upper;
1881 INT4 glitchLower, glitchUpper;
1882 REAL8FrequencySeries **asds, *asd = NULL;
1883 REAL8Vector *flows;
1884 REAL8 deltaT, Tobs, deltaF;
1885 REAL8 Q, Amp, t0, ph0, f0; //sine-Gaussian parameters
1886 REAL8 amparg, phiarg, Ai;//helpers for computing sineGaussian
1887 REAL8 gRe, gIm; //real and imaginary parts of current glitch model
1888 REAL8 tau;
1889 gsl_matrix *glitch_f, *glitch_Q, *glitch_A;
1890 gsl_matrix *glitch_t, *glitch_p;
1891 REAL8TimeSeries **td_data;
1892
1894
1895 /* FIXME: can't store arrays of REAL8FrequencySeries in LI
1896 Variables (any more?)
1897
1898 Need instead Nifo variables called "asdH1", "asdL1", ...
1899 */
1901 flows = LALInferenceGetREAL8VectorVariable(args, "flows");
1902 td_data = *(REAL8TimeSeries ***)LALInferenceGetVariable(args, "td_data");
1903
1904 /* get dataPtr pointing to correct IFO */
1905 asd = asds[ifo];
1906
1907 deltaT = td_data[ifo]->deltaT;
1908 Tobs = (((REAL8)td_data[ifo]->data->length) * deltaT);
1909 deltaF = 1.0 / Tobs;
1910
1911 lower = (INT4)ceil(flows->data[ifo] / deltaF);
1912 upper = (INT4)floor(flows->data[ifo] / deltaF);
1913
1914 glitch_f = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
1915 glitch_Q = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
1916 glitch_A = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
1917 glitch_t = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_t0");
1918 glitch_p = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_phi");
1919
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);
1925
1926 //6 x decay time of sine Gaussian (truncate how much glitch we compute)
1927 tau = Q/LAL_TWOPI/f0;
1928 glitchLower = (INT4)floor((f0 - 1./tau)/deltaF);
1929 glitchUpper = (INT4)floor((f0 + 1./tau)/deltaF);
1930
1931 //set glitch model to zero
1932 if (flag==0) {
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);
1936 }
1937 }
1938
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);
1943 amparg = ((REAL8)i*deltaF - f0)*LAL_PI*tau;
1944 phiarg = LAL_PI*(REAL8)i + ph0 - LAL_TWOPI*(REAL8)i*deltaF*(t0-Tobs/2.);//TODO: SIMPLIFY PHASE FOR SINEGAUSSIAN
1945 Ai = Amp*tau*0.5*sqrt(LAL_PI)*exp(-amparg*amparg)*asd->data->data[i]/sqrt(Tobs);
1946
1947 switch(flag) {
1948 // Remove wavelet from model
1949 case -1:
1950 gRe -= Ai*cos(phiarg);
1951 gIm -= Ai*sin(phiarg);
1952 break;
1953 // Add wavelet to model
1954 case 1:
1955 gRe += Ai*cos(phiarg);
1956 gIm += Ai*sin(phiarg);
1957 break;
1958 // Replace model with wavelet
1959 case 0:
1960 gRe = Ai*cos(phiarg);
1961 gIm = Ai*sin(phiarg);
1962 break;
1963 //Do nothing
1964 default:
1965 break;
1966 }//end switch
1967
1968 //update glitch model
1969 gsl_matrix_set(glitchFD, ifo, 2*i, gRe);
1970 gsl_matrix_set(glitchFD, ifo, 2*i+1, gIm);
1971
1972 }//end upper/lower check
1973 }//end loop over glitch samples
1974}
1975
1977 REAL8 f0;
1978 REAL8 Q;
1979 REAL8 Amp;
1980
1981 REAL8 sigma_t0;
1982 REAL8 sigma_f0;
1983 REAL8 sigma_Q;
1984 REAL8 sigma_Amp;
1985 REAL8 sigma_phi0;
1986
1987 REAL8 SNR = 0.0;
1988 REAL8 sqrt3 = 1.7320508;
1989
1990 f0 = params->data[1];
1991 Q = params->data[2];
1992 Amp = params->data[3];
1993
1994 SNR = Amp*sqrt(Q/(2.0*sqrt(LAL_TWOPI)*f0));
1995
1996 // this caps the size of the proposed jumps
1997 if(SNR < 5.0) SNR = 5.0;
1998
1999 sigma_t0 = 1.0/(LAL_TWOPI*f0*SNR);
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;
2004
2005 // Map diagonal Fisher elements to sigmas vector
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;
2011}
2012
2015 LALInferenceVariables *proposedParams) {
2016 INT4 i, ifo;
2017 INT4 n;
2018
2019 REAL8 logPropRatio = 0.0;
2020 REAL8 t0;
2021 REAL8 f0;
2022 REAL8 Q;
2023 REAL8 Amp;
2024 REAL8 phi0;
2025
2026 REAL8 scale;
2027
2028 REAL8 qyx;
2029 REAL8 qxy;
2030 REAL8 Anorm;
2031
2033
2034 gsl_matrix *glitchFD, *glitch_f, *glitch_Q, *glitch_A, *glitch_t, *glitch_p;
2035
2036 gsl_rng *rng = thread->GSLrandom;
2037 /*
2038 Vectors to store wavelet parameters.
2039 Order:
2040 [0] t0
2041 [1] f0
2042 [2] Q
2043 [3] Amp
2044 [4] phi0
2045 */
2046 REAL8Vector *params_x = XLALCreateREAL8Vector(5);
2047 REAL8Vector *params_y = XLALCreateREAL8Vector(5);
2048
2049 REAL8Vector *sigmas_x = XLALCreateREAL8Vector(5);
2050 REAL8Vector *sigmas_y = XLALCreateREAL8Vector(5);
2051
2052 /* Get glitch meta paramters (dimnsion, proposal) */
2053 UINT4Vector *gsize = LALInferenceGetUINT4VectorVariable(proposedParams, "glitch_size");
2054
2055 glitchFD = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_FD");
2056 glitch_f = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
2057 glitch_Q = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
2058 glitch_A = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
2059 glitch_t = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_t0");
2060 glitch_p = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_phi");
2061
2062 Anorm = LALInferenceGetREAL8Variable(thread->priorArgs, "glitch_norm");
2063
2064 /* Choose which IFO */
2065 ifo = (INT4)floor(gsl_rng_uniform(rng) * (REAL8)(gsize->length));
2066
2067 /* Bail out of proposal if no wavelets */
2068 if (gsize->data[ifo]==0) {
2069 XLALDestroyREAL8Vector(params_x);
2070 XLALDestroyREAL8Vector(params_y);
2071 XLALDestroyREAL8Vector(sigmas_x);
2072 XLALDestroyREAL8Vector(sigmas_y);
2073
2074 return logPropRatio;
2075 }
2076
2077 /* Choose which glitch */
2078 n = (INT4)floor(gsl_rng_uniform(rng) * (REAL8)(gsize->data[ifo]));
2079
2080 /* Remove wavlet form linear combination */
2081 UpdateWaveletSum(thread, proposedParams, glitchFD, ifo, n, -1);
2082
2083 /* Get parameters of n'th glitch int params vector */
2084 t0 = gsl_matrix_get(glitch_t, ifo, n); //Centroid time
2085 f0 = gsl_matrix_get(glitch_f, ifo, n); //Frequency
2086 Q = gsl_matrix_get(glitch_Q, ifo, n); //Quality
2087 Amp = gsl_matrix_get(glitch_A, ifo, n); //Amplitude
2088 phi0 = gsl_matrix_get(glitch_p, ifo, n); //Centroid phase
2089
2090
2091 /* Map to params Vector and compute Fisher */
2092 params_x->data[0] = t0;
2093 params_x->data[1] = f0;
2094 params_x->data[2] = Q;
2095 params_x->data[3] = Amp * (0.25*Anorm);//TODO: What is the 0.25*Anorm about?
2096 params_x->data[4] = phi0;
2097
2098 MorletDiagonalFisherMatrix(params_x, sigmas_x);
2099
2100 /* Jump from x -> y: y = x + N[0,sigmas_x]*scale */
2101 scale = 0.4082482; // 1/sqrt(6)
2102
2103 for(i=0; i<5; i++)
2104 params_y->data[i] = params_x->data[i] + gsl_ran_ugaussian(rng)*sigmas_x->data[i]*scale;
2105
2106 /* Set parameters of n'th glitch int params vector */
2107 /* Map to params Vector and compute Fisher */
2108 t0 = params_y->data[0];
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];
2113
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);
2119
2120 /* Add wavlet to linear combination */
2121 UpdateWaveletSum(thread, proposedParams, glitchFD, ifo, n, 1);
2122
2123 /* Now compute proposal ratio using Fisher at y */
2124 MorletDiagonalFisherMatrix(params_y, sigmas_y);
2125
2126 REAL8 sx = 1.0; // sigma
2127 REAL8 sy = 1.0;
2128 REAL8 dx = 1.0; // (params_x - params_y)/sigma
2129 REAL8 dy = 1.0;
2130 REAL8 exy = 0.0; // argument of exponential part of q
2131 REAL8 eyx = 0.0;
2132 REAL8 nxy = 1.0; // argument of normalization part of q
2133 REAL8 nyx = 1.0; // (computed as product to avoid too many log()s )
2134 for(i=0; i<5; i++) {
2135 sx = scale*sigmas_x->data[i];
2136 sy = scale*sigmas_y->data[i];
2137
2138 dx = (params_x->data[i] - params_y->data[i])/sx;
2139 dy = (params_x->data[i] - params_y->data[i])/sy;
2140
2141 nxy *= sy;
2142 nyx *= sx;
2143
2144 exy += -dy*dy/2.0;
2145 eyx += -dx*dx/2.0;
2146 }
2147
2148 qyx = eyx - log(nyx); //probabiltiy of proposing y given x
2149 qxy = exy - log(nxy); //probability of proposing x given y
2150
2151 logPropRatio = qxy-qyx;
2152
2153 XLALDestroyREAL8Vector(params_x);
2154 XLALDestroyREAL8Vector(params_y);
2155
2156 XLALDestroyREAL8Vector(sigmas_x);
2157 XLALDestroyREAL8Vector(sigmas_y);
2158
2159 return logPropRatio;
2160}
2161
2164 LALInferenceVariables *proposedParams) {
2165 INT4 i,n;
2166 INT4 ifo;
2167 INT4 rj, nx, ny;
2168 REAL8 draw;
2169 REAL8 val, Anorm;
2170 REAL8 t=0, f=0, Q=0, A=0;
2171 REAL8 qx = 0.0; //log amp proposals
2172 REAL8 qy = 0.0;
2173 REAL8 qyx = 0.0; //log pixel proposals
2174 REAL8 qxy = 0.0;
2175 REAL8 pForward = 0.0; //combined p() & q() probabilities for ...
2176 REAL8 pReverse = 0.0; //...RJMCMC hastings ratio
2177 REAL8 logPropRatio = 0.0;
2178 INT4 adapting=1;
2179 gsl_matrix *params = NULL;
2180
2181 gsl_rng *rng = thread->GSLrandom;
2182 LALInferenceVariables *propArgs = thread->proposalArgs;
2183
2185
2186 UINT4Vector *gsize = LALInferenceGetUINT4VectorVariable(proposedParams, "glitch_size");
2187 gsl_matrix *glitchFD = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_FD");
2188
2189 INT4 nmin = (INT4)(LALInferenceGetREAL8Variable(thread->priorArgs,"glitch_dim_min"));
2190 INT4 nmax = (INT4)(LALInferenceGetREAL8Variable(thread->priorArgs,"glitch_dim_max"));
2191
2192 if (LALInferenceCheckVariable(propArgs, "adapting"))
2193 adapting = LALInferenceGetINT4Variable(propArgs, "adapting");
2194
2195 /* Choose which IFO */
2196 ifo = (INT4)floor(gsl_rng_uniform(rng) * (REAL8)(gsize->length) );
2197 nx = gsize->data[ifo];
2198
2199 /* Choose birth or death move */
2200 draw = gsl_rng_uniform(rng);
2201 if (draw < 0.5)
2202 rj = 1;
2203 else
2204 rj = -1;
2205
2206 /* find dimension of proposed model */
2207 ny = nx + rj;
2208
2209 /* Check that new dimension is allowed */
2210 if(ny<nmin || ny>=nmax) {
2211 logPropRatio = -INFINITY;
2212 return logPropRatio;
2213 }
2214
2215 switch(rj) {
2216 /* Birth */
2217 case 1:
2218 //Add new wavelet to glitch model
2219 t = draw_flat(thread, "morlet_t0_prior");
2220 f = draw_flat(thread, "morlet_f0_prior");
2221
2222 //Centroid time
2223 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_t0");
2224 gsl_matrix_set(params, ifo, nx, t);
2225
2226 //Frequency
2227 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
2228 gsl_matrix_set(params, ifo, nx, f);
2229
2230 //Quality
2231 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
2232 val = draw_flat(thread, "morlet_Q_prior");
2233 gsl_matrix_set(params, ifo, nx, val);
2234 Q = val;
2235
2236 //Amplitude
2237 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
2238 val = glitchAmplitudeDraw(Q, f, rng);
2239 Anorm = LALInferenceGetREAL8Variable(thread->priorArgs, "glitch_norm");
2240 A = val/Anorm;
2241
2242 gsl_matrix_set(params, ifo, nx, A);
2243
2244 //Centroid phase
2245 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_phi");
2246 val = draw_flat(thread, "morlet_phi_prior");
2247 gsl_matrix_set(params, ifo, nx, val);
2248
2249 //Add wavlet to linear combination
2250 UpdateWaveletSum(thread, proposedParams, glitchFD, ifo, nx, 1);
2251
2252 //Compute probability of drawing parameters
2253 qy = evaluate_morlet_proposal(thread, proposedParams, ifo, nx);// + log(gsl_matrix_get(power,ifo,k));
2254
2255 //Compute reverse probability of dismissing k
2256 qxy = 0.0;//-log((double)runState->data->freqData->data->length);//-log( (REAL8)ny );
2257
2258 if (adapting)
2259 qy += 10.0;
2260
2261 break;
2262
2263 /* Death */
2264 case -1:
2265 //Choose wavelet to remove from glitch model
2266 draw = gsl_rng_uniform(rng);
2267 n = (INT4)(floor(draw * (REAL8)nx)); //choose which hot pixel
2268
2269 // Remove wavlet from linear combination
2270 UpdateWaveletSum(thread, proposedParams, glitchFD, ifo, n, -1);
2271
2272 //Get t and f of removed wavelet
2273 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
2274 f = gsl_matrix_get(params, ifo, n);
2275 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_t0");
2276 t = gsl_matrix_get(params, ifo, n);
2277 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
2278 Q = gsl_matrix_get(params, ifo, n);
2279 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
2280 A = gsl_matrix_get(params, ifo, n);
2281
2282 //Shift morlet parameters to fill in array
2283 for(i=n; i<ny; i++) {
2284 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_f0");
2285 gsl_matrix_set(params, ifo, i, gsl_matrix_get(params, ifo, i+1));
2286 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Q");
2287 gsl_matrix_set(params, ifo, i, gsl_matrix_get(params, ifo, i+1));
2288 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_Amp");
2289 gsl_matrix_set(params, ifo, i, gsl_matrix_get(params, ifo, i+1));
2290 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_t0");
2291 gsl_matrix_set(params, ifo, i, gsl_matrix_get(params, ifo, i+1));
2292 params = LALInferenceGetgslMatrixVariable(proposedParams, "morlet_phi");
2293 gsl_matrix_set(params, ifo, i, gsl_matrix_get(params, ifo, i+1));
2294 }
2295
2296 //Compute reverse probability of drawing parameters
2297 //find TF pixel
2298
2299 qx = evaluate_morlet_proposal(thread, currentParams, ifo, n);// + log(gsl_matrix_get(power,ifo,k));
2300
2301 //Compute forward probability of dismissing k
2302 qyx = 0.0;//-log((double)runState->data->freqData->data->length);//0.0;//-log( (REAL8)nx );
2303
2304 if(adapting)
2305 qx += 10.0;
2306
2307 break;
2308
2309 default:
2310 break;
2311 }
2312
2313 /* Update proposal structure for return to MCMC */
2314
2315 //Update model meta-date
2316 gsize->data[ifo] = ny;
2317
2318 //Re-package prior and proposal ratios into runState
2319 pForward = qxy + qx;
2320 pReverse = qyx + qy;
2321
2322 logPropRatio = pForward-pReverse;
2323
2324 return logPropRatio;
2325}
2326
2329 LALInferenceVariables *proposedParams) {
2330 REAL8 logPropRatio = 0.0;
2331
2333
2334 REAL8 psi = LALInferenceGetREAL8Variable(proposedParams, "polarisation");
2335 REAL8 phi = LALInferenceGetREAL8Variable(proposedParams, "phase");
2336
2337 phi += M_PI;
2338 psi += M_PI/2;
2339
2340 phi = fmod(phi, 2.0*M_PI);
2341 psi = fmod(psi, M_PI);
2342
2343 LALInferenceSetVariable(proposedParams, "polarisation", &psi);
2344 LALInferenceSetVariable(proposedParams, "phase", &phi);
2345
2346 return logPropRatio;
2347}
2348
2351 LALInferenceVariables *proposedParams) {
2352 REAL8 alpha,beta;
2353 REAL8 draw;
2354 REAL8 psi, phi;
2355 REAL8 logPropRatio = 0.0;
2356
2358
2359 gsl_rng *rng = thread->GSLrandom;
2360
2361 psi = LALInferenceGetREAL8Variable(proposedParams, "polarisation");
2362 phi = LALInferenceGetREAL8Variable(proposedParams, "phase");
2363
2364 alpha = psi + phi;
2365 beta = psi - phi;
2366
2367 //alpha => 0:3pi
2368 //beta => -2pi:pi
2369
2370 //big jump in either alpha (beta) or beta (alpha)
2371 draw = gsl_rng_uniform(rng);
2372 if (draw < 0.5)
2373 alpha = gsl_rng_uniform(rng)*3.0*LAL_PI;
2374 else
2375 beta = -LAL_TWOPI + gsl_rng_uniform(rng)*3.0*LAL_PI;
2376
2377 //transform back to psi,phi space
2378 psi = (alpha + beta)*0.5;
2379 phi = (alpha - beta)*0.5;
2380
2381 //map back in range
2382 LALInferenceCyclicReflectiveBound(proposedParams, thread->priorArgs);
2383
2384 LALInferenceSetVariable(proposedParams, "polarisation", &psi);
2385 LALInferenceSetVariable(proposedParams, "phase", &phi);
2386
2387 return logPropRatio;
2388}
2389
2392 LALInferenceVariables *proposedParams) {
2393 REAL8 f0, df;
2394 REAL8 plusminus;
2395 REAL8 logPropRatio = 0.0;
2396
2398
2399 f0 = LALInferenceGetREAL8Variable(proposedParams, "f0");
2400 df = LALInferenceGetREAL8Variable(proposedParams, "df");
2401
2402 plusminus = gsl_rng_uniform(thread->GSLrandom);
2403 if ( plusminus < 0.5 )
2404 f0 -= df;
2405 else
2406 f0 += df;
2407
2408 LALInferenceSetVariable(proposedParams, "f0", &f0);
2409
2410 return logPropRatio;
2411}
2412
2413//This proposal needs to be called with exactly 3 independent detector locations.
2415 const REAL8 baryTime, const REAL8 dist, const REAL8 iota, const REAL8 psi,
2416 REAL8 *newRA, REAL8 *newDec, REAL8 *newTime,
2417 REAL8 *newDist, REAL8 *newIota, REAL8 *newPsi) {
2418 REAL8 R2[4];
2419 REAL8 dist2;
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];
2425 REAL8 a, a2, b, c12;
2426 REAL8 cosnewIota, cosnewIota2;
2427 LIGOTimeGPS GPSlal;
2428 INT4 nUniqueDet, det;
2430
2431 get_detectors(thread->parent->data, &detectors);
2432 nUniqueDet = LALInferenceGetINT4Variable(thread->proposalArgs, "nUniqueDet");
2433
2434 XLALGPSSetREAL8(&GPSlal, baryTime);
2435 gmst = XLALGreenwichMeanSiderealTime(&GPSlal);
2436
2437 reflected_position_and_time(thread, ra, dec, baryTime, newRA, newDec, newTime);
2438
2439 XLALGPSSetREAL8(&GPSlal, *newTime);
2440 newGmst = XLALGreenwichMeanSiderealTime(&GPSlal);
2441
2442 dist2 = dist*dist;
2443
2444 cosIota = cos(iota);
2445 cosIota2 = cosIota*cosIota;
2446
2447 /* Loop over interferometers */
2448 INT4 i=1, j=0;
2449 for (det=0; det < nUniqueDet; det++) {
2450 psi_temp = 0.0;
2451
2452 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])detectors[det].response, *newRA, *newDec, psi_temp, newGmst);
2453 j=i-1;
2454 while (j>0){
2455 if (Fplus==x[j]){
2456 det++;
2457 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])detectors[det].response, *newRA, *newDec, psi_temp, newGmst);
2458 }
2459 j--;
2460 }
2461 x[i]=Fplus;
2462 x2[i]=Fplus*Fplus;
2463 y[i]=Fcross;
2464 y2[i]=Fcross*Fcross;
2465
2466 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])detectors[det].response, ra, dec, psi, gmst);
2467 R2[i] = (((1.0+cosIota2)*(1.0+cosIota2))/(4.0*dist2))*Fplus*Fplus
2468 + ((cosIota2)/(dist2))*Fcross*Fcross;
2469
2470 i++;
2471 }
2472
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] -
2474 R2[1]*x2[2]*y2[3]);
2475 a2 = a*a;
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]);
2479
2480 (*newPsi) = (2.*atan((b - a*sqrt((a2 + b*b)/(a2)))/a))/4.;
2481
2482 while ((*newPsi)<0){
2483 (*newPsi)=(*newPsi)+LAL_PI/4.0;
2484 }
2485
2486 while ((*newPsi)>LAL_PI/4.0){
2487 (*newPsi)=(*newPsi)-LAL_PI/4.0;
2488 }
2489
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];
2493
2494 newFcross[i] = y[i]*cos(2.0*(*newPsi)) - x[i]*sin(2.0*(*newPsi));
2495 newFcross2[i] = newFcross[i] * newFcross[i];
2496 }
2497
2498 c12 = -2.0*((R2[1]*(newFcross2[2])-R2[2]*(newFcross2[1]))
2499 /(R2[1]*(newFplus2[2])-R2[2]*(newFplus2[1])))-1.0;
2500
2501 if (c12<1.0){
2502 c12 = (3.0-c12)/(1.0+c12);
2503 (*newPsi) = (*newPsi)+LAL_PI/4.0;
2504
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];
2508
2509 newFcross[i] = y[i]*cos(2.0*(*newPsi)) - x[i]*sin(2.0*(*newPsi));
2510 newFcross2[i] = newFcross[i] * newFcross[i];
2511 }
2512 }
2513
2514 if (c12<1){
2515 *newIota = iota;
2516 *newDist = dist;
2517 return;
2518 }
2519
2520 cosnewIota2 = c12-sqrt(c12*c12-1.0);
2521 cosnewIota = sqrt(cosnewIota2);
2522 *newIota = acos(cosnewIota);
2523
2524 *newDist = sqrt((
2525 ((((1.0+cosnewIota2)*(1.0+cosnewIota2))/(4.0))*newFplus2[1]
2526 + (cosnewIota2)*newFcross2[1])
2527 )/ R2[1]);
2528
2529 if (Fplus*newFplus[3]<0){
2530 (*newPsi)=(*newPsi)+LAL_PI/2.;
2531 newFcross[3]=-newFcross[3];
2532 }
2533
2534 if (Fcross*cosIota*cosnewIota*newFcross[3]<0){
2535 (*newIota)=LAL_PI-(*newIota);
2536 }
2537
2539}
2540
2543 LALInferenceVariables *proposedParams) {
2544 REAL8 old_d=0.0;
2545 DistanceParam distParam;
2546
2547 if (LALInferenceCheckVariable(currentParams, "distance")) {
2548 distParam = USES_DISTANCE_VARIABLE;
2549 old_d = LALInferenceGetREAL8Variable(currentParams,"distance");
2550 } else if (LALInferenceCheckVariable(currentParams, "logdistance")) {
2551 distParam = USES_LOG_DISTANCE_VARIABLE;
2552 old_d = exp(LALInferenceGetREAL8Variable(currentParams,"logdistance"));
2553 } else {
2554 XLAL_ERROR_REAL8(XLAL_FAILURE, "could not find 'distance' or 'logdistance' in current params");
2555 }
2556 if(!LALInferenceCheckVariable(currentParams,"optimal_snr") || !LALInferenceCheckVariable(currentParams,"matched_filter_snr"))
2557 /* Force a likelihood calculation to generate the parameters */
2558 thread->parent->likelihood(currentParams,thread->parent->data,thread->model);
2559 if(!LALInferenceCheckVariable(currentParams,"optimal_snr") || !LALInferenceCheckVariable(currentParams,"matched_filter_snr"))
2560 {
2561 /* If still can't find the required parameters, reject this jump */
2563 return(-INFINITY);
2564 }
2565 REAL8 OptimalSNR = LALInferenceGetREAL8Variable(currentParams,"optimal_snr");
2566 REAL8 MatchedFilterSNR = LALInferenceGetREAL8Variable(currentParams,"matched_filter_snr");
2567 REAL8 d_inner_h = MatchedFilterSNR * OptimalSNR;
2568
2569 /* Get params of sampling distribution */
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;
2573
2574 /* Sample new x. Do not check for x<0 since that can throw the code
2575 * into a difficult-to-terminate loop */
2576 REAL8 new_x;
2577 new_x = xmean + gsl_ran_gaussian(thread->GSLrandom,xsigma);
2578 REAL8 new_d = 1.0/new_x;
2579
2581 /* Adjust SNRs */
2582 OptimalSNR *= new_x / old_x;
2583 LALInferenceSetREAL8Variable(proposedParams,"optimal_snr",OptimalSNR);
2584
2585 /* Update individual detector information */
2586 const char *ifonames[5]={"H1","L1","V1","I1","J1"};
2587 char pname[64]="";
2588 for(UINT4 i=0;i<5;i++)
2589 {
2590 sprintf(pname,"%s_optimal_snr",ifonames[i]);
2592 LALInferenceSetREAL8Variable(proposedParams,pname,LALInferenceGetREAL8Variable(currentParams,pname) * (new_x/old_x));
2593 }
2594
2595 REAL8 logxdjac;
2596 /* Set distance */
2597 if(distParam == USES_DISTANCE_VARIABLE)
2598 {
2599 /* The natural proposal density is in x, but we need to compute
2600 the proposal ratio density in d. So, we need a factor of
2601
2602 |dx_old/dd_old| / |dx_new/dd_new| = d_new^2 / d_old^2
2603
2604 to correct the x proposal density.
2605 */
2606 LALInferenceSetVariable(proposedParams,"distance",&new_d);
2607 logxdjac = 2.0*log(new_d) - 2.0*log(old_d);
2608 }
2609 else
2610 {
2611 /* The natural proposal density is in x, but we need to compute
2612 the proposal ratio in log(d). So, we need a factor of
2613
2614 |dx_old/dlog(d_old)| / |dx_new/dlog(d_new)| = d_new / d_old
2615
2616 to correct the x proposal density.
2617 */
2618 REAL8 new_logd = log(new_d);
2619 LALInferenceSetVariable(proposedParams,"logdistance",&new_logd);
2620 logxdjac = log(new_d) - log(old_d);
2621 }
2622 /* Proposal ratio is not symmetric */
2623 /* P.R. = p(xold|xmean,xsigma) / p(xnew|xmean,xsigma) * jacobian */
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);
2626
2627 return(log_p_reverse - log_p_forward + logxdjac);
2628}
2629
2630
2633 LALInferenceVariables *proposedParams) {
2634 INT4 nUniqueDet;
2635 INT4 timeflag=0;
2636 REAL8 baryTime;
2637 REAL8 ra, dec;
2638 REAL8 psi, dist;
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;
2644 REAL8 cst;
2645 REAL8 iota=0.0;
2646 REAL8 logPropRatio = 0.0;
2647 /* Find the number of distinct-position detectors. */
2648 /* Exit with same parameters (with a warning the first time) if
2649 there are not EXACTLY three unique detector locations. */
2650 static INT4 warningDelivered = 0;
2652
2653
2655 gsl_rng *rng = thread->GSLrandom;
2656 epoch = thread->parent->data->epoch;
2657
2658 nUniqueDet = LALInferenceGetINT4Variable(args, "nUniqueDet");
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;
2666 }
2667
2668 return logPropRatio;
2669 }
2671
2672
2673 ra = LALInferenceGetREAL8Variable(proposedParams, "rightascension");
2674 dec = LALInferenceGetREAL8Variable(proposedParams, "declination");
2675
2676 if (LALInferenceCheckVariable(proposedParams,"time")){
2677 baryTime = LALInferenceGetREAL8Variable(proposedParams, "time");
2678 timeflag = 1;
2679 } else {
2680 baryTime = XLALGPSGetREAL8(&epoch);
2681 }
2682
2683 if (LALInferenceCheckVariable(proposedParams,"costheta_jn"))
2684 iota = acos(LALInferenceGetREAL8Variable(proposedParams, "costheta_jn"));
2685 else
2686 fprintf(stderr, "LALInferenceExtrinsicParamProposal: No theta_jn parameter!\n");
2687
2688 psi = LALInferenceGetREAL8Variable(proposedParams, "polarisation");
2689
2690 dist = exp(LALInferenceGetREAL8Variable(proposedParams, "logdistance"));
2691
2692 reflected_extrinsic_parameters(thread, ra, dec, baryTime, dist, iota, psi, &newRA, &newDec, &newTime, &newDist, &newIota, &newPsi);
2693
2694 /* Unit normal deviates, used to "fuzz" the state. */
2695 const REAL8 epsDist = 1e-8;
2696 const REAL8 epsTime = 1e-8;
2697 const REAL8 epsAngle = 1e-8;
2698
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);
2705
2706 newRA += epsAngle*nRA;
2707 newDec += epsAngle*nDec;
2708 newTime += epsTime*nTime;
2709 newDist += epsDist*nDist;
2710 newIota += epsAngle*nIota;
2711 newPsi += epsAngle*nPsi;
2712
2713 /* And the doubly-reflected position (near the original, but not
2714 exactly due to the fuzzing). */
2715 reflected_extrinsic_parameters(thread, newRA, newDec, newTime, newDist, newIota, newPsi, &refRA, &refDec, &refTime, &refDist, &refIota, &refPsi);
2716
2717 /* The Gaussian increments required to shift us back to the original
2718 position from the doubly-reflected position. */
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;
2725
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);
2729
2730 LALInferenceSetVariable(proposedParams, "rightascension", &newRA);
2731 LALInferenceSetVariable(proposedParams, "declination", &newDec);
2732 if (timeflag)
2733 LALInferenceSetVariable(proposedParams, "time", &newTime);
2734
2735 REAL8 logNewDist = log(newDist);
2736 LALInferenceSetVariable(proposedParams, "logdistance", &logNewDist);
2737
2738 REAL8 newcosIota = cos(newIota);
2739 LALInferenceSetVariable(proposedParams, "costheta_jn", &newcosIota);
2740 LALInferenceSetVariable(proposedParams, "polarisation", &newPsi);
2741
2742 logPropRatio = pReverse - pForward;
2743
2744 return logPropRatio;
2745}
2746
2747
2749 INT4 i, nDet;
2750 REAL8Vector *flows, *fhighs;
2751 REAL8FrequencySeries **asds, **psds;
2752 REAL8TimeSeries **td_data;
2753 COMPLEX16FrequencySeries **fd_data;
2754 REAL8FFTPlan **plans;
2755
2756 nDet = LALInferenceGetINT4Variable(propArgs, "nDet");
2757
2758 flows = XLALCreateREAL8Vector(nDet);
2759 fhighs = XLALCreateREAL8Vector(nDet);
2760 asds = XLALCalloc(nDet, sizeof(REAL8FrequencySeries *));
2761 psds = XLALCalloc(nDet, sizeof(REAL8FrequencySeries *));
2762 td_data = XLALCalloc(nDet, sizeof(REAL8TimeSeries *));
2763 fd_data = XLALCalloc(nDet, sizeof(COMPLEX16FrequencySeries *));
2764 plans = XLALCalloc(nDet, sizeof(REAL8FFTPlan *));
2765
2766 for (i=0; i<nDet; i++) {
2767 flows->data[i] = data->fLow;
2768 fhighs->data[i] = data->fHigh;
2769
2770 asds[i] = data->noiseASD;
2771 psds[i] = data->oneSidedNoisePowerSpectrum;
2772
2773 td_data[i] = data->timeData;
2774 fd_data[i] = data->freqData;
2775
2776 plans[i] = data->freqToTimeFFTPlan;
2777 data = data->next;
2778 }
2779
2787
2788}
2789
2790
2791/** Setup adaptive proposals. Should be called when state->currentParams is already filled with an initial sample */
2793 INT4 no_adapt, adapting;
2794 INT4 adaptTau, adaptableStep, adaptLength, adaptResetBuffer;
2795 REAL8 sigma, s_gamma;
2796 REAL8 logPAtAdaptStart = -INFINITY;
2797
2799
2800 for(this=params->head; this; this=this->next) {
2802 char *name = this->name;
2803
2804 if (!strcmp(name, "eta") || !strcmp(name, "q") || !strcmp(name, "time") || !strcmp(name, "a_spin2") || !strcmp(name, "a_spin1") || !strcmp(name,"t0")){
2805 sigma = 0.001;
2806 } else if (!strcmp(name, "polarisation") || !strcmp(name, "phase") || !strcmp(name, "costheta_jn")){
2807 sigma = 0.1;
2808 } else {
2809 sigma = 0.01;
2810 }
2811
2812 /* Set up variables to store current sigma, proposed and accepted */
2813 char varname[MAX_STRLEN] = "";
2814 sprintf(varname, "%s_%s", name, ADAPTSUFFIX);
2816
2817 sigma = 0.0;
2818 sprintf(varname, "%s_%s", name, ACCEPTSUFFIX);
2820
2821 sprintf(varname, "%s_%s", name, PROPOSEDSUFFIX);
2823 }
2824 }
2825
2826 no_adapt = LALInferenceGetINT4Variable(propArgs, "no_adapt");
2827 adapting = !no_adapt; // Indicates if current iteration is being adapted
2828 LALInferenceAddINT4Variable(propArgs, "adapting", adapting, LALINFERENCE_PARAM_LINEAR);
2829
2830 char name[MAX_STRLEN] = "none";
2831 LALInferenceAddstringVariable(propArgs, "proposedVariableName", name, LALINFERENCE_PARAM_OUTPUT);
2832
2833 adaptableStep = 0;
2834 adaptTau = LALInferenceGetINT4Variable(propArgs, "adaptTau"); // Sets decay of adaption function
2835 adaptLength = pow(10, adaptTau); // Number of iterations to adapt before turning off
2836 adaptResetBuffer = 100; // Number of iterations before adapting after a restart
2837 s_gamma = 1.0; // Sets the size of changes to jump size during adaptation
2838
2839 LALInferenceAddINT4Variable(propArgs, "adaptableStep", adaptableStep, LALINFERENCE_PARAM_LINEAR);
2840 LALInferenceAddINT4Variable(propArgs, "adaptLength", adaptLength, LALINFERENCE_PARAM_LINEAR);
2841 LALInferenceAddINT4Variable(propArgs, "adaptResetBuffer", adaptResetBuffer, LALINFERENCE_PARAM_LINEAR);
2842 LALInferenceAddREAL8Variable(propArgs, "s_gamma", s_gamma, LALINFERENCE_PARAM_LINEAR);
2843 LALInferenceAddREAL8Variable(propArgs, "logPAtAdaptStart", logPAtAdaptStart, LALINFERENCE_PARAM_LINEAR);
2844
2845 return;
2846}
2847
2848
2849/** Update proposal statistics if tracking */
2851 INT4 i = 0;
2852
2853 LALInferenceProposal *prop = thread->cycle->proposals[i];
2854
2855 /* Find the proposal that was last called (by name) */
2856 while (strcmp(prop->name, thread->cycle->last_proposal_name)) {
2857 i++;
2858 prop = thread->cycle->proposals[i];
2859 }
2860
2861 /* Update proposal statistics */
2862 prop->proposed++;
2863 if (thread->accepted == 1){
2864 prop->accepted++;
2865 }
2866
2867 return;
2868}
2869
2870/* Zero out proposal statistics counters */
2872 INT4 i=0;
2873
2874 for (i=0; i<cycle->nProposals; i++) {
2875 LALInferenceProposal *prop = cycle->proposals[i];
2876
2877 prop->proposed = 0;
2878 prop->accepted = 0;
2879 }
2880
2881 return;
2882}
2883
2884/** Update the adaptive proposal. Whether or not a jump was accepted is passed with accepted */
2886 INT4 adaptableStep = 0;
2887 INT4 adapting = 0;
2888 REAL8 priorMin, priorMax, dprior, s_gamma;
2889 REAL8 accept, propose, sigma;
2890 const char *name;
2891
2893
2894 if (LALInferenceCheckVariable(args, "adaptableStep" ) &&
2895 LALInferenceCheckVariable(args, "adapting" )){
2896 adaptableStep = LALInferenceGetINT4Variable(args, "adaptableStep");
2897 adapting = LALInferenceGetINT4Variable(args, "adapting");
2898 }
2899 /* Don't do anything if these are not found */
2900 else return;
2901
2902 if (adaptableStep && adapting) {
2903 char tmpname[MAX_STRLEN] = "";
2904 name = LALInferenceGetstringVariable(args, "proposedVariableName");
2905
2906 sprintf(tmpname, "%s_%s", name, PROPOSEDSUFFIX);
2907 propose = LALInferenceGetREAL8Variable(args, tmpname) + 1;
2908 LALInferenceSetVariable(args, tmpname, &propose);
2909
2910 sprintf(tmpname, "%s_%s", name, ACCEPTSUFFIX);
2911 accept = LALInferenceGetREAL8Variable(args, tmpname) + thread->accepted;
2912 LALInferenceSetVariable(args, tmpname, &accept);
2913 }
2914
2915 /* Adapt if desired. */
2916 if (LALInferenceCheckVariable(args, "proposedVariableName") &&
2917 LALInferenceCheckVariable(args, "s_gamma") &&
2918 LALInferenceCheckVariable(args, "adapting") &&
2919 LALInferenceCheckVariable(args, "adaptableStep")) {
2920
2921 if (adaptableStep) {
2922 name = LALInferenceGetstringVariable(args, "proposedVariableName");
2923 char tmpname[MAX_STRLEN]="";
2924
2925 sprintf(tmpname, "%s_%s", name, ADAPTSUFFIX);
2926
2927 s_gamma = LALInferenceGetREAL8Variable(args, "s_gamma");
2928
2929 sigma = LALInferenceGetREAL8Variable(args, tmpname);
2930
2932 {
2933 LALInferenceGetMinMaxPrior(thread->priorArgs, name, &priorMin, &priorMax);
2934 dprior = priorMax - priorMin;
2935 }
2937 {
2938 REAL8 mu;
2939 /* Get std. dev. as dprior */
2941 }
2942 else
2943 {
2944 return;
2945 }
2946
2947 if (thread->accepted == 1){
2948 sigma += s_gamma * (dprior/100.0) * (1.0-targetAcceptance);
2949 } else {
2950 sigma -= s_gamma * (dprior/100.0) * (targetAcceptance);
2951 }
2952
2953 sigma = (sigma > dprior ? dprior : sigma);
2954 sigma = (sigma < DBL_MIN ? DBL_MIN : sigma);
2955 LALInferenceSetVariable(args, tmpname, &sigma);
2956 }
2957 }
2958
2959 /* Make sure we don't do this again until we take another adaptable step.*/
2960 adaptableStep = 0;
2961 LALInferenceSetVariable(args, "adaptableStep", &adaptableStep);
2962}
2963
2964
2965
2966
2967/**
2968 * Setup all clustered-KDE proposals with samples read from file.
2969 *
2970 * Constructed clustered-KDE proposals from all sample lists provided in
2971 * files given on the command line.
2972 * @param thread The LALInferenceThreadState to get command line options from and to the proposal cycle of.
2973 * @param input The input file pointer
2974 * @param burnin The number of burn-in points
2975 * @param weight The weight?
2976 * @param ptmcmc Flag to determine if using parallel tempering MCMC
2977 */
2980 INT4 j=0, k=0;
2981
2982 INT4 cyclic_reflective = LALInferenceGetINT4Variable(thread->proposalArgs, "cyclic_reflective_kde");
2983
2985
2986 INT4 nInSamps;
2987 INT4 nCols;
2988 REAL8 *sampleArray;
2989
2990 if (ptmcmc)
2992
2993 char params[128][VARNAME_MAX];
2994 LALInferenceReadAsciiHeader(input, params, &nCols);
2995
2996 LALInferenceVariables *backwardClusterParams = XLALCalloc(1, sizeof(LALInferenceVariables));
2997
2998 /* Only cluster parameters that are being sampled */
2999 INT4 nValidCols=0;
3000 INT4 *validCols = XLALCalloc(nCols, sizeof(INT4));
3001 for (j=0; j<nCols; j++)
3002 validCols[j] = 0;
3003
3004 INT4 logl_idx = 0;
3005 for (j=0; j<nCols; j++) {
3006 if (!strcmp("logl", params[j])) {
3007 logl_idx = j;
3008 continue;
3009 }
3010
3011 char* internal_param_name = XLALCalloc(512, sizeof(char));
3013
3014 for (item = thread->currentParams->head; item; item = item->next) {
3015 if (!strcmp(item->name, internal_param_name) &&
3017 nValidCols++;
3018 validCols[j] = 1;
3019 LALInferenceAddVariable(backwardClusterParams, item->name, item->value, item->type, item->vary);
3020 break;
3021 }
3022 }
3023 }
3024
3025 /* LALInferenceAddVariable() builds the array backwards, so reverse it. */
3026 LALInferenceVariables *clusterParams = XLALCalloc(1, sizeof(LALInferenceVariables));
3027
3028 for (item = backwardClusterParams->head; item; item = item->next)
3029 LALInferenceAddVariable(clusterParams, item->name, item->value, item->type, item->vary);
3030
3031 /* Burn in samples and parse the remainder */
3032 if (ptmcmc)
3033 LALInferenceBurninPTMCMC(input, logl_idx, nValidCols);
3034 else
3035 LALInferenceBurninStream(input, burnin);
3036
3037 sampleArray = LALInferenceParseDelimitedAscii(input, nCols, validCols, &nInSamps);
3038
3039 /* Downsample PTMCMC file to have independent samples */
3040 if (ptmcmc) {
3041 REAL8 acl_real8 = LALInferenceComputeMaxAutoCorrLen(sampleArray, nInSamps, nValidCols);
3042 INT4 acl;
3043 if (acl_real8 == INFINITY)
3044 acl = INT_MAX;
3045 else if (acl_real8 < 1.0)
3046 acl = 1;
3047 else
3048 acl = (INT4)acl_real8;
3049
3050 INT4 downsampled_size = ceil((REAL8)nInSamps/acl);
3051 REAL8 *downsampled_array = (REAL8 *)XLALCalloc(downsampled_size * nValidCols, sizeof(REAL8));
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];
3056 }
3057 XLALFree(sampleArray);
3058 sampleArray = downsampled_array;
3059 nInSamps = downsampled_size;
3060 }
3061
3062 /* Build the KDE estimate and add to the KDE proposal set */
3063 INT4 ntrials = 50; // Number of trials at fixed-k to find optimal BIC
3064 LALInferenceInitClusteredKDEProposal(thread, kde, sampleArray, nInSamps, clusterParams, clusteredKDEProposalName, weight, LALInferenceOptimizedKmeans, cyclic_reflective, ntrials);
3065
3066 /* If kmeans construction failed, halt the run */
3067 if (!kde->kmeans) {
3068 fprintf(stderr, "\nERROR: Couldn't build kmeans clustering from the file specified.\n");
3069 XLALFree(kde);
3070 abort();
3071 }
3072
3074
3075 LALInferenceClearVariables(backwardClusterParams);
3076 XLALFree(backwardClusterParams);
3077 XLALFree(sampleArray);
3078}
3079
3080
3081/**
3082 * Initialize a clustered-KDE proposal.
3083 *
3084 * Estimates the underlying distribution of a set of points with a clustered kernel density estimate
3085 * and constructs a jump proposal from the estimated distribution.
3086 * @param thread The current LALInferenceThreadState.
3087 * @param[out] kde An empty proposal structure to populate with the clustered-KDE estimate.
3088 * @param[in] array The data to estimate the underlying distribution of.
3089 * @param[in] nSamps Number of samples contained in \a array.
3090 * @param[in] params The parameters contained in \a array.
3091 * @param[in] name The name of the proposal being constructed.
3092 * @param[in] weight The relative weight this proposal is to have against other KDE proposals.
3093 * @param[in] cluster_method A pointer to the clustering function to be used.
3094 * @param[in] cyclic_reflective Flag to check for cyclic/reflective bounds.
3095 * @param[in] ntrials Number of kmeans attempts at fixed k to find optimal BIC.
3096 */
3099 REAL8 *array,
3100 INT4 nSamps,
3102 const char *name,
3103 REAL8 weight,
3104 LALInferenceKmeans* (*cluster_method)(gsl_matrix*, INT4, gsl_rng*),
3105 INT4 cyclic_reflective,
3106 INT4 ntrials) {
3107 INT4 dim;
3108 INT4 ndraws = 1000;
3109 gsl_matrix_view mview;
3110 char outp_name[256];
3111 char outp_draws_name[256];
3112
3113 strcpy(kde->name, name);
3115
3116 /* If kmeans is already assigned, assume it was calculated elsewhere */
3117 if (!kde->kmeans) {
3118 mview = gsl_matrix_view_array(array, nSamps, dim);
3119 kde->kmeans = (*cluster_method)(&mview.matrix, ntrials, thread->GSLrandom);
3120 }
3121
3122 /* Return if kmeans setup failed */
3123 if (!kde->kmeans)
3124 return;
3125
3126 kde->dimension = kde->kmeans->dim;
3127 kde->params = params;
3128
3129 kde->weight = weight;
3130 kde->next = NULL;
3131
3132 /* Selectivey impose bounds on KDEs */
3133 LALInferenceKmeansImposeBounds(kde->kmeans, params, thread->priorArgs, cyclic_reflective);
3134
3135 /* Print out clustered samples, assignments, and PDF values if requested */
3136 if (LALInferenceGetINT4Variable(thread->proposalArgs, "verbose")) {
3137 printf("Thread %i found %i clusters.\n", thread->id, kde->kmeans->k);
3138
3139 sprintf(outp_name, "clustered_samples.%2.2d", thread->id);
3140 sprintf(outp_draws_name, "clustered_draws.%2.2d", thread->id);
3141
3142 LALInferenceDumpClusteredKDE(kde, outp_name, array);
3143 LALInferenceDumpClusteredKDEDraws(kde, outp_draws_name, ndraws);
3144 }
3145}
3146
3147
3148/**
3149 * Dump draws from a KDE to file.
3150 *
3151 * Print out the samples used to estimate the distribution, along with their
3152 * cluster assignments, and the PDF evaluated at each sample.
3153 * @param[in] kde The clustered KDE to dump the info of.
3154 * @param[in] outp_name The name of the output file.
3155 * @param[in] array The array of samples used for the KDE (it only stores a whitened version).
3156 */
3158 FILE *outp;
3159 REAL8 PDF;
3160 INT4 i, j;
3161
3162 outp = fopen(outp_name, "w");
3164 fprintf(outp, "cluster\tweight\tPDF\n");
3165
3166 for (i=0; i<kde->kmeans->npts; i++) {
3167 PDF = LALInferenceKmeansPDF(kde->kmeans, array + i*kde->dimension);
3168 for (j=0; j<kde->dimension; j++)
3169 fprintf(outp, "%g\t", array[i*kde->dimension + j]);
3170 fprintf(outp, "%i\t%f\t%g\n", kde->kmeans->assignments[i], kde->kmeans->weights[kde->kmeans->assignments[i]], PDF);
3171 }
3172 fclose(outp);
3173}
3174
3175
3176/**
3177 * Dump clustered KDE information to file.
3178 *
3179 * Dump a requested number of draws from a clustered-KDE to file,
3180 * along with the value of the PDF at each point.
3181 * @param[in] kde The clustered-KDE proposal to draw from.
3182 * @param[in] outp_name The name of the file to write to.
3183 * @param[in] nSamps The number of draws to write.
3184 */
3186 FILE *outp;
3187 INT4 i, j;
3188 REAL8 *draw, PDF;
3189
3190 outp = fopen(outp_name, "w");
3192 fprintf(outp, "PDF\n");
3193
3194 for (i=0; i<nSamps; i++) {
3195 draw = LALInferenceKmeansDraw(kde->kmeans);
3196 PDF = LALInferenceKmeansPDF(kde->kmeans, draw);
3197 for (j=0; j<kde->dimension; j++)
3198 fprintf(outp, "%g\t", draw[j]);
3199 fprintf(outp, "%g\n", PDF);
3200 XLALFree(draw);
3201 }
3202 fclose(outp);
3203}
3204
3205
3206/**
3207 * Add a KDE proposal to the KDE proposal set.
3208 *
3209 * If other KDE proposals already exist, the provided KDE is appended to the list, otherwise it is added
3210 * as the first of such proposals.
3211 * @param propArgs The proposal arguments to be added to.
3212 * @param[in] kde The proposal to be added to \a thread->cycle.
3213 */
3215 /* If proposal doesn't already exist, add to proposal args */
3218
3219 /* If proposals already exist, add to the end */
3220 } else {
3222 LALInferenceClusteredKDE *old_kde = NULL;
3223
3224 /* If the first proposal has the same name, replace it */
3225 if (!strcmp(existing_kde->name, kde->name)) {
3226 old_kde = existing_kde;
3227 kde->next = existing_kde->next;
3228 LALInferenceSetVariable(propArgs, clusteredKDEProposalName, (void *)&kde);
3229 } else {
3230 while (existing_kde->next != NULL) {
3231 /* Replace proposal with the same name if found */
3232 if (!strcmp(existing_kde->next->name, kde->name)) {
3233 old_kde = existing_kde->next;
3234 kde->next = old_kde->next;
3235 existing_kde->next = kde;
3236 break;
3237 }
3238 existing_kde = existing_kde->next;
3239 }
3240
3241 /* If a proposal was not replaced, add the proposal to the end of the list */
3242 existing_kde->next=kde;
3243 }
3244
3246 }
3247
3248 return;
3249}
3250
3251
3252/**
3253 * Destroy an existing clustered-KDE proposal.
3254 *
3255 * Convenience function for freeing a clustered KDE proposal that
3256 * already exists. This is particularly useful for a proposal that
3257 * is updated during a run.
3258 * @param proposal The proposal to be destroyed.
3259 */
3261 if (proposal != NULL) {
3264 XLALFree(proposal->params);
3265 }
3266 return;
3267}
3268
3269
3270/**
3271 * Setup a clustered-KDE proposal from the differential evolution buffer.
3272 *
3273 * Reads the samples currently in the differential evolution buffer and construct a
3274 * jump proposal from its clustered kernel density estimate.
3275 * @param thread The LALInferenceThreadState to get the buffer from and add the proposal to.
3276 */
3278 INT4 i;
3279
3280 /* If ACL can be estimated, thin DE buffer to only have independent samples */
3281 REAL8 bufferSize = (REAL8) thread->differentialPointsLength;
3282 REAL8 effSampleSize = (REAL8) LALInferenceComputeEffectiveSampleSize(thread);
3283
3284 /* Correlations wont effect the proposal much, so floor is taken instead of ceil
3285 * when determining the step size */
3286 INT4 step = 1;
3287 if (effSampleSize > 0)
3288 step = (INT4) floor(bufferSize/effSampleSize);
3289
3290 if (step == 0)
3291 step = 1;
3292 INT4 nPoints = (INT4) ceil(bufferSize/(REAL8)step);
3293
3294 /* Get points to be clustered from the differential evolution buffer. */
3296 REAL8** DEsamples = (REAL8**) XLALCalloc(nPoints, sizeof(REAL8*));
3297 REAL8* temp = (REAL8*) XLALCalloc(nPoints * nPar, sizeof(REAL8));
3298 for (i=0; i < nPoints; i++)
3299 DEsamples[i] = temp + (i*nPar);
3300
3301 LALInferenceThinnedBufferToArray(thread, DEsamples, step);
3302
3303 /* Check if imposing cyclic reflective bounds */
3304 INT4 cyclic_reflective = LALInferenceGetINT4Variable(thread->proposalArgs, "cyclic_reflective_kde");
3305
3306 INT4 ntrials = 5;
3307 LALInferenceSetupClusteredKDEProposalFromRun(thread, DEsamples[0], nPoints, cyclic_reflective, ntrials);
3308
3309 /* The proposal copies the data, so the local array can be freed */
3310 XLALFree(temp);
3311 XLALFree(DEsamples);
3312}
3313
3314/**
3315 * Setup a clustered-KDE proposal from the parameters in a run.
3316 *
3317 * Reads the samples currently in the differential evolution buffer and construct a
3318 * jump proposal from its clustered kernel density estimate.
3319 * @param thread The LALInferenceThreadState to get the buffer from and add the proposal to.
3320 * @param samples The samples to estimate the distribution of. Column order expected to match
3321 * the order in \a thread->currentParams.
3322 * @param size Number of samples in \a samples.
3323 * @param cyclic_reflective Flag to check for cyclic/reflective bounds.
3324 * @param ntrials Number of tirals at fixed-k to find optimal BIC
3325 */
3327 REAL8 weight=2.;
3328
3329 /* Keep track of clustered parameter names */
3330 LALInferenceVariables *backwardClusterParams = XLALCalloc(1, sizeof(LALInferenceVariables));
3331 LALInferenceVariables *clusterParams = XLALCalloc(1, sizeof(LALInferenceVariables));
3333 for (item = thread->currentParams->head; item; item = item->next)
3335 LALInferenceAddVariable(backwardClusterParams, item->name, item->value, item->type, item->vary);
3336 for (item = backwardClusterParams->head; item; item = item->next)
3337 LALInferenceAddVariable(clusterParams, item->name, item->value, item->type, item->vary);
3338
3339 /* Build the proposal */
3341 LALInferenceInitClusteredKDEProposal(thread, proposal, samples, size, clusterParams, clusteredKDEProposalName, weight, LALInferenceOptimizedKmeans, cyclic_reflective, ntrials);
3342
3343 /* Only add the kmeans was successfully setup */
3344 if (proposal->kmeans)
3346 else {
3347 LALInferenceClearVariables(clusterParams);
3348 XLALFree(clusterParams);
3349 XLALFree(proposal);
3350 }
3351
3352 LALInferenceClearVariables(backwardClusterParams);
3353 XLALFree(backwardClusterParams);
3354}
3355
3356
3357/**
3358 * A proposal based on the clustered kernal density estimate of a set of samples.
3359 *
3360 * Proposes samples from the estimated distribution of a collection of points.
3361 * The distribution is estimated with a clustered kernel density estimator. This
3362 * proposal is added to the proposal cycle with a specified weight, and in turn
3363 * chooses at random a KDE-estimate from a linked list.
3364 * @param thread The current LALInferenceThreadState.
3365 * @param currentParams The current parameters.
3366 * @param[out] proposedParams The proposed parameters.
3367 * @return proposal_ratio The (log) proposal ratio for maintaining detailed balance
3368 */
3370 REAL8 logPropRatio;
3371
3372 logPropRatio = LALInferenceStoredClusteredKDEProposal(thread, currentParams, proposedParams, NULL);
3373
3374 return logPropRatio;
3375}
3376
3377/**
3378 * An interface to the KDE proposal that avoids a KDE evaluation if possible.
3379 *
3380 * If the value of the KDE at the current location is known, use it. Otherwise
3381 * calculate and return.
3382 * @param thread The current LALInferenceThreadState.
3383 * @param currentParams The current parameters.
3384 * @param[out] proposedParams The proposed parameters.
3385 * @param propDensity If input is not NULL or >-INFINITY, assume this is the
3386 * proposal density at \a currentParams, otherwise
3387 * calculate. It is then replaced with the proposal
3388 * density at \a proposedParams.
3389 * @return proposal_ratio The (log) proposal ratio for maintaining detailed balance
3390 */
3392 REAL8 cumulativeWeight, totalWeight;
3393 REAL8 logPropRatio = 0.0;
3394
3396 LALInferenceVariables *propArgs = thread->proposalArgs;
3397
3399 LALInferenceClearVariables(proposedParams);
3400 return logPropRatio; /* Quit now, since there is no proposal to call */
3401 }
3402
3404
3405 /* Clustered KDE estimates are stored in a linked list, with possibly different weights */
3407
3408 totalWeight = 0.;
3409 LALInferenceClusteredKDE *kde = kdes;
3410 while (kde!=NULL) {
3411 totalWeight += kde->weight;
3412 kde = kde->next;
3413 }
3414
3415 /* If multiple KDE estimates exists, draw one at random */
3416 REAL8 randomDraw = gsl_rng_uniform(thread->GSLrandom);
3417
3418 kde = kdes;
3419 cumulativeWeight = kde->weight;
3420 while(cumulativeWeight/totalWeight < randomDraw) {
3421 kde = kde->next;
3422 cumulativeWeight += kde->weight;
3423 }
3424
3425 /* Draw a sample and fill the proposedParams variable with the parameters described by the KDE */
3426 REAL8 *current = XLALCalloc(kde->dimension, sizeof(REAL8));
3427 REAL8 *proposed = LALInferenceKmeansDraw(kde->kmeans);
3428
3429 INT4 i=0;
3430 for (item = kde->params->head; item; item = item->next) {
3432 current[i] = *(REAL8 *) LALInferenceGetVariable(currentParams, item->name);
3433 LALInferenceSetVariable(proposedParams, item->name, &(proposed[i]));
3434 i++;
3435 }
3436 }
3437
3438 /* Calculate the proposal ratio */
3439 REAL8 logCurrentP;
3440 if (propDensity == NULL || *propDensity == -INFINITY)
3441 logCurrentP = LALInferenceKmeansPDF(kde->kmeans, current);
3442 else
3443 logCurrentP = *propDensity;
3444
3445 REAL8 logProposedP = LALInferenceKmeansPDF(kde->kmeans, proposed);
3446
3447 logPropRatio = logCurrentP - logProposedP;
3448
3449 if (propDensity != NULL)
3450 *propDensity = logProposedP;
3451
3452 XLALFree(current);
3453 XLALFree(proposed);
3454
3455 return logPropRatio;
3456}
3457
3458
3459/**
3460 * A wrapper for the KDE proposal that doesn't store KDE evaluations.
3461 *
3462 */
3463
3464
3465/**
3466 * Compute the maximum ACL from the differential evolution buffer.
3467 *
3468 * Given the current differential evolution buffer, the maximum
3469 * one-dimensional autocorrelation length is found.
3470 * @param thread The thread state containing the differential evolution buffer.
3471 * @param maxACL UNDOCUMENTED
3472*/
3474 INT4 nPar, nPoints, nSkip;
3475 INT4 i;
3476 REAL8** DEarray;
3477 REAL8* temp;
3478 REAL8 max_acl;
3479
3481 nPoints = thread->differentialPointsLength;
3482
3483 /* Determine the number of iterations between each entry in the DE buffer */
3484 nSkip = thread->differentialPointsSkip;
3485
3486 /* Prepare 2D array for DE points */
3487 DEarray = (REAL8**) XLALCalloc(nPoints, sizeof(REAL8*));
3488 temp = (REAL8*) XLALCalloc(nPoints * nPar, sizeof(REAL8));
3489 for (i=0; i < nPoints; i++)
3490 DEarray[i] = temp + (i*nPar);
3491
3492 LALInferenceBufferToArray(thread, DEarray);
3493 max_acl = nSkip * LALInferenceComputeMaxAutoCorrLen(DEarray[nPoints/2], nPoints-nPoints/2, nPar);
3494
3495 if (max_acl == INFINITY)
3496 max_acl = INT_MAX;
3497 else if (max_acl < 1.0)
3498 max_acl = 1.0;
3499
3500 *maxACL = (INT4)max_acl;
3501 XLALFree(temp);
3502 XLALFree(DEarray);
3503}
3504
3505/**
3506 * Compute the maximum single-parameter autocorrelation length. Each
3507 * parameter's ACL is the smallest s such that
3508 *
3509 * 1 + 2*ACF(1) + 2*ACF(2) + ... + 2*ACF(M*s) < s,
3510 *
3511 * The parameter M controls the length of the window over which we sum
3512 * the ACF to estimate the ACL; there must be at least M*ACL samples
3513 * summed. This ensures that we obtain a reliable estimate of the ACL
3514 * by incorporating lags that are much longer that the estimated ACL.
3515 *
3516 * The maximum window length is also restricted to be N/K as a safety
3517 * precaution against relying on data near the extreme of the lags in
3518 * the ACF, where there is a lot of noise.
3519 *
3520 * By default, safe parameters are M = 5, K = 2.
3521 *
3522 * If no estimate can be obtained, then return Infinity.
3523 *
3524 * @param array Array with rows containing samples.
3525 * @param nPoints UNDOCUMENTED
3526 * @param nPar UNDOCUMENTED
3527 * @return The maximum one-dimensional autocorrelation length
3528*/
3530 INT4 M=5, K=2;
3531
3532 REAL8 mean, ACL, ACF, maxACL=0;
3533 INT4 par=0, lag=0, i=0, imax;
3534 REAL8 cumACF, s;
3535
3536 if (nPoints > 1) {
3537 imax = nPoints/K;
3538
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;
3543
3544 lag=1;
3545 ACL=1.0;
3546 ACF=1.0;
3547 s=1.0/(REAL8)M;
3548 cumACF=1.0;
3549 while (cumACF >= s) {
3550 ACF = gsl_stats_correlation(array + par, nPar, array + lag*nPar + par, nPar, nPoints-lag);
3551 cumACF += 2.0 * ACF;
3552 lag++;
3553 s = (REAL8)lag/(REAL8)M;
3554 if (lag > imax) {
3555 return INFINITY; /* Short circuit: this parameter has indeterminate ACL */
3556 }
3557 }
3558 ACL = cumACF;
3559
3560 if (ACL > maxACL)
3561 maxACL = ACL;
3562 else if (gsl_isnan(ACL))
3563 return INFINITY; /* Short circuit: this parameter has indeterminate ACL */
3564
3565 for (i=0; i<nPoints; i++)
3566 array[i*nPar + par] += mean;
3567 }
3568 } else {
3569 maxACL = INFINITY;
3570 }
3571
3572 return maxACL;
3573}
3574
3575/**
3576 * Update the estimatate of the autocorrelation length.
3577 *
3578 * @param thread The current LALInferenceThreadState.
3579*/
3581 // Calculate ACL with latter half of data to avoid ACL overestimation from chain equilibrating after adaptation
3582 INT4 acl;
3583
3585
3586 LALInferenceSetVariable(thread->proposalArgs, "acl", &acl);
3587}
3588
3589/**
3590 * Determine the effective sample size based on the DE buffer.
3591 *
3592 * Compute the number of independent samples in the differential evolution
3593 * buffer.
3594 * @param thread The current LALInferenceThreadState.
3595 */
3597 /* Update the ACL estimate, assuming a thinned DE buffer if ACL isn't available */
3598 INT4 acl = 1;
3599 if (LALInferenceCheckVariable(thread->proposalArgs, "acl")) {
3601 acl = LALInferenceGetINT4Variable(thread->proposalArgs, "acl");
3602 }
3603
3604 /* Estimate the total number of samples post-burnin based on samples in DE buffer */
3605 INT4 nPoints = thread->differentialPointsLength * thread->differentialPointsSkip;
3606 INT4 iEff = nPoints/acl;
3607 return iEff;
3608}
3609
3610
3612 fprintf(fp, "proposal\t");
3615 fprintf(fp, "prop_ratio\taccepted\t");
3616 fprintf(fp, "\n");
3617 return 0;
3618}
3619
3621 fprintf(fp, "%s\t", cycle->proposals[cycle->counter]->name);
3623 LALInferencePrintSampleNonFixed(fp, theta_prime);
3624 fprintf(fp, "%9.5f\t", exp(logPropRatio));
3625 fprintf(fp, "%d\t", accepted);
3626 fprintf(fp, "\n");
3627 return;
3628}
3629
3631 INT4 nifo = LALInferenceGetINT4Variable(thread->proposalArgs, "nDet");
3632 LALInferenceIFOData *det=NULL;
3634
3635 for(det=thread->parent->data;det;det=det->next)
3636 {
3637 UINT4 i;
3638
3639 char ampName[VARNAME_MAX];
3640 char phaseName[VARNAME_MAX];
3641 REAL8 dummy;
3642
3643 REAL8 ampWidth;
3644 REAL8 phaseWidth;
3645 UINT4 nspl = LALInferenceGetUINT4Variable(proposedParams, "spcal_npts");
3646 for (i = 0; i < nspl; i++) {
3647 if((VARNAME_MAX <= snprintf(ampName, VARNAME_MAX, "%s_spcal_amp_%i", det->name, i)))
3648 {
3649 fprintf(stderr,"variable name too long\n"); abort();
3650 }
3651 if((VARNAME_MAX <= snprintf(phaseName, VARNAME_MAX, "%s_spcal_phase_%i", det->name, i)))
3652 {
3653 fprintf(stderr,"variable name too long\n"); abort();
3654 }
3655
3656 LALInferenceGetGaussianPrior(thread->priorArgs, ampName, &dummy, &ampWidth);
3657 REAL8 amp = LALInferenceGetREAL8Variable(proposedParams, ampName);
3658 amp += ampWidth*gsl_ran_ugaussian(thread->GSLrandom)/sqrt(nifo*(REAL8)nspl);
3659 LALInferenceSetREAL8Variable(proposedParams, ampName, amp);
3660
3661 LALInferenceGetGaussianPrior(thread->priorArgs, phaseName, &dummy, &phaseWidth);
3662 REAL8 ph = LALInferenceGetREAL8Variable(proposedParams, phaseName);
3663 ph += phaseWidth*gsl_ran_ugaussian(thread->GSLrandom)/sqrt(nifo*(REAL8)nspl);
3664 LALInferenceSetREAL8Variable(proposedParams, phaseName, ph);
3665 }
3666 };
3667
3668 return 0.0;
3669}
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
@ USES_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)
#define max(a, b)
LALInferenceVariables currentParams
ProcessParamsTable * ppt
int j
ProcessParamsTable * ptr
int k
static double double delta
#define fprintf
const char *const name
const char * names[]
int s
int l
double e
double theta
const double sx
const double Q
const double pn
const double sy
const double u
const double ny
const double a2
const double w
sigmaKerr data[0]
const double nx
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
#define LAL_2_SQRTPI
#define LAL_C_SI
#define LAL_E
#define LAL_PI
#define LAL_TWOPI
#define LAL_SQRT1_2
double REAL8
int64_t INT8
uint32_t UINT4
int32_t INT4
float REAL4
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.
Definition: LALInference.c:948
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.
Definition: LALInference.c:321
void LALInferenceDiscardPTMCMCHeader(FILE *filestream)
Discard the standard header of a PTMCMC chain file.
#define VARNAME_MAX
Definition: LALInference.h:50
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.
Definition: LALInference.c:255
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.
Definition: LALInference.c:395
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.
Definition: LALInference.c:207
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
Definition: LALInference.c:558
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...
Definition: LALInference.c:238
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.
Definition: LALInference.c:250
REAL8(* LALInferenceProposalFunction)(struct tagLALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Jump proposal distribution Computes proposedParams based on currentParams and additional variables st...
Definition: LALInference.h:391
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.
Definition: LALInference.c:532
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.
Definition: LALInference.c:525
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.
Definition: LALInference.c:352
int LALInferenceCheckVariableNonFixed(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars and having type LINEAR or CIRCULAR.
Definition: LALInference.c:503
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
Definition: LALInference.h:131
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
Definition: LALInference.h:130
@ LALINFERENCE_PARAM_LINEAR
Definition: LALInference.h:128
@ LALINFERENCE_REAL8_t
Definition: LALInference.h:109
@ LALINFERENCE_void_ptr_t
Definition: LALInference.h:119
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.
#define ADAPTSUFFIX
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)
#define PROPOSEDSUFFIX
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
#define MAX_STRLEN
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.
#define ACCEPTSUFFIX
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)
void XLALFree(void *p)
static const INT4 r
static const INT4 a
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)
XLAL_ENOMEM
XLAL_FAILURE
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
M
list y
list mu
args
type
DEC
RA
LALDetector detectors[LAL_NUM_DETECTORS]
double alpha
double t0
REAL8 location[3]
Struct to hold clustered-KDE estimates.
LALInferenceKmeans * kmeans
struct tagLALInferenceClusteredKDEProposal * next
LALInferenceVariables * params
Structure to contain IFO data.
Definition: LALInference.h:625
LALDetector * detector
integration limits for overlap integral in F-domain
Definition: LALInference.h:651
char name[DETNAMELEN]
Definition: LALInference.h:626
struct tagLALInferenceIFOData * next
ROQ data.
Definition: LALInference.h:659
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.
Definition: LALInference.h:436
LALInferenceVariables * params
Definition: LALInference.h:437
Structure for holding a proposal cycle.
Definition: LALInference.h:526
LALInferenceProposal ** proposals
Definition: LALInference.h:527
char last_proposal_name[VARNAME_MAX]
Counter for cycling through proposals.
Definition: LALInference.h:532
INT4 * order
Array of proposals (one per proposal function)
Definition: LALInference.h:528
INT4 nProposals
Length of cycle.
Definition: LALInference.h:530
Structure for holding a LALInference proposal, along with name and stats.
Definition: LALInference.h:512
char name[VARNAME_MAX]
Definition: LALInference.h:514
LALInferenceProposalFunction func
Definition: LALInference.h:513
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
ProcessParamsTable * commandLine
Definition: LALInference.h:593
LALInferenceVariables * proposalArgs
The data from the interferometers.
Definition: LALInference.h:602
LALInferenceVariables * algorithmParams
Any special arguments for the prior function.
Definition: LALInference.h:604
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferenceAlgorithm algorithm
A function that returns a new set of variables for the model.
Definition: LALInference.h:595
Structure containing chain-specific variables.
Definition: LALInference.h:541
LALInferenceVariables * currentParams
Prior boundaries, etc.
Definition: LALInference.h:556
struct tagLALInferenceRunState * parent
Definition: LALInference.h:578
LALInferenceVariables * priorArgs
Stope things such as output arrays.
Definition: LALInference.h:553
LALInferenceModel * model
Cycle of proposals to call.
Definition: LALInference.h:548
INT4 accepted
This should be removed, can be given as an algorithmParams entry.
Definition: LALInference.h:574
size_t differentialPointsLength
Array of points for differential evolution.
Definition: LALInference.h:560
LALInferenceProposalCycle * cycle
The proposal cycle.
Definition: LALInference.h:547
LALInferenceVariables * proposalArgs
Definition: LALInference.h:551
REAL8 temperature
Array containing multiple proposal densities.
Definition: LALInference.h:550
size_t differentialPointsSkip
Size of the differentialPoints memory block (must be >= length of differential points).
Definition: LALInference.h:566
LALInferenceVariables ** differentialPoints
Parameters proposed.
Definition: LALInference.h:559
The LALInferenceVariableItem list node structure This should only be accessed using the accessor func...
Definition: LALInference.h:154
char name[VARNAME_MAX]
Definition: LALInference.h:155
LALInferenceVariableType type
Definition: LALInference.h:157
struct tagVariableItem * next
Definition: LALInference.h:159
LALInferenceParamVaryType vary
Definition: LALInference.h:158
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
Definition: LALInference.h:170
LALInferenceVariableItem * head
Definition: LALInference.h:171
CHAR value[LIGOMETA_VALUE_MAX]
struct tagProcessParamsTable * next
REAL8Sequence * data
REAL8 * data
REAL8 longitude
REAL8 latitude
CoordinateSystem system
UINT4 * data
FILE * fp
enum @1 epoch
double df