SPINspiral
SPINspiral is a parameter-estimation code for gravitational-wave signals detected by LIGO/Virgo
|
Contains MCMC routines. More...
#include <SPINspiral.h>
Functions | |
void | MCMC (struct runPar run, struct interferometer *ifo[]) |
MCMC routine - forms the MCMC core of the program. | |
void | par2arr (struct parSet par, double **param, struct MCMCvariables mcmc) |
Put the MCMC parameters in an array. | |
void | arr2par (double **param, struct parSet *par, struct MCMCvariables mcmc) |
Get the MCMC parameters out of their array. | |
double | prior (double *par, int p, struct MCMCvariables mcmc) |
Compute the prior for the given parameter set. | |
double | sigmaPeriodicBoundaries (double sigma, int p, struct MCMCvariables mcmc) |
Bring the adaptation sigma between its periodic boundaries. | |
void | correlatedMCMCupdate (struct interferometer *ifo[], struct parSet *state, struct MCMCvariables *mcmc, struct runPar run) |
Do a correlated block MCMC update. | |
void | uncorrelatedMCMCsingleUpdate (struct interferometer *ifo[], struct parSet *state, struct MCMCvariables *mcmc, struct runPar run) |
Do an uncorrelated, per-parameter MCMC update. | |
void | uncorrelatedMCMCblockUpdate (struct interferometer *ifo[], struct parSet *state, struct MCMCvariables *mcmc, struct runPar run) |
Do an uncorrelated block update. | |
void | writeMCMCheader (struct interferometer *ifo[], struct MCMCvariables mcmc, struct runPar run) |
Write MCMC header to screen and file. | |
void | writeMCMCoutput (struct MCMCvariables mcmc, struct interferometer *ifo[]) |
Write an MCMC iteration as an output line to screen and/or file. | |
void | allocateMCMCvariables (struct MCMCvariables *mcmc) |
Allocate memory for the MCMCvariables struct. | |
void | freeMCMCvariables (struct MCMCvariables *mcmc) |
Deallocate memory for the MCMCvariables struct. | |
void | updateCovarianceMatrix (struct MCMCvariables *mcmc) |
Calculate the new covariance matrix and determine whether the new matrix should be accepted. | |
void | CholeskyDecompose (double **A, struct MCMCvariables *mcmc) |
Compute Cholesky decomposition matrix. | |
double | annealTemperature (double temp0, int nburn, int nburn0, int iIter) |
Annealing: set the temperature according to the iteration number and burnin. | |
void | swapChains (struct MCMCvariables *mcmc) |
Parallel tempering: Swap states between two chains. | |
void | writeChainInfo (struct MCMCvariables mcmc) |
Parallel tempering: Print chain and swap info to screen. | |
void | startMCMCOffset (struct parSet *par, struct MCMCvariables *mcmc, struct interferometer *ifo[], struct runPar run) |
Choose and print offset starting values for the Markov chain. | |
void | setTemperatureLadder (struct MCMCvariables *mcmc) |
Set up the temperature ladder for parallel tempering. | |
void | setTemperatureLadderOld (struct MCMCvariables *mcmc) |
Set up the temperature ladder for parallel tempering - old routine. |
Contains MCMC routines.
void MCMC | ( | struct runPar | run, |
struct interferometer * | ifo[] | ||
) |
MCMC routine - forms the MCMC core of the program.
Initialise and build a Markov chain
References MCMCvariables::acceptPrior, MCMCvariables::acceptRateTarget, MCMCvariables::adaptiveMCMC, MCMCvariables::adaptScale, MCMCvariables::adaptSigma, allocateMCMCvariables(), allocParset(), MCMCvariables::annealNburn, MCMCvariables::annealNburn0, MCMCvariables::annealTemp0, annealTemperature(), arr2par(), MCMCvariables::baseTime, MCMCvariables::beVerbose, MCMCvariables::blockFrac, MCMCvariables::chTemp, copyRun2MCMC(), correlatedMCMCupdate(), MCMCvariables::correlatedUpdates, MCMCvariables::corrFrac, MCMCvariables::corrUpdate, MCMCvariables::covar, MCMCvariables::decreaseSigma, MCMCvariables::dlogL, MCMCvariables::fouts, freeMCMCvariables(), freeParset(), getInjectionParameters(), getStartParameters(), MCMCvariables::hist, MCMCvariables::iHist, MCMCvariables::iIter, MCMCvariables::increaseSigma, MCMCvariables::injectionWaveform, MCMCvariables::injectSignal, MCMCvariables::injID, MCMCvariables::injParUse, MCMCvariables::injParVal, MCMCvariables::injRevID, MCMCvariables::iTemp, localPar(), MCMCvariables::logL, max, MCMCvariables::maxdlogL, MCMCvariables::maxLparam, MCMCvariables::mcmcWaveform, MCMCvariables::minlogL, MCMCvariables::nCorr, netLogLikelihood(), MCMCvariables::networkSize, MCMCvariables::nInjectPar, MCMCvariables::nIter, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, MCMCvariables::nParFit, MCMCvariables::nTemps, runPar::outputPath, par2arr(), MCMCvariables::parallelTempering, MCMCvariables::param, MCMCvariables::parBestVal, MCMCvariables::parFix, MCMCvariables::parID, MCMCvariables::parSigma, MCMCvariables::prParTempInfo, MCMCvariables::ran, MCMCvariables::saveHotChains, MCMCvariables::seed, setTemperatureLadderOld(), sigmaPeriodicBoundaries(), startMCMCOffset(), swapChains(), MCMCvariables::tempAmpl, MCMCvariables::tempLadder, MCMCvariables::tempOverlap, tpi, uncorrelatedMCMCblockUpdate(), uncorrelatedMCMCsingleUpdate(), updateCovarianceMatrix(), writeChainInfo(), writeMCMCheader(), and writeMCMCoutput().
Referenced by main().
void par2arr | ( | struct parSet | par, |
double ** | param, | ||
struct MCMCvariables | mcmc | ||
) |
Put the MCMC parameters in an array.
References MCMCvariables::iTemp, MCMCvariables::nMCMCpar, and parSet::par.
Referenced by correlatedMCMCupdate(), MCMC(), uncorrelatedMCMCblockUpdate(), and uncorrelatedMCMCsingleUpdate().
void arr2par | ( | double ** | param, |
struct parSet * | par, | ||
struct MCMCvariables | mcmc | ||
) |
Get the MCMC parameters out of their array.
References MCMCvariables::iTemp, MCMCvariables::nMCMCpar, and parSet::par.
Referenced by correlatedMCMCupdate(), MCMC(), startMCMCOffset(), uncorrelatedMCMCblockUpdate(), and uncorrelatedMCMCsingleUpdate().
double prior | ( | double * | par, |
int | p, | ||
struct MCMCvariables | mcmc | ||
) |
Compute the prior for the given parameter set.
Contains boundary conditions and prior information for the MCMC. Try to avoid returning 0, to increase jump sizes
References mtpi, pi, MCMCvariables::priorBoundLow, MCMCvariables::priorBoundUp, MCMCvariables::priorType, and tpi.
Referenced by correlatedMCMCupdate(), startMCMCOffset(), uncorrelatedMCMCblockUpdate(), and uncorrelatedMCMCsingleUpdate().
double sigmaPeriodicBoundaries | ( | double | sigma, |
int | p, | ||
struct MCMCvariables | mcmc | ||
) |
Bring the adaptation sigma between its periodic boundaries.
References min, pi, MCMCvariables::priorType, and tpi.
Referenced by MCMC(), and uncorrelatedMCMCsingleUpdate().
void correlatedMCMCupdate | ( | struct interferometer * | ifo[], |
struct parSet * | state, | ||
struct MCMCvariables * | mcmc, | ||
struct runPar | run | ||
) |
Do a correlated block MCMC update.
Do an update for all non-fixed MCMC parameters. Use the covariance matrix to take into account correlations. The covariance matrix has been constructed from previous iterations. Use adaptation to scale the whole matrix. Some experiments with larger jumps using the 'hotter' covariance matrix.
References MCMCvariables::accepted, MCMCvariables::acceptPrior, MCMCvariables::adaptiveMCMC, MCMCvariables::adaptSigmaOut, arr2par(), MCMCvariables::chTemp, MCMCvariables::corrSig, MCMCvariables::covar, MCMCvariables::decreaseSigma, MCMCvariables::increaseSigma, MCMCvariables::iTemp, localPar(), MCMCvariables::logL, max, MCMCvariables::mcmcWaveform, min, MCMCvariables::minlogL, netLogLikelihood(), MCMCvariables::networkSize, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, par2arr(), MCMCvariables::param, MCMCvariables::parFix, prior(), and MCMCvariables::ran.
Referenced by MCMC().
void uncorrelatedMCMCsingleUpdate | ( | struct interferometer * | ifo[], |
struct parSet * | state, | ||
struct MCMCvariables * | mcmc, | ||
struct runPar | run | ||
) |
Do an uncorrelated, per-parameter MCMC update.
Do an update for all non-fixed MCMC parameters in the current T chain. Propose a jump and decide whether to accept or not on a per-parameter basis. Use adaptation.
References MCMCvariables::accepted, MCMCvariables::acceptPrior, MCMCvariables::acceptRateTarget, MCMCvariables::adaptiveMCMC, MCMCvariables::adaptScale, MCMCvariables::adaptSigma, MCMCvariables::adaptSigmaOut, arr2par(), MCMCvariables::chTemp, MCMCvariables::iIter, MCMCvariables::iTemp, localPar(), MCMCvariables::logL, max, MCMCvariables::mcmcWaveform, min, MCMCvariables::minlogL, netLogLikelihood(), MCMCvariables::networkSize, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, par2arr(), MCMCvariables::param, MCMCvariables::parFix, prior(), MCMCvariables::ran, and sigmaPeriodicBoundaries().
Referenced by MCMC().
void uncorrelatedMCMCblockUpdate | ( | struct interferometer * | ifo[], |
struct parSet * | state, | ||
struct MCMCvariables * | mcmc, | ||
struct runPar | run | ||
) |
Do an uncorrelated block update.
Do an update for all non-fixed MCMC parameters in the current T chain. Propose a jump and decide whether to accept or not for all parameters at once. No adaptation here, some experimenting with larger jumps every now and then.
References MCMCvariables::accepted, MCMCvariables::acceptPrior, MCMCvariables::adaptSigma, arr2par(), MCMCvariables::chTemp, MCMCvariables::iTemp, localPar(), MCMCvariables::logL, max, MCMCvariables::mcmcWaveform, min, MCMCvariables::minlogL, netLogLikelihood(), MCMCvariables::networkSize, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, par2arr(), MCMCvariables::param, MCMCvariables::parFix, prior(), and MCMCvariables::ran.
Referenced by MCMC().
void writeMCMCheader | ( | struct interferometer * | ifo[], |
struct MCMCvariables | mcmc, | ||
struct runPar | run | ||
) |
Write MCMC header to screen and file.
References interferometer::after_tc, MCMCvariables::annealNburn, interferometer::before_tc, interferometer::deltaFT, MCMCvariables::fouts, interferometer::FTsize, interferometer::FTstart, interferometer::highCut, interferometer::lowCut, MCMCvariables::maxTemp, runPar::mcmcPNorder, runPar::mcmcWaveform, interferometer::name, MCMCvariables::nCorr, runPar::netsnr, runPar::networkSize, MCMCvariables::nIter, runPar::nMCMCpar, MCMCvariables::nMCMCpar, MCMCvariables::nTemps, MCMCvariables::offsetMCMC, MCMCvariables::parAbrev, MCMCvariables::parID, interferometer::samplerate, interferometer::samplesize, MCMCvariables::saveHotChains, MCMCvariables::seed, interferometer::snr, and MCMCvariables::tempLadder.
Referenced by MCMC().
void writeMCMCoutput | ( | struct MCMCvariables | mcmc, |
struct interferometer * | ifo[] | ||
) |
Write an MCMC iteration as an output line to screen and/or file.
References MCMCvariables::accepted, MCMCvariables::fouts, MCMCvariables::iIter, interferometer::index, MCMCvariables::iTemp, MCMCvariables::logL, MCMCvariables::nMCMCpar, MCMCvariables::parAbrev, MCMCvariables::param, MCMCvariables::parID, MCMCvariables::saveHotChains, MCMCvariables::thinOutput, and MCMCvariables::thinScreenOutput.
Referenced by MCMC().
void allocateMCMCvariables | ( | struct MCMCvariables * | mcmc | ) |
Allocate memory for the MCMCvariables struct.
Allocate memory for the MCMCvariables struct. Don't forget to deallocate whatever you put here in freeMCMCvariables()
References MCMCvariables::accepted, MCMCvariables::acceptElems, MCMCvariables::acceptPrior, MCMCvariables::adaptScale, MCMCvariables::adaptSigma, MCMCvariables::adaptSigmaOut, MCMCvariables::corrSig, MCMCvariables::corrUpdate, MCMCvariables::covar, MCMCvariables::dlogL, MCMCvariables::hist, MCMCvariables::histDev, MCMCvariables::histMean, MCMCvariables::iHist, MCMCvariables::logL, max, MCMCvariables::maxdlogL, MCMCvariables::maxLparam, MCMCvariables::nCorr, MCMCvariables::nInjectPar, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, MCMCvariables::nParFit, MCMCvariables::nTemps, MCMCvariables::param, MCMCvariables::swapTs1, MCMCvariables::swapTs2, MCMCvariables::swapTss, and MCMCvariables::tempAmpl.
Referenced by MCMC().
void freeMCMCvariables | ( | struct MCMCvariables * | mcmc | ) |
Deallocate memory for the MCMCvariables struct.
References MCMCvariables::accepted, MCMCvariables::acceptElems, MCMCvariables::acceptPrior, MCMCvariables::adaptScale, MCMCvariables::adaptSigma, MCMCvariables::adaptSigmaOut, MCMCvariables::corrSig, MCMCvariables::corrUpdate, MCMCvariables::covar, MCMCvariables::dlogL, MCMCvariables::hist, MCMCvariables::histDev, MCMCvariables::histMean, MCMCvariables::iHist, MCMCvariables::logL, MCMCvariables::maxdlogL, MCMCvariables::maxLparam, MCMCvariables::nlogL, MCMCvariables::nMCMCpar, MCMCvariables::nParam, MCMCvariables::nTemps, MCMCvariables::param, MCMCvariables::ran, MCMCvariables::swapTs1, MCMCvariables::swapTs2, MCMCvariables::swapTss, and MCMCvariables::tempAmpl.
Referenced by MCMC().
void updateCovarianceMatrix | ( | struct MCMCvariables * | mcmc | ) |
Calculate the new covariance matrix and determine whether the new matrix should be accepted.
Compute the new covariance matrix for the current T chain. Determine by the 'improvement' of the new matrix whether it should be accepted.
References MCMCvariables::acceptElems, CholeskyDecompose(), MCMCvariables::corrUpdate, MCMCvariables::covar, MCMCvariables::hist, MCMCvariables::histDev, MCMCvariables::histMean, MCMCvariables::iIter, MCMCvariables::iTemp, MCMCvariables::matAccFr, max, MCMCvariables::nCorr, MCMCvariables::nMCMCpar, MCMCvariables::nParFit, MCMCvariables::nTemps, MCMCvariables::parFix, and MCMCvariables::prMatrixInfo.
Referenced by MCMC().
void CholeskyDecompose | ( | double ** | A, |
struct MCMCvariables * | mcmc | ||
) |
Compute Cholesky decomposition matrix.
Performs Cholesky decompositon of matrix A and returns result in the same matrix - adapted from PJG Fortran function If matrix is not positive definite, return zeroes
References MCMCvariables::nMCMCpar, and MCMCvariables::parFix.
Referenced by updateCovarianceMatrix().
double annealTemperature | ( | double | temp0, |
int | nburn, | ||
int | nburn0, | ||
int | iIter | ||
) |
void swapChains | ( | struct MCMCvariables * | mcmc | ) |
Parallel tempering: Swap states between two chains.
References MCMCvariables::logL, max, min, MCMCvariables::nMCMCpar, MCMCvariables::nTemps, MCMCvariables::param, MCMCvariables::ran, MCMCvariables::swapTs1, MCMCvariables::swapTs2, MCMCvariables::swapTss, and MCMCvariables::tempLadder.
Referenced by MCMC().
void writeChainInfo | ( | struct MCMCvariables | mcmc | ) |
Parallel tempering: Print chain and swap info to screen.
References MCMCvariables::accepted, MCMCvariables::acceptElems, MCMCvariables::chTemp, MCMCvariables::corrUpdate, MCMCvariables::histDev, MCMCvariables::iIter, MCMCvariables::iTemp, MCMCvariables::nMCMCpar, MCMCvariables::nTemps, MCMCvariables::parAbrv, MCMCvariables::parID, MCMCvariables::prParTempInfo, MCMCvariables::swapTs1, MCMCvariables::swapTs2, and MCMCvariables::swapTss.
Referenced by MCMC().
void startMCMCOffset | ( | struct parSet * | par, |
struct MCMCvariables * | mcmc, | ||
struct interferometer * | ifo[], | ||
struct runPar | run | ||
) |
Choose and print offset starting values for the Markov chain.
Set MCMC parameters to either the best-guess values or the injection values (where possible). Then, depending on the detailed per-parameter settings, add a random offset from this value. Require a good value for logL (determined by mcmc->minlogL) in order to accept the proposed starting values, unless MCMC parameters do not fully match the injection parameters. This happens independently of whether parameters are fixed or not! Finally, print the selected starting values to screen.
References MCMCvariables::acceptPrior, arr2par(), MCMCvariables::beVerbose, MCMCvariables::injectionWaveform, MCMCvariables::injectSignal, MCMCvariables::injID, MCMCvariables::injParUse, MCMCvariables::injParVal, MCMCvariables::injRevID, MCMCvariables::iTemp, localPar(), MCMCvariables::logL, max, MCMCvariables::mcmcWaveform, netLogLikelihood(), MCMCvariables::networkSize, MCMCvariables::nMCMCpar, MCMCvariables::nParam, MCMCvariables::offsetMCMC, MCMCvariables::offsetX, MCMCvariables::parAbrev, MCMCvariables::param, MCMCvariables::parBestVal, MCMCvariables::parID, MCMCvariables::parSigma, MCMCvariables::parStartMCMC, prior(), MCMCvariables::priorBoundLow, MCMCvariables::priorBoundUp, MCMCvariables::ran, and MCMCvariables::thinScreenOutput.
Referenced by MCMC().
void setTemperatureLadder | ( | struct MCMCvariables * | mcmc | ) |
Set up the temperature ladder for parallel tempering.
References MCMCvariables::beVerbose, MCMCvariables::maxTemp, MCMCvariables::nTemps, MCMCvariables::parallelTempering, MCMCvariables::prParTempInfo, MCMCvariables::tempAmpl, MCMCvariables::tempLadder, and MCMCvariables::tempOverlap.
void setTemperatureLadderOld | ( | struct MCMCvariables * | mcmc | ) |
Set up the temperature ladder for parallel tempering - old routine.
References MCMCvariables::beVerbose, MCMCvariables::maxTemp, min, MCMCvariables::nTemps, MCMCvariables::parallelTempering, MCMCvariables::prParTempInfo, MCMCvariables::tempAmpl, and MCMCvariables::tempLadder.
Referenced by MCMC().