StanConfig.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace ana
4 {
5  /// Configuration parameters for the Stan MCMC fitter, bundled up together for easy storage and parameter passing
6  struct StanConfig
7  {
8  enum class Verbosity
9  {
10  kSilent,
11  kQuiet,
12  kVerbose,
14  };
15 
16  /// Constructor initializes to Stan's default values. See the documentation on the members for what the parameters mean
17  /// (defaults lifted from CmdStan output; see, e.g., examples in CmdStan manual, ch. 2.)
18  StanConfig(unsigned int _random_seed = 4294967295,
19  unsigned int _chain = 1,
20  double _init_radius = 2.0,
21  int _num_warmup = 1000,
22  int _num_samples = 1000,
23  int _num_thin = 1,
24  bool _save_warmup = true, // not Stan default, but we save warmup separately from regular samples, so no chance of getting confused
25  int _refresh = 100,
26  double _stepsize = 1,
27  double _stepsize_jitter = 0,
28  int _max_depth = 10,
29  double _delta = 0.8,
30  double _kappa = 0.75,
31  double _gamma = 0.05,
32  double _t0 = 10,
33  unsigned int _init_buffer = 75,
34  unsigned int _term_buffer = 50,
35  unsigned int _window = 25,
37  bool _denseMassMx = false)
38  : random_seed(_random_seed),
39  chain(_chain),
40  init_radius(_init_radius),
41  num_warmup(_num_warmup),
42  num_samples(_num_samples),
43  num_thin(_num_thin),
44  save_warmup(_save_warmup),
45  refresh(_refresh),
46  stepsize(_stepsize),
47  stepsize_jitter(_stepsize_jitter),
48  max_depth(_max_depth),
49  delta(_delta),
50  kappa(_kappa),
51  gamma(_gamma),
52  t0(_t0),
53  init_buffer(_init_buffer),
54  term_buffer(_term_buffer),
55  window(_window),
56  verbosity(_verbosity),
57  denseMassMx(_denseMassMx)
58  {}
59 
60  unsigned int random_seed; ///< Random seed used by Stan internally
61  unsigned int chain; ///< Number of Markov chains to run (1 per core)
62  double init_radius; ///< Size of the range in *unconstrained* parameter space where the initial point for un-specified parameters is randomly seeded
63  int num_warmup; ///< Number of initial steps in the Markov chain (used to enter the typical set). These are usually discarded because they may not be sampled proportionally to the likelihood.
64  int num_samples; ///< Number of steps in the Markov chain retained for analysis (after warmup).
65  int num_thin; ///< Number of Markov chain steps between saved samples when sampling.
66  bool save_warmup; ///< Save the warmup steps?
67  int refresh; ///< Number of iterations between printout updates. Only relevant when fitting in 'verbose' mode
68  double stepsize; ///< Integrator step size used in each simulation. Typically this is adaptive and the default value is a fine initial guess.
69  double stepsize_jitter; ///< Randomly "jitter" the step size by this fraction of the step size. (Sometimes can help if the integrator is getting "stuck" in regions of high curvature, but usually not needed.)
70  int max_depth; ///< Depth of the binary tree used by the HMC when taking its leapfrog steps. Note: the number of leapfrog steps taken is 2**(tree_depth), so increase with care!
71 
72  ///@{
73  /// Parameters controlling the automatic MCMC step size adaptation
74  /// that happens during the warmup period.
75  /// See the Stan documentation for more insight on what they do
76  /// and how to set them properly if you need to adjust them beyond the defaults.
77  /// (The CmdStan manual has a nice quick synopsis of each; the full Stan manual
78  /// has more statistics references and explanation of what's going on if you need.
79  /// In general you probably don't want to adjust these unless you know what you're doing.)
80  double delta = 0.8; ///< Adaptation target acceptance statistic; 0 < delta < 1
81  double kappa = 0.75; ///< Adaptation relaxation exponent; kappa > 0
82  double gamma = 0.05; ///< Adaptation regularization scale; gamma > 0
83  double t0 = 10; ///< Adaptation iteration offset; t0 > 0
84  unsigned int init_buffer = 75; ///< Width of initial fast adaptation interval
85  unsigned int term_buffer = 50; ///< Width of final fast adaptation interval
86  unsigned int window = 25; ///< Initial width of slow adaptation interval
87  ///@}
88 
89  Verbosity verbosity; ///< How verbose do you want me to be?
90  bool denseMassMx; ///< Should the mass matrix used in HMC be diagonal (default) or dense?
91 
92  };
93 
94  /// Allow for comparing them, since kQuiet is definitely "less" verbose than kVerbose
96  {
97  return static_cast<int>(a) < static_cast<int>(b);
98  }
99 
101  {
102  return a != b && !(static_cast<int>(a) < static_cast<int>(b));
103  }
104 
105 }
double delta
Adaptation target acceptance statistic; 0 < delta < 1.
Definition: StanConfig.h:80
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
unsigned int chain
Number of Markov chains to run (1 per core)
Definition: StanConfig.h:61
StanConfig(unsigned int _random_seed=4294967295, unsigned int _chain=1, double _init_radius=2.0, int _num_warmup=1000, int _num_samples=1000, int _num_thin=1, bool _save_warmup=true, int _refresh=100, double _stepsize=1, double _stepsize_jitter=0, int _max_depth=10, double _delta=0.8, double _kappa=0.75, double _gamma=0.05, double _t0=10, unsigned int _init_buffer=75, unsigned int _term_buffer=50, unsigned int _window=25, StanConfig::Verbosity _verbosity=StanConfig::Verbosity::kQuiet, bool _denseMassMx=false)
Definition: StanConfig.h:18
bool operator>(StanConfig::Verbosity a, StanConfig::Verbosity b)
Definition: StanConfig.h:100
double stepsize
Integrator step size used in each simulation. Typically this is adaptive and the default value is a f...
Definition: StanConfig.h:68
Configuration parameters for the Stan MCMC fitter, bundled up together for easy storage and parameter...
Definition: StanConfig.h:6
Verbosity verbosity
How verbose do you want me to be?
Definition: StanConfig.h:89
bool save_warmup
Save the warmup steps?
Definition: StanConfig.h:66
unsigned int term_buffer
Width of final fast adaptation interval.
Definition: StanConfig.h:85
double init_radius
Size of the range in unconstrained parameter space where the initial point for un-specified parameter...
Definition: StanConfig.h:62
int refresh
Number of iterations between printout updates. Only relevant when fitting in &#39;verbose&#39; mode...
Definition: StanConfig.h:67
const double a
bool operator<(StanConfig::Verbosity a, StanConfig::Verbosity b)
Allow for comparing them, since kQuiet is definitely "less" verbose than kVerbose.
Definition: StanConfig.h:95
int num_warmup
Number of initial steps in the Markov chain (used to enter the typical set). These are usually discar...
Definition: StanConfig.h:63
bool denseMassMx
Should the mass matrix used in HMC be diagonal (default) or dense?
Definition: StanConfig.h:90
unsigned int window
Definition: StanConfig.h:86
double stepsize_jitter
Randomly "jitter" the step size by this fraction of the step size. (Sometimes can help if the integra...
Definition: StanConfig.h:69
int max_depth
Depth of the binary tree used by the HMC when taking its leapfrog steps. Note: the number of leapfrog...
Definition: StanConfig.h:70
double gamma
Adaptation regularization scale; gamma > 0.
Definition: StanConfig.h:82
unsigned int init_buffer
Width of initial fast adaptation interval.
Definition: StanConfig.h:84
int num_thin
Number of Markov chain steps between saved samples when sampling.
Definition: StanConfig.h:65
const hit & b
Definition: hits.cxx:21
double kappa
Adaptation relaxation exponent; kappa > 0.
Definition: StanConfig.h:81
double t0
Adaptation iteration offset; t0 > 0.
Definition: StanConfig.h:83
unsigned int random_seed
Random seed used by Stan internally.
Definition: StanConfig.h:60
int num_samples
Number of steps in the Markov chain retained for analysis (after warmup).
Definition: StanConfig.h:64