8 #include "Math/DistFunc.h"
45 bool InitFromConfig(
const YAML::Node &adapt_manager,
const std::string &matrix_name_str,
46 const std::vector<std::string> *parameter_names,
47 const std::vector<double> *parameters,
48 const std::vector<double> *fixed,
49 const std::vector<bool> *param_skip_adapt_flags,
50 const TMatrixDSym* throwMatrix,
51 const double initial_scale_);
61 void SaveAdaptiveToFile(
const std::string &outFileName,
const std::string &systematicName,
const bool is_final =
false);
68 const std::string &matrix_name,
69 const std::string &means_name,
102 index =
static_cast<int>(i);
113 std::vector<int> indices;
114 for (
const auto& name : param_names) {
117 indices.push_back(index);
119 MACH3LOG_ERROR(
"Parameter name {} not found in parameter list", name);
147 for (
int i = 0; i < static_cast<int>(
_fFixedPars->size()); i++)
161 return static_cast<int>(
_fCurrVal->size());
175 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.
Custom exception class used throughout MaCh3.
Contains information about adaptive covariance matrix .
std::vector< double > par_means
Mean values for all parameters.
const std::vector< std::string > * _ParamNames
Parameter names.
bool IsFixed(const int ipar) const
Check if a parameter is fixed.
int GetNFixed() const
Get the number of fixed parameters.
void IncrementAcceptedSteps()
double GetAdaptionScale()
Get the current adaption scale.
bool UpdateMatrixAdapt()
Tell whether matrix should be updated.
std::vector< int > adapt_block_matrix_indices
Indices for block-matrix adaption.
int GetTotalSteps() const
Get Total Number of Steps.
std::string output_file_name
Name of the file to save the adaptive matrices into.
double adaption_scale
Scaling factor.
void CheckMatrixValidityForAdaption(const TMatrixDSym *covMatrix) const
Check if there are structures in matrix that could result in failure of adaption fits....
std::vector< int > GetParIndicesFromNames(const std::vector< std::string > ¶m_names) const
Convert vector of parameter names to indices.
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.
double target_acceptance
Target acceptance rate for Robbins Monro.
int acceptance_rate_batch_size
Acceptance rate in the current batch.
std::vector< int > adapt_block_sizes
Size of blocks for adaption.
double initial_scale
Initial scaling factor.
virtual ~AdaptiveMCMCHandler()
Destructor.
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.
int adaptive_save_n_iterations
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 CalculateRobbinsMonroStepLength()
Calculate the constant step length for Robbins-Monro adaption.
void SetTotalSteps(const int nsteps)
Change Total Number of Steps to new value.
bool GetUseRobbinsMonro() const
Use Robbins-Monro approach?
AdaptiveMCMCHandler()
Constructor.
void CreateNewAdaptiveCovariance()
If we don't have a covariance matrix to start from for adaptive tune we need to make one!
TMatrixDSym * GetAdaptiveCovariance() const
Increase by one number of total steps.
bool SkipAdaption() const
Tell if we are Skipping Adaption.
const std::vector< bool > * _param_skip_adapt_flags
Parameters to skip during adaption.
int GetParIndex(const std::string &name) const
Get the index of the parameter given its name.
std::string GetOutFileName() const
Get Name of Output File.
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...
int n_rm_restarts
Number of restarts for Robbins Monro (so far)
double c_robbins_monro
Constant "step scaling" factor for Robbins-Monro.
bool use_robbins_monro
Use Robbins Monro https://arxiv.org/pdf/1006.3690.
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
int GetNumParams() const
Get the current values of the parameters.
std::vector< double > GetParameterMeans() const
Get the parameter means used in the adaptive handler.
void UpdateRobbinsMonroScale()
Update the scale factor for Robbins-Monro adaption.
bool prev_step_accepted
Need to keep track of whether previous step was accepted for RM.
bool initial_throw_matrix_saved
Flag to check if initial throw matrix has been saved.
int total_rm_restarts
Total number of restarts ALLOWED for Robbins Monro.
const TMatrixDSym * initial_throw_matrix
Initial throw matrix.
TMatrixDSym * adaptive_covariance
Full adaptive covariance matrix.
void IncrementNSteps()
Increase by one number of total steps.
constexpr static const int _BAD_INT_
Default value used for int initialisation.