9 using std::istringstream;
30 long int iseed,
double size_scale);
40 const double& size_scale);
44 double total_spread,
int probflag=0);
48 double total_spreadd,
int probflag=0);
71 (
int feval,
int iter,
double fval,
double gmax);
74 double fval,
double gmax,
const char * cbuf);
106 cerr <<
" You must declare at least one object of type sdreport "
107 <<
endl <<
" to do the mcmc calculations" <<
endl;
174 dvector mean_mcmc_values(1,ndvar);
178 dvector square_mcmc_values(1,ndvar);
182 int use_empirical_flag=0;
188 int old_Hybrid_bounded_flag=-1;
195 cerr <<
"Usage -hyeps option needs number -- ignored" <<
endl;
204 cerr <<
"Usage -hyeps option needs positive number -- ignored\n";
219 cerr <<
" -hynstep argument must be integer between > 0 --"
220 " using default of 10" <<
endl;
232 cout <<
" Setting covariance matrix to diagonal with entries " << dscale
241 int rescale_bounded_flag=0;
242 double rescale_bounded_power=0.5;
248 if (iii < 1 || iii > 9)
250 cerr <<
" -mcrb argument must be integer between 1 and 9 --"
251 " using default of 5" <<
endl;
252 rescale_bounded_power=0.5;
255 rescale_bounded_power=iii/10.0;
259 rescale_bounded_power=0.5;
261 rescale_bounded_flag=1;
265 use_empirical_flag=1;
267 if (use_empirical_flag)
271 else if (!rescale_bounded_flag)
284 cerr <<
"error opening file " << tmpstring <<
endl;
290 cerr <<
"error reading from file " << tmpstring <<
endl;
293 if (tmp_nvar != nvar)
295 cerr <<
"size error reading from " << tmpstring <<
endl;
301 cerr <<
"error reading from file " << tmpstring <<
endl;
306 old_scale(1,old_nvar)=tmp;
336 for (
int i=1;i<=nvar;i++)
344 if ( mcrestart_flag>-1)
350 cerr <<
"Error trying to open file" <<
352 " for mcrestart" <<
endl;
358 cerr <<
"wrong number of independent variables in" <<
360 <<
" I found " << nv1 <<
" instead of " << nvar <<
endl;
364 std::streamoff sz = parsave.
size() *
sizeof(double);
366 uis.seekg(-sz, ios::end);
368 cout <<
" restored " << parsave(parsave.indexmin()) <<
" "
369 << parsave(parsave.indexmax()) <<
endl;
372 cerr <<
"error resotring last mcmc poistion from file "
388 if ( mcrestart_flag>-1)
421 if (!pofs_psave|| !(*pofs_psave))
423 cerr <<
"Error trying to open file" <<
427 if (mcrestart_flag == -1 )
429 (*pofs_psave) << nvar;
443 for (
int i=1;i<=nvar;i++)
445 for (
int j=1;j<=nvar;j++)
447 S(i,j)*=old_scale(i)*old_scale(j);
450 for (
int i=1;i<=nvar;i++)
452 for (
int j=1;j<=nvar;j++)
454 S(i,j)/=current_scale(i)*current_scale(j);
484 if (iseed0) iseed=iseed0;
485 if ( mcrestart_flag>-1)
487 ifstream ifs(
"hybrid_seed");
491 cerr <<
"error reading random number seed" <<
endl;
496 ofstream ogs(
"sims");
524 double choice=
randu(rng);
530 dmatrix xvalues(1,number_sims,1,nvar);
540 double r2=0.5*
norm2(p);
541 pprob=-
log(0.95*
exp(-r2)+0.05/3.0*
exp(-r2/9.0));
543 double Hbegin=beginprior+pprob;
548 cout <<
"Starting from y=" << y <<
endl;
549 cout <<
"Starting from z=" << z <<
endl;
550 cout <<
"Starting from gr=" << g <<
endl;
551 cout <<
"Starting from nll=" << beginprior <<
endl;
555 for (
int is=1;is<=number_sims;is++)
567 double rnd2=
randn(rng);
569 int hnsteps = (int)(
exp(0.2 * rnd2) * hybnstep);
571 double _hnsteps=
exp(0.2 * rnd2) * hybnstep;
572 assert(_hnsteps > 0 && _hnsteps <= (
double)INT_MAX);
573 int hnsteps = (int)_hnsteps;
575 for (
int i=1;i<=hnsteps;i++)
587 double r2=0.5*
norm2(phalf);
588 double z=0.95*
exp(-r2)+0.05/3.0*
exp(-r2/9.0);
589 double xx=(0.95*
exp(-r2)+0.05/27.0*
exp(-r2/9.0))/z;
608 double r2=0.5*
norm2(phalf);
609 double z=0.95*
exp(-r2)+0.05/3.0*
exp(-r2/9.0);
626 double r2=0.5*
norm2(p);
627 pprob=-
log(0.95*
exp(-r2)+0.05/3.0*
exp(-r2/9.0));
629 double Ham=tmpprior+pprob;
630 double rr=
randu(rng);
631 double pp=
exp(Hbegin-Ham);
636 double choice=
randu(rng);
648 double r2=0.5*
norm2(p);
649 pprob=-
log(0.95*
exp(-r2)+0.05/3.0*
exp(-r2/9.0));
653 cout <<
" hybrid sim " << is <<
" accept rate " << iaccept/is
654 <<
" Hbegin-Ham " << Hbegin-Ham <<
" Ham " << Ham <<
endl;
660 Hbegin=beginprior+pprob;
669 Hbegin=beginprior+pprob;
672 (*pofs_psave) << parsave;
681 ofstream ofs(
"hybrid_seed");
682 int seed=(int) (10000*
randu(rng));
void ad_update_mcmchist_report(dmatrix &mcmc_values, ivector &number_offsets, dvector &mean_mcmc_values, dvector &h, int ff=0)
static void restore_all_values(const dvector &x, const int &ii)
void make_preliminary_hist(const dvector &s, const dvector &m, int nsim, const dmatrix &values, dmatrix &hist, const dvector &h, int slots, double total_spread, int probflag=0)
void read_hessian_matrix_and_scale(int nvar, const dmatrix &S, const dvector &pen_vector)
static void set_NO_DERIVATIVES(void)
Disable accumulation of derivative information.
Description not yet available.
static void set_active_random_effects(void)
void allocate(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
dvector read_old_scale(int &old_nvar)
dvector new_probing_bounded_multivariate_normal(int nvar, const dvector &a1, const dvector &b1, dmatrix &ch, const double &wght, double pprobe, random_number_generator &rng)
void ad_update_mcmc_stats_report(int feval, int iter, double fval, double gmax)
int read_hist_data(const dmatrix &hist, const dvector &h, dvector &m, const dvector &s, const dvector &parsave, long int &iseed, const double &size_scale)
Vector of double precision numbers.
void allocate(int ncl, int ncu)
Allocate memory for a dvector.
void print_hist_data(const dmatrix &hist, const dmatrix &values, const dvector &h, dvector &m, const dvector &s, const dvector &parsave, long int iseed, double size_scale)
void hybrid_mcmc_routine(int, int, double, int)
Description not yet available.
void set_labels_for_mcmc(void)
static dvariable reset(const dvar_vector &x)
void ad_update_function_minimizer_report(int feval, int iter, int phase, double fval, double gmax, const char *cbuf)
static void restore_start_phase(void)
static adstring adprogram_name
static int num_stddev_calc(void)
int atoi(adstring &s)
Returns a integer converted from input s.
df1_one_matrix choleski_decomp(const df1_one_matrix &MM)
double randu(const random_number_generator &rng)
Uniform random number generator.
void fill_randn(long int &n)
Fill vector with random numbers.
Description not yet available.
void ad_update_mcmc_report(dmatrix &m, int i, int j, int ff=0)
void write_empirical_covariance_matrix(int ncor, const dvector &s_mean, const dmatrix &s_covar, adstring &prog_name)
Writes the covariance matrix out to a file, which is prog_name prepended to the extension '...
prnstream & endl(prnstream &)
Description not yet available.
Array of integers(int) with indexes from index_min to indexmax.
double get_hybrid_monte_carlo_value(int nvar, const independent_variables &y, dvector &g)
Written by Dave, commented by Cole starting 8/31/2016 Description not yet available.
Description not yet available.
Description not yet available.
static void xinit(const dvector &x)
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
static void set_inactive_random_effects(void)
Description not yet available.
void read_covariance_matrix(const dmatrix &S, int nvar, int &hbf, dvector &sscale)
void initialize(void)
Initialze all elements of dvector to zero.
double norm2(const d3_array &a)
Return sum of squared elements in a.
static void copy_all_values(const dvector &x, const int &ii)
void read_empirical_covariance_matrix(int nvar, const dmatrix &S, const adstring &prog_name)
Reads the covariance matrix from a file, which is the program name prepended to the extension '...
unsigned int size() const
Get number of elements in array.
int option_match(int argc, char *argv[], const char *string)
Checks if the program has been invoked with a particular command line argument ("string").
void store_mcmc_values(const ofstream &ofs)
double randn(const random_number_generator &rng)
Normal number generator.
int maxnz(const dvector &xa)
Description not yet available.
void new_probing_bounded_multivariate_normal_mcmc(int nvar, const dvector &a1, const dvector &b1, dmatrix &ch, const double &wght, const dvector &_y, double pprobe, random_number_generator &rng)
int minnz(const dvector &x)
static void set_YES_DERIVATIVES(void)
Enable accumulation of derivative information.
double better_rand(long int &idum)
Description not yet available.
Description not yet available.
void read_hessian_matrix_and_scale1(int nvar, const dmatrix &_SS, double s, int mcmc2_flag)
static int stddev_scale(const dvector &d, const dvector &x)
void initialize(void)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
void add_hist_values(const dvector &s, const dvector &m, const dmatrix &hist, dvector &mcmc_values, double llc, const dvector &h, int nslots, double total_spreadd, int probflag=0)
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
static int num_stddev_params