MaCh3  2.2.3
Reference Guide
AdaptiveMCMCHandler.h
Go to the documentation of this file.
1 #pragma once
2 
3 // MaCh3 Includes
4 #include "Manager/Manager.h"
6 
7 namespace adaptive_mcmc{
8 
14  public:
17 
19  virtual ~AdaptiveMCMCHandler();
20 
22  void Print() const;
23 
31  bool InitFromConfig(const YAML::Node& adapt_manager, const std::string& matrix_name_str,
32  const std::vector<double>* parameters, const std::vector<double>* fixed);
33 
36 
39  void SetAdaptiveBlocks(const std::vector<std::vector<int>>& block_indices);
40 
42  void SaveAdaptiveToFile(const std::string& outFileName, const std::string& systematicName, const bool is_final=false);
43 
48  void SetThrowMatrixFromFile(const std::string& matrix_file_name,
49  const std::string& matrix_name,
50  const std::string& means_name,
51  bool& use_adaptive);
52 
57 
59  bool IndivStepScaleAdapt() const;
60 
62  bool UpdateMatrixAdapt();
63 
65  bool AdaptionUpdate() const;
66 
68  bool SkipAdaption() const;
69 
71  void SetParams(const std::vector<double>* params) {
72  _fCurrVal = params;
73  }
74 
76  void SetFixed(const std::vector<double>* fix) {
77  _fFixedPars = fix;
78  }
79 
82  int GetNumParams() const {
83  return static_cast<int>(_fCurrVal->size());
84  }
85 
87  bool IsFixed(const int ipar) const {
88  if(!_fFixedPars){
89  return false;
90  }
91  return ((*_fFixedPars)[ipar] < 0);
92  }
93 
95  double CurrVal(const int par_index) const;
96 
99  int GetTotalSteps() const {
100  return total_steps;
101  }
102 
104  void SetTotalSteps(const int nsteps) {
105  total_steps = nsteps;
106  }
107 
110  total_steps++;
111  }
112 
115  TMatrixDSym* GetAdaptiveCovariance() const {
116  return adaptive_covariance;
117  }
118 
121  std::vector<double> GetParameterMeans() const {
122  return par_means;
123  }
124 
127  std::string GetOutFileName() const {
128  return output_file_name;
129  }
130 
131  private:
135 
138 
141 
144 
148 
150  std::string output_file_name;
151 
153  std::vector<int> adapt_block_matrix_indices;
154 
156  std::vector<int> adapt_block_sizes;
157 
158  // Variables directedly linked to adaption
160  std::vector<double> par_means;
161 
163  TMatrixDSym* adaptive_covariance;
164 
167 
170 
172  const std::vector<double>* _fFixedPars;
173 
175  const std::vector<double>* _fCurrVal;
176 };
177 
178 } // adaptive_mcmc namespace
Contains information about adaptive covariance matrix .
std::vector< double > par_means
Mean values for all parameters.
bool IsFixed(const int ipar) const
Check if a parameter is fixed.
bool UpdateMatrixAdapt()
Tell whether matrix should be updated.
std::vector< int > adapt_block_matrix_indices
Indices for block-matrix adaption.
bool InitFromConfig(const YAML::Node &adapt_manager, const std::string &matrix_name_str, const std::vector< double > *parameters, const std::vector< double > *fixed)
Read initial values from config file.
std::string output_file_name
Name of the file to save the adaptive matrices into.
void SaveAdaptiveToFile(const std::string &outFileName, const std::string &systematicName, const bool is_final=false)
HW: Save adaptive throw matrix to file.
const std::vector< double > * _fCurrVal
Current values of parameters.
int start_adaptive_update
When do we stop update the adaptive matrix.
std::vector< int > adapt_block_sizes
Size of blocks for adaption.
const std::vector< double > * _fFixedPars
Vector of fixed parameters.
bool IndivStepScaleAdapt() const
Tell whether we want reset step scale or not.
void SetFixed(const std::vector< double > *fix)
Set the fixed parameters.
void SetParams(const std::vector< double > *params)
Set the current values of the parameters.
void SetTotalSteps(const int nsteps)
Change Total Number of Steps to new value.
void CreateNewAdaptiveCovariance()
If we don't have a covariance matrix to start from for adaptive tune we need to make one!
bool SkipAdaption() const
Tell if we are Skipping Adaption.
int end_adaptive_update
Steps between changing throw matrix.
int total_steps
Total number of MCMC steps.
void Print() const
Print all class members.
void UpdateAdaptiveCovariance()
Method to update adaptive MCMC .
double CurrVal(const int par_index) const
Get Current value of parameter.
int adaptive_update_step
Steps between changing throw matrix.
bool AdaptionUpdate() const
To be fair not a clue...
void SetAdaptiveBlocks(const std::vector< std::vector< int >> &block_indices)
HW: sets adaptive block matrix.
void SetThrowMatrixFromFile(const std::string &matrix_file_name, const std::string &matrix_name, const std::string &means_name, bool &use_adaptive)
sets throw matrix from a file
TMatrixDSym * adaptive_covariance
Full adaptive covariance matrix.
void IncrementNSteps()
Increase by one number of total steps.
int GetTotalSteps() const
Get Total Number of Steps.
TMatrixDSym * GetAdaptiveCovariance() const
Increase by one number of total steps.
std::string GetOutFileName() const
Get Name of Output File.
int GetNumParams() const
Get the current values of the parameters.
std::vector< double > GetParameterMeans() const
Get the parameter means used in the adaptive handler.