Canoe
Comprehensive Atmosphere N' Ocean Engine
mcmc.cpp File Reference
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <configure.hpp>
#include <climath/core.h>
#include <utils/ndarrays.hpp>
#include "mcmc.hpp"

Go to the source code of this file.

Macros

#define TAUMAX   2
 
#define WINMULT   5
 
#define MAXLAG   TAUMAX *WINMULT
 
#define MINFAC   5
 

Functions

void _choldc (double **a, int n, double *p)
 
int _acor (double *mean, double *sigma, double *tau, double *X, int L)
 
void mcmc_alloc (mcmc_recs *recs, int nstep, int nwalker, int ndim, int nvalue)
 
void mcmc_free (mcmc_recs *recs)
 
void mcmc_statistics (double *mean, double *sigma, double *tau, mcmc_recs *recs)
 
void mcmc_save_fits (char const *fname, mcmc_opts *opts, mcmc_recs *recs, int include_last)
 
void mcmc_load_fits (char const *fname, mcmc_opts *opts, mcmc_recs *recs, int alloc)
 
void mcmc_append_recs (mcmc_recs *dst, mcmc_recs *src)
 
void mcmc_report (mcmc_opts *opts, mcmc_recs *recs, char const *mode)
 
void mcmc_init (ObjectiveFunction_t lnprob, double **par, mcmc_opts *opts, mcmc_recs *recs, void *obj)
 
void mcmc_advance (ObjectiveFunction_t lnprob, mcmc_opts *opts, mcmc_recs *recs, void *obj)
 
double mcmc_stretch_move (double *newp, double **oldp, int iwalker, int nwalker, int ndim, mcmc_opts *opts)
 
void mcmc_walk_move (double *newp, double **oldp, int k, int nwalker, int np, mcmc_opts *opts)
 

Macro Definition Documentation

◆ TAUMAX

#define TAUMAX   2

Definition at line 47 of file mcmc.cpp.

◆ WINMULT

#define WINMULT   5

Definition at line 50 of file mcmc.cpp.

◆ MAXLAG

#define MAXLAG   TAUMAX *WINMULT

Definition at line 54 of file mcmc.cpp.

◆ MINFAC

#define MINFAC   5

Definition at line 58 of file mcmc.cpp.

Function Documentation

◆ _choldc()

void _choldc ( double **  a,
int  n,
double *  p 
)

Given a positive definite symmetric matrix a[0..n-1][0..n-1], this subroutine constructs its Cholesky decomposition: A = L*L'. On input, only the upper triangle of A need be given; it is not modified. The Cholesky factor L is returned in the lower triangle of A, except for its diagonal elements which are returned in p[0..n-1]. see Numerical Recipes in C, pg 97

Definition at line 27 of file mcmc.cpp.

◆ _acor()

int _acor ( double *  mean,
double *  sigma,
double *  tau,
double *  X,
int  L 
)

calculate auto-correlation time given a time series Written by Jonathan Goodman, March 2009, goodm.nosp@m.an@c.nosp@m.ims.n.nosp@m.yu.e.nosp@m.du Modified by Cheng Li, June 2016, cli@g.nosp@m.ps.c.nosp@m.altec.nosp@m.h.ed.nosp@m.u

Definition at line 60 of file mcmc.cpp.

◆ mcmc_alloc()

void mcmc_alloc ( mcmc_recs recs,
int  nstep,
int  nwalker,
int  ndim,
int  nvalue 
)

allocate memory for mcmc chains

Definition at line 126 of file mcmc.cpp.

◆ mcmc_free()

void mcmc_free ( mcmc_recs recs)

free memory

Definition at line 151 of file mcmc.cpp.

◆ mcmc_statistics()

void mcmc_statistics ( double *  mean,
double *  sigma,
double *  tau,
mcmc_recs recs 
)

calculate autocorrelation time

Definition at line 160 of file mcmc.cpp.

◆ mcmc_save_fits()

void mcmc_save_fits ( char const *  fname,
mcmc_opts opts,
mcmc_recs recs,
int  include_last = false 
)

save mcmc chains to a FITS file

Definition at line 179 of file mcmc.cpp.

◆ mcmc_load_fits()

void mcmc_load_fits ( char const *  fname,
mcmc_opts opts,
mcmc_recs recs,
int  alloc = true 
)

load mcmc chains from a FITS file

Definition at line 379 of file mcmc.cpp.

◆ mcmc_append_recs()

void mcmc_append_recs ( mcmc_recs dst,
mcmc_recs src 
)

copy mcmc chains

Definition at line 459 of file mcmc.cpp.

◆ mcmc_report()

void mcmc_report ( mcmc_opts opts,
mcmc_recs recs,
char const *  mode 
)

Definition at line 486 of file mcmc.cpp.

◆ mcmc_init()

void mcmc_init ( ObjectiveFunction_t  lnprob,
double **  par,
mcmc_opts opts,
mcmc_recs recs,
void *  obj 
)

Definition at line 698 of file mcmc.cpp.

◆ mcmc_advance()

void mcmc_advance ( ObjectiveFunction_t  lnprob,
mcmc_opts opts,
mcmc_recs recs,
void *  obj 
)

implement Ensemble Samplers with Affine Invariance, Goodman and Weare (2010)

Parameters
lnprobI, function calculating log probabiligy
parI/O, parameter vector
valI, measurement vector
npI, size of input parameter vector
nvI, size of measurement vector
nwalkerI, number of walkers
nstepI, number of steps
optsI, mcmc options
recsO, mcmc chains

Definition at line 738 of file mcmc.cpp.

◆ mcmc_stretch_move()

double mcmc_stretch_move ( double *  newp,
double **  oldp,
int  iwalker,
int  nwalker,
int  ndim,
mcmc_opts opts 
)

Definition at line 784 of file mcmc.cpp.

◆ mcmc_walk_move()

void mcmc_walk_move ( double *  newp,
double **  oldp,
int  k,
int  nwalker,
int  np,
mcmc_opts opts 
)

Definition at line 827 of file mcmc.cpp.