8 #include "Math/DistFunc.h"
44 bool InitFromConfig(
const YAML::Node &adapt_manager,
const std::string &matrix_name_str,
45 const std::vector<std::string> *parameter_names,
46 const std::vector<double> *parameters,
47 const std::vector<double> *fixed,
48 const std::vector<bool> *param_skip_adapt_flags,
49 const TMatrixDSym* throwMatrix,
50 const double initial_scale_);
60 void SaveAdaptiveToFile(
const std::string &outFileName,
const std::string &systematicName,
const bool is_final =
false);
67 const std::string &matrix_name,
68 const std::string &means_name,
101 index =
static_cast<int>(i);
112 std::vector<int> indices;
113 for (
const auto& name : param_names) {
116 indices.push_back(index);
118 MACH3LOG_ERROR(
"Parameter name {} not found in parameter list", name);
146 for (
int i = 0; i < static_cast<int>(
_fFixedPars->size()); i++)
160 return static_cast<int>(
_fCurrVal->size());
174 double CurrVal(
const int par_index)
const;
#define _MaCh3_Safe_Include_Start_
KS: Avoiding warning checking for headers.
#define _MaCh3_Safe_Include_End_
KS: Restore warning checking after including external headers.
Contains information about adaptive covariance matrix .
const std::vector< bool > * _param_skip_adapt_flags
Parameters to skip during adaption.
bool IndivStepScaleAdapt() const
Tell whether we want reset step scale or not.
void SaveAdaptiveToFile(const std::string &outFileName, const std::string &systematicName, const bool is_final=false)
HW: Save adaptive throw matrix to file.
bool SkipAdaption() const
Tell if we are Skipping Adaption.
bool AdaptionUpdate() const
To be fair not a clue...
int adaptive_save_n_iterations
int GetNumParams() const
Get the current values of the parameters.
int GetParIndex(const std::string &name) const
Get the index of the parameter given its name.
void CheckMatrixValidityForAdaption(const TMatrixDSym *covMatrix) const
Check if there are structures in matrix that could result in failure of adaption fits....
const std::vector< std::string > * _ParamNames
Parameter names.
double GetAdaptionScale()
Get the current adaption scale.
std::vector< int > GetParIndicesFromNames(const std::vector< std::string > ¶m_names) const
Convert vector of parameter names to indices.
void SetFixed(const std::vector< double > *fix)
Set the fixed parameters.
void IncrementNSteps()
Increase by one number of total steps.
int GetTotalSteps() const
Get Total Number of Steps.
bool UpdateMatrixAdapt()
Tell whether matrix should be updated.
int end_adaptive_update
Steps between changing throw matrix.
const TMatrixDSym * initial_throw_matrix
Initial throw matrix.
std::vector< double > GetParameterMeans() const
Get the parameter means used in the adaptive handler.
int total_steps
Total number of MCMC steps.
const std::vector< double > * _fFixedPars
Vector of fixed parameters.
void UpdateAdaptiveCovariance()
Method to update adaptive MCMC .
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
double target_acceptance
Target acceptance rate for Robbins Monro.
int adaptive_update_step
Steps between changing throw matrix.
void UpdateRobbinsMonroScale()
Update the scale factor for Robbins-Monro adaption.
void SetParams(const std::vector< double > *params)
Set the current values of the parameters.
void CreateNewAdaptiveCovariance()
If we don't have a covariance matrix to start from for adaptive tune we need to make one!
bool IsFixed(const int ipar) const
Check if a parameter is fixed.
bool InitFromConfig(const YAML::Node &adapt_manager, const std::string &matrix_name_str, const std::vector< std::string > *parameter_names, const std::vector< double > *parameters, const std::vector< double > *fixed, const std::vector< bool > *param_skip_adapt_flags, const TMatrixDSym *throwMatrix, const double initial_scale_)
Read initial values from config file.
AdaptiveMCMCHandler()
Constructor.
int start_adaptive_update
When do we stop update the adaptive matrix.
TMatrixDSym * GetAdaptiveCovariance() const
Increase by one number of total steps.
TMatrixDSym * adaptive_covariance
Full adaptive covariance matrix.
double initial_scale
Initial scaling factor.
double adaption_scale
Scaling factor.
bool GetUseRobbinsMonro() const
Use Robbins-Monro approach?
std::string output_file_name
Name of the file to save the adaptive matrices into.
double CurrVal(const int par_index) const
Get Current value of parameter.
int acceptance_rate_batch_size
Acceptance rate in the current batch.
void CalculateRobbinsMonroStepLength()
Calculate the constant step length for Robbins-Monro adaption.
std::vector< int > adapt_block_sizes
Size of blocks for adaption.
std::string GetOutFileName() const
Get Name of Output File.
void Print() const
Print all class members.
std::vector< double > par_means
Mean values for all parameters.
int total_rm_restarts
Total number of restarts ALLOWED for Robbins Monro.
bool initial_throw_matrix_saved
Flag to check if initial throw matrix has been saved.
void SetAdaptiveBlocks(const std::vector< std::vector< int >> &block_indices)
HW: sets adaptive block matrix.
bool use_robbins_monro
Use Robbins Monro https://arxiv.org/pdf/1006.3690.
std::vector< int > adapt_block_matrix_indices
Indices for block-matrix adaption.
bool prev_step_accepted
Need to keep track of whether previous step was accepted for RM.
double c_robbins_monro
Constant "step scaling" factor for Robbins-Monro.
int n_rm_restarts
Number of restarts for Robbins Monro (so far)
const std::vector< double > * _fCurrVal
Current values of parameters.
void IncrementAcceptedSteps()
void SetTotalSteps(const int nsteps)
Change Total Number of Steps to new value.
int GetNFixed() const
Get the number of fixed parameters.
virtual ~AdaptiveMCMCHandler()
Destructor.
Custom exception class used throughout MaCh3.
constexpr static const int _BAD_INT_
Default value used for int initialisation.