MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
AdaptiveMCMCHandler.h
Go to the documentation of this file.
1#pragma once
2
3// MaCh3 Includes
4#include "Manager/Manager.h"
6
7namespace adaptive_mcmc{
8
14 public:
17
19 virtual ~AdaptiveMCMCHandler();
20
22 void Print();
23
26 bool InitFromConfig(const YAML::Node& adapt_manager, const std::string& matrix_name_str,
27 const std::vector<double>* parameters, const std::vector<double>* fixed);
28
31
34 void SetAdaptiveBlocks(const std::vector<std::vector<int>>& block_indices);
35
37 void SaveAdaptiveToFile(const std::string& outFileName, const std::string& systematicName, const bool is_final=false);
38
43 void SetThrowMatrixFromFile(const std::string& matrix_file_name,
44 const std::string& matrix_name,
45 const std::string& means_name,
46 bool& use_adaptive);
47
52
55
57 bool UpdateMatrixAdapt();
58
60 bool AdaptionUpdate();
61
63 bool SkipAdaption();
64
66 void SetParams(const std::vector<double>* params){
67 _fCurrVal = params;
68 }
69
71 void SetFixed(const std::vector<double>* fix){
72 _fFixedPars = fix;
73 }
74
76 int GetNumParams() const {
77 return static_cast<int>(_fCurrVal->size());
78 }
79
81 bool IsFixed(const int ipar) const {
82 if(!_fFixedPars){
83 return false;
84 }
85 return ((*_fFixedPars)[ipar] < 0);
86 }
87
89 double CurrVal(const int par_index);
90
92 int GetTotalSteps() const {
93 return total_steps;
94 }
95
97 void SetTotalSteps(const int nsteps) {
98 total_steps = nsteps;
99 }
100
103 total_steps++;
104 }
105
107 TMatrixDSym* GetAdaptiveCovariance() const {
108 return adaptive_covariance;
109 }
110
113 std::vector<double> GetParameterMeans() const {
114 return par_means;
115 }
116
119 std::string GetOutFileName() const {
120 return output_file_name;
121 }
122
123 private:
127
130
133
136
140
142 std::string output_file_name;
143
146
148 std::vector<int> adapt_block_sizes;
149
150 // Variables directedly linked to adaption
152 std::vector<double> par_means;
153
156
159
162
164 const std::vector<double>* _fFixedPars;
165
167 const std::vector<double>* _fCurrVal;
168};
169
170} // 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.
double CurrVal(const int par_index)
Get Current value of parameter.
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.
int GetTotalSteps() const
Get Total Number of Steps.
std::string output_file_name
Name of the file to save the adaptive matrices into.
bool AdaptionUpdate()
To be fair not a clue...
void SaveAdaptiveToFile(const std::string &outFileName, const std::string &systematicName, const bool is_final=false)
HW: Save adaptive throw matrix to file.
void SetAdaptiveBlocks(const std::vector< std::vector< int > > &block_indices)
HW: sets adaptive block matrix.
const std::vector< double > * _fCurrVal
Current values of parameters.
void Print()
Print all class members.
int start_adaptive_update
When do we stop update the adaptive matrix.
std::vector< int > adapt_block_sizes
Size of blocks for adaption.
bool IndivStepScaleAdapt()
Tell whether we want reset step scale or not.
const std::vector< double > * _fFixedPars
Vector of fixed parameters.
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!
int end_adaptive_update
Steps between changing throw matrix.
int total_steps
Total number of MCMC steps.
void UpdateAdaptiveCovariance()
Method to update adaptive MCMC .
int adaptive_update_step
Steps between changing throw matrix.
TMatrixDSym * GetAdaptiveCovariance() const
Increase by one number of total steps.
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
int GetNumParams() const
Get the current values of the parameters.
bool SkipAdaption()
Tell if we are Skipping Adaption.
TMatrixDSym * adaptive_covariance
Full adaptive covariance matrix.
void IncrementNSteps()
Increase by one number of total steps.
std::string GetOutFileName() const
Get Name of Output File.
std::vector< double > GetParameterMeans() const
Get the parameter means used in the adaptive handler.