Canoe
Comprehensive Atmosphere N' Ocean Engine
mcmc.hpp
Go to the documentation of this file.
1 #ifndef SRC_INVERSION_MCMC_HPP_
2 #define SRC_INVERSION_MCMC_HPP_
3 #include <cstddef>
4 
5 #ifdef MPI_PARALLEL
6 #include <mpi.h>
7 #endif
8 
27 void _choldc(double **a, int n, double *p);
28 
33 int _acor(double *mean, double *sigma, double *tau, double *X, int L);
34 
36 struct mcmc_opts {
37  double a, b, c, d;
38  int p, q, r;
39 
40  int print;
41  char logfile[80];
42 
43 #ifdef MPI_PARALLEL
44  MPI_Comm mpi_comm;
45 #endif
46 };
47 
49 struct mcmc_recs {
50  int ndim,
55  double ***par,
56  ***val,
57  **lnp;
59  double *opt_par,
62  int **newstate;
64  int cur,
67  double opt_lnp;
68 };
69 
71 void mcmc_alloc(mcmc_recs *recs, int nstep, int nwalker, int ndim, int nvalue);
72 
74 void mcmc_free(mcmc_recs *recs);
75 
77 void mcmc_statistics(double *mean, double *sigma, double *tau, mcmc_recs *recs);
78 
80 void mcmc_save_fits(char const *fname, mcmc_opts *opts, mcmc_recs *recs,
81  int include_last = false);
82 
84 void mcmc_load_fits(char const *fname, mcmc_opts *opts, mcmc_recs *recs,
85  int alloc = true);
86 
88 void mcmc_append_recs(mcmc_recs *dst, mcmc_recs *src);
89 
90 // report MCMC sampler result
91 void mcmc_report(mcmc_opts *opts, mcmc_recs *recs, char const *mode);
92 
93 typedef double (*ObjectiveFunction_t)(double *, double *, int, int, void *);
94 
95 void mcmc_init(ObjectiveFunction_t lnprob, double **par, mcmc_opts *opts,
96  mcmc_recs *recs, void *obj);
97 
109 void mcmc_advance(ObjectiveFunction_t lnprob, mcmc_opts *opts, mcmc_recs *recs,
110  void *obj);
111 
112 double mcmc_stretch_move(double *newp, double **oldp, int iwalker, int nwalker,
113  int ndim, mcmc_opts *opts);
114 
115 void mcmc_walk_move(double *newp, double **oldp, int k, int nwalker, int np,
116  mcmc_opts *opts);
117 
118 #endif // SRC_INVERSION_MCMC_HPP_
double(* ObjectiveFunction_t)(double *, double *, int, int, void *)
Definition: mcmc.hpp:93
void mcmc_statistics(double *mean, double *sigma, double *tau, mcmc_recs *recs)
Definition: mcmc.cpp:160
void mcmc_append_recs(mcmc_recs *dst, mcmc_recs *src)
Definition: mcmc.cpp:459
void _choldc(double **a, int n, double *p)
Definition: mcmc.cpp:27
void mcmc_advance(ObjectiveFunction_t lnprob, mcmc_opts *opts, mcmc_recs *recs, void *obj)
Definition: mcmc.cpp:738
void mcmc_report(mcmc_opts *opts, mcmc_recs *recs, char const *mode)
Definition: mcmc.cpp:486
void mcmc_init(ObjectiveFunction_t lnprob, double **par, mcmc_opts *opts, mcmc_recs *recs, void *obj)
Definition: mcmc.cpp:698
void mcmc_free(mcmc_recs *recs)
Definition: mcmc.cpp:151
int _acor(double *mean, double *sigma, double *tau, double *X, int L)
Definition: mcmc.cpp:60
void mcmc_alloc(mcmc_recs *recs, int nstep, int nwalker, int ndim, int nvalue)
Definition: mcmc.cpp:126
void mcmc_load_fits(char const *fname, mcmc_opts *opts, mcmc_recs *recs, int alloc=true)
Definition: mcmc.cpp:379
void mcmc_walk_move(double *newp, double **oldp, int k, int nwalker, int np, mcmc_opts *opts)
Definition: mcmc.cpp:827
double mcmc_stretch_move(double *newp, double **oldp, int iwalker, int nwalker, int ndim, mcmc_opts *opts)
Definition: mcmc.cpp:784
void mcmc_save_fits(char const *fname, mcmc_opts *opts, mcmc_recs *recs, int include_last=false)
Definition: mcmc.cpp:179
double b
Definition: mcmc.hpp:37
double c
Definition: mcmc.hpp:37
int print
Definition: mcmc.hpp:40
int p
Definition: mcmc.hpp:38
int r
Definition: mcmc.hpp:38
double d
Definition: mcmc.hpp:37
char logfile[80]
Definition: mcmc.hpp:41
double a
Definition: mcmc.hpp:37
int q
Definition: mcmc.hpp:38
double *** val
Definition: mcmc.hpp:56
int ** newstate
Definition: mcmc.hpp:62
double * opt_par
Definition: mcmc.hpp:59
int nstep
Definition: mcmc.hpp:53
int reset
Definition: mcmc.hpp:66
int ndim
Definition: mcmc.hpp:50
int accept
Definition: mcmc.hpp:65
double * opt_val
Definition: mcmc.hpp:60
int nvalue
Definition: mcmc.hpp:51
double ** lnp
Definition: mcmc.hpp:57
double opt_lnp
Definition: mcmc.hpp:67
int cur
Definition: mcmc.hpp:64
int nwalker
Definition: mcmc.hpp:52
double *** par
Definition: mcmc.hpp:55