hops
AcceptanceRateTuner.hpp
Go to the documentation of this file.
1 #ifndef HOPS_ACCEPTANCERATETUNER_HPP
2 #define HOPS_ACCEPTANCERATETUNER_HPP
3 
11 
12 #include <Eigen/Core>
13 
14 #include <chrono>
15 #include <cmath>
16 #include <memory>
17 #include <vector>
18 
19 #ifdef _OPENMP
20 #include <omp.h>
21 #endif
22 
23 namespace hops {
25  public:
26  struct param_type {
37  size_t randomSeed;
38  bool recordData;
39 
45  size_t stepSizeGridSize,
46  double stepSizeLowerBound,
47  double stepSizeUpperBound,
48  double smoothingLength,
49  size_t randomSeed,
50  bool recordData = false
51  );
52  };
53 
62  static bool
63  tune(std::vector<std::shared_ptr<MarkovChain>>& markovChain,
64  std::vector<RandomNumberGenerator>& randomNumberGenerator,
65  param_type &parameters);
66 
75  static bool
76  tune(double& stepSize,
77  double& deltaAcceptanceRate,
78  std::vector<std::shared_ptr<MarkovChain>>& markovChain,
79  std::vector<RandomNumberGenerator>& randomNumberGenerator,
80  param_type &parameters);
81 
90  static bool
91  tune(double& stepSize,
92  double& deltaAcceptanceRate,
93  std::vector<std::shared_ptr<MarkovChain>>& markovChain,
94  std::vector<RandomNumberGenerator>& randomNumberGenerator,
95  param_type&,
96  Eigen::MatrixXd&,
97  Eigen::MatrixXd&);
98 
99  AcceptanceRateTuner() = delete;
100  };
101 
102  namespace internal {
103  struct AcceptanceRateTarget : public ThompsonSamplingTarget<double, Eigen::VectorXd> {
104  std::vector<std::shared_ptr<hops::MarkovChain>> markovChain;
105  std::vector<RandomNumberGenerator>* randomNumberGenerator;
107 
108  AcceptanceRateTarget(std::vector<std::shared_ptr<hops::MarkovChain>>& markovChain,
109  std::vector<hops::RandomNumberGenerator>& randomNumberGenerator,
114 
115  virtual std::tuple<double, double> operator()(const Eigen::VectorXd& x) override;
116  };
117  }
118 }
119 
120 #endif //HOPS_ACCEPTANCERATETUNER_HPP
hops::AcceptanceRateTuner::param_type::iterationsToTestStepSize
size_t iterationsToTestStepSize
Definition: AcceptanceRateTuner.hpp:28
hops::AcceptanceRateTuner::param_type
Definition: AcceptanceRateTuner.hpp:26
hops::AcceptanceRateTuner::param_type::recordData
bool recordData
Definition: AcceptanceRateTuner.hpp:38
hops::internal::ThompsonSamplingTarget
Definition: ThompsonSampling.hpp:17
hops::AcceptanceRateTuner::AcceptanceRateTuner
AcceptanceRateTuner()=delete
hops::AcceptanceRateTuner::param_type::posteriorUpdateIterationsNeeded
size_t posteriorUpdateIterationsNeeded
Definition: AcceptanceRateTuner.hpp:32
hops::internal::AcceptanceRateTarget::parameters
AcceptanceRateTuner::param_type parameters
Definition: AcceptanceRateTuner.hpp:106
hops::internal::AcceptanceRateTarget::randomNumberGenerator
std::vector< RandomNumberGenerator > * randomNumberGenerator
Definition: AcceptanceRateTuner.hpp:105
hops::internal::AcceptanceRateTarget
Definition: AcceptanceRateTuner.hpp:103
FileWriterType.hpp
hops::internal::AcceptanceRateTarget::AcceptanceRateTarget
AcceptanceRateTarget(std::vector< std::shared_ptr< hops::MarkovChain >> &markovChain, std::vector< hops::RandomNumberGenerator > &randomNumberGenerator, const hops::AcceptanceRateTuner::param_type &parameters)
Definition: AcceptanceRateTuner.hpp:108
FileWriterFactory.hpp
hops::internal::AcceptanceRateTarget::operator()
virtual std::tuple< double, double > operator()(const Eigen::VectorXd &x) override
measures the stepsize of a configured step size
Definition: AcceptanceRateTuner.cpp:10
hops::AcceptanceRateTuner::param_type::stepSizeLowerBound
double stepSizeLowerBound
Definition: AcceptanceRateTuner.hpp:34
hops::AcceptanceRateTuner::param_type::stepSizeUpperBound
double stepSizeUpperBound
Definition: AcceptanceRateTuner.hpp:35
hops::AcceptanceRateTuner::param_type::posteriorUpdateIterations
size_t posteriorUpdateIterations
Definition: AcceptanceRateTuner.hpp:29
GaussianProcess.hpp
hops::AcceptanceRateTuner::param_type::smoothingLength
double smoothingLength
Definition: AcceptanceRateTuner.hpp:36
hops::AcceptanceRateTuner::param_type::param_type
param_type(double m_acceptanceRateTargetValue, size_t iterationsToTestStepSize, size_t posteriorUpdateIterations, size_t pureSamplingIterations, size_t iterationsForConvergence, size_t stepSizeGridSize, double stepSizeLowerBound, double stepSizeUpperBound, double smoothingLength, size_t randomSeed, bool recordData=false)
Definition: AcceptanceRateTuner.cpp:139
hops
Definition: CsvReader.hpp:8
MarkovChain.hpp
hops::AcceptanceRateTuner::param_type::randomSeed
size_t randomSeed
Definition: AcceptanceRateTuner.hpp:37
hops::AcceptanceRateTuner::param_type::m_acceptanceRateTargetValue
double m_acceptanceRateTargetValue
Definition: AcceptanceRateTuner.hpp:27
hops::AcceptanceRateTuner::param_type::pureSamplingIterations
size_t pureSamplingIterations
Definition: AcceptanceRateTuner.hpp:30
MarkovChainAttribute.hpp
ThompsonSampling.hpp
hops::AcceptanceRateTuner
Definition: AcceptanceRateTuner.hpp:24
hops::AcceptanceRateTuner::param_type::stepSizeGridSize
size_t stepSizeGridSize
Definition: AcceptanceRateTuner.hpp:33
FileWriter.hpp
hops::AcceptanceRateTuner::param_type::iterationsForConvergence
size_t iterationsForConvergence
Definition: AcceptanceRateTuner.hpp:31
hops::AcceptanceRateTuner::tune
static bool tune(std::vector< std::shared_ptr< MarkovChain >> &markovChain, std::vector< RandomNumberGenerator > &randomNumberGenerator, param_type &parameters)
tunes markov chain acceptance rate by nested intervals. The chain is not guaranteed to have converged...
hops::internal::AcceptanceRateTarget::markovChain
std::vector< std::shared_ptr< hops::MarkovChain > > markovChain
Definition: AcceptanceRateTuner.hpp:104