27 #ifndef O2SCL_MCMC_PARA_H 28 #define O2SCL_MCMC_PARA_H 40 #include <boost/numeric/ublas/vector.hpp> 42 #include <o2scl/uniform_grid.h> 43 #include <o2scl/table3d.h> 44 #include <o2scl/hdf_file.h> 45 #include <o2scl/exception.h> 46 #include <o2scl/prob_dens_func.h> 47 #include <o2scl/vector.h> 48 #include <o2scl/multi_funct.h> 49 #include <o2scl/interpm_idw.h> 50 #include <o2scl/vec_stats.h> 106 template<
class func_t,
class measure_t,
131 std::vector<rng_gsl>
rg;
179 scr_out.setf(std::ios::scientific);
189 scr_out <<
"mcmc (" << it <<
"): accept=" <<
n_accept[it]
190 <<
" reject=" <<
n_reject[it] << std::endl;
199 virtual void best_point(vec_t &best,
double w_best, data_t &dat) {
316 MPI_Comm_rank(MPI_COMM_WORLD,&this->mpi_rank);
317 MPI_Comm_size(MPI_COMM_WORLD,&this->mpi_nprocs);
344 virtual int mcmc(
size_t nparams, vec_t &low, vec_t &high,
345 std::vector<func_t> &func, std::vector<measure_t> &meas) {
347 if (initial_points.size()==0) {
349 initial_points.resize(1);
350 for(
size_t k=0;k<nparams;k++) {
351 initial_points[0][k]=(low[k]+high[k])/2.0;
356 for(
size_t iip=0;iip<initial_points.size();iip++) {
357 for(
size_t ipar=0;ipar<nparams;ipar++) {
358 if (initial_points[iip][ipar]<low[ipar] ||
359 initial_points[iip][ipar]>high[ipar]) {
363 ") in mcmc_base::mcmc().").c_str(),
372 omp_set_num_threads(n_threads);
373 n_threads=omp_get_num_threads();
380 mpi_start_time=MPI_Wtime();
382 mpi_start_time=time(0);
386 std::vector<int> func_ret(n_threads), meas_ret(n_threads);
390 if (n_walk<=1) n_walk=2;
396 if (aff_inv) step_fac=2.0;
401 rg.resize(n_threads);
402 unsigned long int seed=time(0);
403 if (this->user_seed!=0) {
407 seed*=(mpi_rank*n_threads+it+1);
408 rg[it].set_seed(seed);
412 n_accept.resize(n_threads);
413 n_reject.resize(n_threads);
422 if (n_warm_up==0) warm_up=
false;
428 current.resize(ssize);
429 std::vector<double> w_current(ssize);
430 for(
size_t i=0;i<ssize;i++) {
431 current[i].resize(nparams);
436 ret_value_counts.resize(n_threads);
437 curr_walker.resize(n_threads);
440 data_arr.resize(2*ssize);
441 switch_arr.resize(ssize);
442 for(
size_t i=0;i<switch_arr.size();i++) switch_arr[i]=
false;
445 std::vector<vec_t> next(n_threads);
447 next[it].resize(nparams);
449 std::vector<double> w_next(n_threads);
457 std::vector<bool> mcmc_done_flag(n_threads);
459 mcmc_done_flag[it]=
false;
470 O2SCL_ERR(
"Function mcmc_init() failed in mcmc_base::mcmc().",
478 scr_out <<
"mcmc: Affine-invariant step, n_params=" 479 << nparams <<
", n_walk=" << n_walk
480 <<
", n_threads=" << n_threads <<
", n_ranks=" 481 << mpi_nprocs << std::endl;
482 }
else if (pd_mode==
true) {
483 scr_out <<
"mcmc: With proposal distribution, n_params=" 484 << nparams <<
", n_threads=" << n_threads <<
", n_ranks=" 485 << mpi_nprocs << std::endl;
487 scr_out <<
"mcmc: Random-walk w/uniform dist., n_params=" 488 << nparams <<
", n_threads=" << n_threads <<
", n_ranks=" 489 << mpi_nprocs << std::endl;
500 #pragma omp parallel default(shared) 509 for(curr_walker[it]=0;curr_walker[it]<n_walk &&
510 mcmc_done_flag[it]==
false;curr_walker[it]++) {
513 size_t sindex=n_walk*it+curr_walker[it];
519 if (sindex<initial_points.size()) {
522 for(
size_t ipar=0;ipar<nparams;ipar++) {
523 current[sindex][ipar]=initial_points[sindex][ipar];
527 func_ret[it]=func[it](nparams,current[sindex],
528 w_current[sindex],data_arr[sindex]);
530 if (func_ret[it]==mcmc_done) {
531 mcmc_done_flag[it]=
true;
536 if (func_ret[it]>=0 &&
537 func_ret[it]<((
int)ret_value_counts[it].size())) {
538 ret_value_counts[it][func_ret[it]]++;
540 meas_ret[it]=meas[it](current[sindex],w_current[sindex],
541 curr_walker[it],
true,data_arr[sindex]);
542 if (meas_ret[it]==mcmc_done) {
543 mcmc_done_flag[it]=
true;
549 while (!done && !mcmc_done_flag[it]) {
552 for(
size_t ipar=0;ipar<nparams;ipar++) {
554 current[sindex][ipar]=
555 initial_points[sindex % initial_points.size()][ipar]+
556 (rg[it].random()*2.0-1.0)*
557 (high[ipar]-low[ipar])*ai_initial_step;
558 }
while (current[sindex][ipar]>high[ipar] ||
559 current[sindex][ipar]<low[ipar]);
563 func_ret[it]=func[it](nparams,current[sindex],
564 w_current[sindex],data_arr[sindex]);
571 if (func_ret[it]==mcmc_done) {
572 mcmc_done_flag[it]=
true;
577 if (func_ret[it]>=0 &&
578 func_ret[it]<((
int)ret_value_counts[it].size())) {
579 ret_value_counts[it][func_ret[it]]++;
581 if (meas_ret[it]!=mcmc_done) {
582 meas_ret[it]=meas[it](current[sindex],w_current[sindex],
583 curr_walker[it],
true,
586 mcmc_done_flag[it]=
true;
589 }
else if (init_iters>max_bad_steps) {
601 bool stop_early=
false;
603 if (mcmc_done_flag[it]==
true) {
605 scr_out <<
"mcmc (" << it <<
"): Returned mcmc_done " 606 <<
"(initial; ai)." << std::endl;
620 for(curr_walker[it]=0;curr_walker[it]<
n_walk;curr_walker[it]++) {
621 size_t sindex=n_walk*it+curr_walker[it];
622 if (w_current[sindex]>w_current[0]) {
624 w_best=w_current[sindex];
628 best=current[best_index];
634 for(curr_walker[it]=0;curr_walker[it]<
n_walk;curr_walker[it]++) {
635 size_t sindex=n_walk*it+curr_walker[it];
636 scr_out.precision(4);
637 scr_out <<
"mcmc (" << it <<
"): i_walk: ";
638 scr_out.width((
int)(1.0+log10((
double)(n_walk-1))));
639 scr_out << curr_walker[it] <<
" log_wgt: " 640 << w_current[sindex] <<
" (initial; ai)" << std::endl;
641 scr_out.precision(6);
656 for(
size_t ipar=0;ipar<nparams;ipar++) {
657 current[0][ipar]=initial_points[0][ipar];
662 func_ret[0]=func[0](nparams,current[0],w_current[0],data_arr[0]);
663 if (func_ret[0]==mcmc_done) {
665 scr_out <<
"mcmc: Initial point returned mcmc_done." 673 O2SCL_ERR(
"Initial weight vanished in mcmc_para_base::mcmc().",
680 #pragma omp parallel default(shared) 689 func_ret[it]=func_ret[0];
690 current[it]=current[0];
691 w_current[it]=w_current[0];
692 data_arr[it]=data_arr[0];
695 if (func_ret[it]>=0 &&
696 func_ret[it]<((
int)ret_value_counts[it].size())) {
697 ret_value_counts[it][func_ret[it]]++;
700 meas_ret[it]=meas[it](current[it],w_current[it],0,
702 if (meas_ret[it]==mcmc_done) {
703 mcmc_done_flag[it]=
true;
710 bool stop_early=
false;
712 if (mcmc_done_flag[it]==
true) {
714 scr_out <<
"mcmc (" << it <<
"): Returned mcmc_done " 715 <<
"(initial)." << std::endl;
731 scr_out.precision(4);
732 scr_out <<
"mcmc (0): " 733 << w_current[0] <<
" (initial)" << std::endl;
734 scr_out.precision(6);
740 std::cout <<
"Press a key and type enter to continue. ";
748 bool main_done=
false;
754 std::vector<double> smove_z(n_threads);
760 curr_walker[it]=mcmc_iters %
n_walk;
765 #pragma omp parallel default(shared) 780 ij=((size_t)(rg[it].random()*((double)n_walk)));
781 }
while (ij==curr_walker[it] || ij>=n_walk);
784 double p=rg[it].random();
786 smove_z[it]=(1.0-2.0*p+2.0*a*p+p*p-2.0*a*p*p+a*a*p*p)/a;
789 for(
size_t i=0;i<nparams;i++) {
790 next[it][i]=current[n_walk*it+ij][i]+
791 smove_z[it]*(current[n_walk*it+curr_walker[it]][i]-
792 current[n_walk*it+ij][i]);
795 }
else if (pd_mode) {
798 (*prop_dist)(current[it],next[it]);
799 q_prop=prop_dist->
log_pdf(current[it],next[it])-
800 prop_dist->
log_pdf(next[it],current[it]);
801 if (!std::isfinite(q_prop)) {
802 O2SCL_ERR2(
"Proposal distribution not finite in ",
809 for(
size_t k=0;k<nparams;k++) {
810 next[it][k]=current[it][k]+(rg[it].random()*2.0-1.0)*
811 (high[k]-low[k])/step_fac;
821 for(
size_t k=0;k<nparams;k++) {
822 if (next[it][k]<low[k] || next[it][k]>high[k]) {
826 if (func_ret[it]!=mcmc_skip) {
827 if (switch_arr[n_walk*it+curr_walker[it]]==
false) {
828 func_ret[it]=func[it](nparams,next[it],w_next[it],
829 data_arr[it*n_walk+curr_walker[it]+
832 func_ret[it]=func[it](nparams,next[it],w_next[it],
833 data_arr[it*n_walk+curr_walker[it]]);
835 if (func_ret[it]==mcmc_done) {
836 mcmc_done_flag[it]=
true;
838 if (func_ret[it]>=0 &&
839 func_ret[it]<((
int)ret_value_counts[it].size())) {
840 ret_value_counts[it][func_ret[it]]++;
852 if (func_ret[it]==mcmc_done) {
853 scr_out <<
"mcmc (" << it <<
"): Returned mcmc_done." 855 }
else if (func_ret[it]==mcmc_skip && verbose>=3) {
856 scr_out <<
"mcmc (" << it
857 <<
"): Parameter(s) out of range: " << std::endl;
858 scr_out.setf(std::ios::showpos);
859 for(
size_t k=0;k<nparams;k++) {
860 scr_out << k <<
" " << low[k] <<
" " 861 << next[it][k] <<
" " << high[k];
862 if (next[it][k]<low[k] || next[it][k]>high[k]) {
865 scr_out << std::endl;
867 scr_out.unsetf(std::ios::showpos);
869 func_ret[it]!=mcmc_skip) {
871 scr_out <<
"mcmc (" << it <<
"): Function returned failure " 872 << func_ret[it] <<
" at point ";
873 for(
size_t k=0;k<nparams;k++) {
874 scr_out << next[it][k] <<
" ";
876 scr_out << std::endl;
881 std::cout <<
"Press a key and type enter to continue. ";
888 #pragma omp parallel default(shared) 897 size_t sindex=n_walk*it+curr_walker[it];
903 if (always_accept && func_ret[it]==
success) accept=
true;
906 double r=rg[it].random();
909 double ai_ratio=pow(smove_z[it],((
double)nparams)-1.0)*
910 exp(w_next[it]-w_current[sindex]);
914 }
else if (pd_mode) {
915 if (r<exp(w_next[it]-w_current[sindex]+q_prop)) {
920 if (r<exp(w_next[it]-w_current[sindex])) {
934 if (switch_arr[sindex]==
false) {
935 meas_ret[it]=meas[it](next[it],w_next[it],curr_walker[it],
true,
936 data_arr[sindex+n_threads*
n_walk]);
938 meas_ret[it]=meas[it](next[it],w_next[it],curr_walker[it],
true,
944 current[sindex]=next[it];
945 w_current[sindex]=w_next[it];
946 switch_arr[sindex]=!(switch_arr[sindex]);
955 if (switch_arr[sindex]==
false) {
956 meas_ret[it]=meas[it](current[sindex],
958 curr_walker[it],
false,data_arr[sindex]);
960 meas_ret[it]=meas[it](current[sindex],
962 curr_walker[it],
false,
976 size_t sindex=n_walk*it+curr_walker[it];
977 scr_out.precision(4);
978 scr_out <<
"mcmc (" << it <<
"): iter: ";
979 scr_out.width((
int)(1.0+log10((
double)(nparams-1))));
980 scr_out << mcmc_iters <<
" i_walk: " 981 << curr_walker[it] <<
" log_wgt: " 982 << w_current[sindex] << std::endl;
983 scr_out.precision(6);
992 if (switch_arr[n_walk*it+curr_walker[it]]==
false) {
993 best_point(best,w_best,data_arr[curr_walker[it]+n_walk*it+
996 best_point(best,w_best,data_arr[curr_walker[it]+n_walk*it]);
1004 if (meas_ret[it]==mcmc_done || func_ret[it]==mcmc_done) {
1009 O2SCL_ERR((((std::string)
"Measurement function returned ")+
1011 " in mcmc_para_base::mcmc().").c_str(),
1018 if (main_done==
false) {
1022 if (warm_up && mcmc_iters==n_warm_up) {
1030 scr_out <<
"Finished warmup." << std::endl;
1037 std::cout <<
"Press a key and type enter to continue. ";
1042 if (main_done==
false && warm_up==
false && max_iters>0 &&
1043 mcmc_iters==max_iters) {
1044 scr_out <<
"mcmc (0): Stopping because number of iterations " 1045 <<
"equal to 'max_iters'." << std::endl;
1049 if (main_done==
false) {
1056 if (max_time>0.0 && elapsed>max_time) {
1058 scr_out <<
"mcmc (0): Stopping because elapsed > max_time." 1136 template<
class func_t,
class fill_t,
class data_t,
class vec_t=ubvector>
1138 std::function<int(const vec_t &,double,size_t,bool,data_t &)>,
1144 typedef std::function<int(const vec_t &,double,size_t,bool,data_t &)>
1157 std::shared_ptr<o2scl::table_units<> >
table;
1171 table->new_column(
"thread");
1172 table->new_column(
"walker");
1173 table->new_column(
"mult");
1174 table->new_column(
"log_wgt");
1175 for(
size_t i=0;i<col_names.size();i++) {
1176 table->new_column(col_names[i]);
1177 if (col_units[i].length()>0) {
1178 table->set_unit(col_names[i],col_units[i]);
1201 return parent_t::mcmc_init();
1207 std::vector<double> &line, data_t &dat,
1208 size_t i_walker, fill_t &fill) {
1211 size_t i_thread=omp_get_thread_num();
1217 line.push_back(i_thread);
1219 line.push_back(i_walker);
1221 line.push_back(1.0);
1222 line.push_back(log_weight);
1223 for(
size_t i=0;i<pars.size();i++) {
1224 line.push_back(pars[i]);
1226 int tempi=fill(pars,log_weight,line,dat);
1247 int tag=0, buffer=0;
1249 MPI_Recv(&buffer,1,MPI_INT,this->
mpi_rank-1,tag,MPI_COMM_WORLD,
1258 if (first_write==
false) {
1273 hf.
seti(
"allow_estimates",allow_estimates);
1286 hdf_output(hf,*table,
"markov_chain0");
1292 MPI_Send(&buffer,1,MPI_INT,this->
mpi_rank+1,tag,MPI_COMM_WORLD);
1303 allow_estimates=
false;
1312 std::vector<std::string> units) {
1326 vec_t &low, vec_t &high, std::vector<func_t> &func,
1327 std::vector<fill_t> &fill) {
1340 std::vector<internal_measure_t> meas(this->
n_threads);
1341 for(
size_t it=0;it<this->
n_threads;it++) {
1343 (std::mem_fn<
int(
const vec_t &,
double,
size_t,
bool,
1344 data_t &,
size_t, fill_t &)>
1346 std::placeholders::_2,std::placeholders::_3,std::placeholders::_4,
1347 std::placeholders::_5,it,std::ref(fill[it]));
1350 return parent_t::mcmc(nparams,low,high,func,meas);
1371 csizes.resize(ntot);
1373 for(
size_t it=0;it<this->
n_threads;it++) {
1374 for(
size_t iw=0;iw<this->
n_walk;iw++) {
1375 size_t ix=it*this->n_walk+iw;
1378 for(
size_t j=istart;j<table->get_nlines();j+=ntot) {
1379 if (table->get(
"mult",j)>0.5) csizes[ix]++;
1390 virtual int add_line(
const vec_t &pars,
double log_weight,
1391 size_t walker_ix,
bool new_meas, data_t &dat,
1392 size_t i_thread, fill_t &fill) {
1395 size_t windex=i_thread*this->
n_walk+walker_ix;
1406 #pragma omp critical (o2scl_mcmc_para_table_add_line) 1412 if ((walker_rows[windex]<0 && table->get_nlines()<ntot) ||
1413 table->get_nlines()<=walker_rows[windex]+ntot) {
1414 size_t istart=table->get_nlines();
1416 table->set_nlines(table->get_nlines()+ntot);
1419 for(
size_t i=0;i<this->
n_walk;i++) {
1420 table->set(
"thread",istart+j*this->n_walk+i,j);
1421 table->set(
"walker",istart+j*this->n_walk+i,i);
1422 table->set(
"mult",istart+j*this->n_walk+i,0.0);
1423 table->set(
"log_wgt",istart+j*this->n_walk+i,-1.0);
1433 if (new_meas==
true || walker_rows[windex]<0) {
1437 if (walker_rows[windex]>=0) {
1438 walker_rows[windex]+=ntot;
1440 walker_rows[windex]=windex;
1443 if (walker_rows[windex]>=((
int)(table->get_nlines()))) {
1447 std::vector<double> line;
1448 int fret=fill_line(pars,log_weight,line,dat,walker_ix,fill);
1462 if (line.size()!=table->get_ncolumns()) {
1463 std::cout <<
"line: " << line.size() <<
" columns: " 1464 << table->get_ncolumns() << std::endl;
1465 O2SCL_ERR(
"Table misalignment in mcmc_para_table::add_line().",
1469 table->set_row(((
size_t)walker_rows[windex]),line);
1477 double mult_old=table->get(
"mult",walker_rows[windex]);
1478 table->set(
"mult",walker_rows[windex],mult_old+1.0);
1497 for(i=table->get_nlines()-1;i>=0 && done==
false;i--) {
1499 if (table->get(
"mult",i)<1.0e-10) {
1503 if (i+2<((
int)table->get_nlines())) {
1504 table->set_nlines(i+2);
1506 return parent_t::mcmc_cleanup();
1512 std::vector<size_t> csizes;
1513 get_chain_sizes(csizes);
1514 size_t min_size=csizes[0];
1515 for(
size_t i=1;i<csizes.size();i++) {
1516 if (csizes[i]<min_size) min_size=csizes[i];
1518 size_t N_max=min_size/2;
1519 ac_coeffs.resize(ncols,N_max-1);
1520 for(
size_t i=0;i<ncols;i++) {
1521 for(
size_t ell=1;ell<N_max;ell++) {
1522 ac_coeffs(i,ell-1)=0.0;
1527 size_t cstart=table->lookup_column(
"log_wgt")+1;
1528 for(
size_t i=0;i<ncols;i++) {
1530 for(
size_t k=0;k<
n_walk;k++) {
1531 size_t tindex=j*n_walk+k;
1532 for(
size_t ell=1;ell<N_max;ell++) {
1533 double mean=o2scl::vector_mean_double
1534 (csizes[tindex]+1,&((*table)[cstart+i][table_row]));
1536 (csizes[tindex]+1,&((*table)[cstart+i][table_row]),
1539 table_row+=csizes[tindex]+1;
1542 for(
size_t ell=1;ell<N_max;ell++) {
1543 ac_coeffs(i,ell-1)/=((double)n_tot);
1552 ubvector &ac_lengths) {
1553 size_t N_max=ac_coeffs_cols.size2();
1554 ac_lengths.resize(ncols);
1555 for(
size_t icol=0;icol<ncols;icol++) {
1556 std::vector<double> tau(N_max);
1557 for(
size_t i=5;i<N_max;i++) {
1559 for(
size_t j=0;j<i;j++) {
1560 sum+=ac_coeffs_cols(icol,j);
1563 std::cout << tau[i] <<
" " << ((double)i)/5.0 << std::endl;
1565 std::cout << std::endl;
1575 std::shared_ptr<o2scl::table_units<> > table2=
1579 for(
size_t j=0;j<
n_walk;j++) {
1580 std::string func=std::string(
"abs(walker-")+
o2scl::szttos(j)+
1582 table->copy_rows(func,*table2);
1604 for(
size_t it=0;it<this->
n_threads;it++) {
1606 size_t n=table->get_nlines();
1608 O2SCL_ERR2(
"Cannot reblock. Not enough data in ",
1611 size_t n_block=n/n_blocks;
1612 size_t m=table->get_ncolumns();
1613 for(
size_t j=0;j<n_blocks;j++) {
1616 for(
size_t i=0;i<m;i++) {
1619 for(
size_t k=j*n_block;k<(j+1)*n_block;k++) {
1620 mult+=(*table)[
"mult"][k];
1621 for(
size_t i=1;i<m;i++) {
1622 dat[i]+=(*table)[i][k]*(*table)[
"mult"][k];
1625 table->set(
"mult",j,mult);
1626 for(
size_t i=1;i<m;i++) {
1628 table->set(i,j,dat[i]);
1631 table->set_nlines(n_blocks);
double vector_lagk_autocorr(size_t n, const vec_t &data, size_t k, double mean)
Lag-k autocorrelation.
std::shared_ptr< o2scl::table_units<> > table
Main data table for Markov chain.
std::vector< data_t > data_arr
Data array.
std::string prefix
Prefix for output filenames.
static const int mcmc_done
Integer to indicate completion.
double ai_initial_step
Initial step fraction for affine-invariance sampling walkers (default 0.1)
Multi-dimensional interpolation by inverse distance weighting.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
virtual double log_pdf(const vec_t &x, const vec_t &x2) const =0
The log of the normalized density.
int set_szt_vec(std::string name, const std::vector< size_t > &v)
Set vector dataset named name with v.
size_t n_warm_up
Number of warm up steps (successful steps not iterations) (default 0)
A generic MCMC simulation class writing data to a o2scl::table_units object.
bool allow_estimates
If true, allow estimates of the weight (default false)
bool err_nonconv
If true, call the error handler if msolve() or msolve_de() does not converge (default true) ...
int verbose
Output control (default 0)
std::vector< vec_t > current
Current points in parameter space for each walker and each OpenMP thread.
virtual int mcmc(size_t nparams, vec_t &low, vec_t &high, std::vector< func_t > &func, std::vector< fill_t > &fill)
Perform an MCMC simulation.
void close()
Close the file.
void set_szt(std::string name, size_t u)
Set an unsigned integer named name to value u.
void setd(std::string name, double d)
Set a double named name to value d.
bool aff_inv
If true, use affine-invariant Monte Carlo.
size_t max_iters
If non-zero, the maximum number of MCMC iterations (default 0)
sanity check failed - shouldn't happen
std::vector< bool > switch_arr
Data switch array for each walker and each OpenMP thread.
std::vector< std::string > col_names
Column names.
invalid argument supplied by user
virtual void ac_lengths(size_t ncols, ubmatrix &ac_coeffs_cols, ubvector &ac_lengths)
Desc.
int mpi_nprocs
The MPI number of processors.
std::function< int(const vec_t &, double, size_t, bool, data_t &)> internal_measure_t
Measurement functor type for the parent.
std::vector< std::vector< size_t > > ret_value_counts
Return value counters, one vector for each OpenMP thread.
void seti(std::string name, int i)
Set an integer named name to value i.
std::vector< size_t > curr_walker
Index of the current walker.
double step_fac
Stepsize factor (default 10.0)
A multi-dimensional conditional probability density function.
virtual void unset_proposal()
Go back to random-walk Metropolis with a uniform distribution.
virtual int add_line(const vec_t &pars, double log_weight, size_t walker_ix, bool new_meas, data_t &dat, size_t i_thread, fill_t &fill)
A measurement function which adds the point to the table.
bool always_accept
If true, accept all steps.
std::vector< ubvector > initial_points
Initial points in parameter space.
virtual void write_files()
Write MCMC tables to files.
o2scl::prob_cond_mdim< vec_t > * prop_dist
Proposal distribution.
size_t n_walk
Number of walkers for affine-invariant MC or 1 otherwise (default 1)
virtual void mcmc_cleanup()
Desc.
void sets(std::string name, std::string s)
Set a string named name to value s.
virtual int mcmc(size_t nparams, vec_t &low, vec_t &high, std::vector< func_t > &func, std::vector< measure_t > &meas)
Perform an MCMC simulation.
std::vector< std::string > col_units
Column units.
double mpi_start_time
The MPI starting time.
void open_or_create(std::string fname)
Open a file named fname or create if it doesn't already exist.
virtual int fill_line(const vec_t &pars, double log_weight, std::vector< double > &line, data_t &dat, size_t i_walker, fill_t &fill)
Fill line with data for insertion into the table.
double max_time
Time in seconds (default is 0)
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
std::string dtos(double x, int prec=6, bool auto_prec=false)
Convert a double to a string.
int user_seed
If non-zero, use as the seed for the random number generator (default 0)
void reblock(size_t n_blocks)
Reaverage the data into blocks of a fixed size in order to avoid autocorrelations.
int set_szt_arr2d_copy(std::string name, size_t r, size_t c, const arr2d_t &a2d)
Set a two-dimensional array dataset named name with m.
std::vector< size_t > n_reject
The number of Metropolis steps which were rejected in each thread (summed over all walkers) ...
virtual void set_names_units(std::vector< std::string > names, std::vector< std::string > units)
Set the table names and units.
bool warm_up
If true, we are in the warm up phase.
std::vector< size_t > n_accept
The number of Metropolis steps which were accepted in each thread (summed over all walkers) ...
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
bool pd_mode
If true, then use the user-specified proposal distribution.
virtual void reorder_table()
Reorder the table by thread and walker index.
std::vector< int > walker_rows
Record the last row in the table which corresponds to each walker.
int setd_arr2d_copy(std::string name, size_t r, size_t c, const arr2d_t &a2d)
Set a two-dimensional array dataset named name with m.
virtual void mcmc_cleanup()
Cleanup after the MCMC.
virtual int mcmc_init()
MCMC initialization function.
virtual void set_proposal(o2scl::prob_cond_mdim< vec_t > &p)
Set the proposal distribution.
Data table table class with units.
virtual int mcmc_init()
Initializations before the MCMC.
int mpi_rank
The MPI processor rank.
static const int mcmc_skip
Integer to indicate rejection.
size_t max_bad_steps
Maximum number of failed steps when generating initial points with affine-invariant sampling (default...
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
virtual void best_point(vec_t &best, double w_best, data_t &dat)
Function to run for the best point.
interpm_idw< double * > esti
Likelihood estimator.
size_t n_threads
Number of OpenMP threads.
mcmc_para_base< func_t, internal_measure_t, data_t, vec_t > parent_t
Type of parent class.
std::string itos(int x)
Convert an integer to a string.
A generic MCMC simulation class.
std::vector< rng_gsl > rg
Random number generators.
void set_table(std::shared_ptr< o2scl::table_units<> > &t)
Set the output table.
std::string szttos(size_t x)
Convert a size_t to a string.
std::shared_ptr< o2scl::table_units<> > get_table()
Get the output table.
std::ofstream scr_out
The screen output file.
virtual void ac_coeffs(size_t ncols, ubmatrix &ac_coeffs)
Desc.
void get_chain_sizes(std::vector< size_t > &csizes)
Determine the chain sizes.