![]() |
MaCh3
2.4.2
Reference Guide
|
Contains information about adaptive covariance matrix [13] [10]. More...
#include <Parameters/AdaptiveMCMCHandler.h>
Public Member Functions | |
| AdaptiveMCMCHandler () | |
| Constructor. More... | |
| virtual | ~AdaptiveMCMCHandler () |
| Destructor. More... | |
| void | Print () const |
| Print all class members. More... | |
| 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. More... | |
| void | CreateNewAdaptiveCovariance () |
| If we don't have a covariance matrix to start from for adaptive tune we need to make one! More... | |
| void | SetAdaptiveBlocks (const std::vector< std::vector< int >> &block_indices) |
| HW: sets adaptive block matrix. More... | |
| void | SaveAdaptiveToFile (const std::string &outFileName, const std::string &systematicName, const bool is_final=false) |
| HW: Save adaptive throw matrix to file. More... | |
| 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 More... | |
| void | CheckMatrixValidityForAdaption (const TMatrixDSym *covMatrix) const |
| Check if there are structures in matrix that could result in failure of adaption fits. this mostly cover cases of highly correlated block which seem to results in adaption failure. More... | |
| void | UpdateAdaptiveCovariance () |
| Method to update adaptive MCMC [13]. More... | |
| bool | IndivStepScaleAdapt () const |
| Tell whether we want reset step scale or not. More... | |
| bool | UpdateMatrixAdapt () |
| Tell whether matrix should be updated. More... | |
| bool | AdaptionUpdate () const |
| To be fair not a clue... More... | |
| bool | SkipAdaption () const |
| Tell if we are Skipping Adaption. More... | |
| int | GetParIndex (const std::string &name) const |
| Get the index of the parameter given its name. More... | |
| std::vector< int > | GetParIndicesFromNames (const std::vector< std::string > ¶m_names) const |
| Convert vector of parameter names to indices. More... | |
| void | SetParams (const std::vector< double > *params) |
| Set the current values of the parameters. More... | |
| void | SetFixed (const std::vector< double > *fix) |
| Set the fixed parameters. More... | |
| int | GetNFixed () const |
| Get the number of fixed parameters. More... | |
| int | GetNumParams () const |
| Get the current values of the parameters. More... | |
| bool | IsFixed (const int ipar) const |
| Check if a parameter is fixed. More... | |
| double | CurrVal (const int par_index) const |
| Get Current value of parameter. More... | |
| int | GetTotalSteps () const |
| Get Total Number of Steps. More... | |
| void | SetTotalSteps (const int nsteps) |
| Change Total Number of Steps to new value. More... | |
| void | IncrementNSteps () |
| Increase by one number of total steps. More... | |
| void | IncrementAcceptedSteps () |
| TMatrixDSym * | GetAdaptiveCovariance () const |
| Increase by one number of total steps. More... | |
| std::vector< double > | GetParameterMeans () const |
| Get the parameter means used in the adaptive handler. More... | |
| std::string | GetOutFileName () const |
| Get Name of Output File. More... | |
| double | GetAdaptionScale () |
| Get the current adaption scale. More... | |
| bool | GetUseRobbinsMonro () const |
| Use Robbins-Monro approach? More... | |
| void | UpdateRobbinsMonroScale () |
| Update the scale factor for Robbins-Monro adaption. More... | |
Private Member Functions | |
| void | CalculateRobbinsMonroStepLength () |
| Calculate the constant step length for Robbins-Monro adaption. More... | |
Private Attributes | |
| int | start_adaptive_throw |
| int | start_adaptive_update |
| When do we stop update the adaptive matrix. More... | |
| int | end_adaptive_update |
| Steps between changing throw matrix. More... | |
| int | adaptive_update_step |
| Steps between changing throw matrix. More... | |
| int | adaptive_save_n_iterations |
| std::string | output_file_name |
| Name of the file to save the adaptive matrices into. More... | |
| std::vector< int > | adapt_block_matrix_indices |
| Indices for block-matrix adaption. More... | |
| std::vector< int > | adapt_block_sizes |
| Size of blocks for adaption. More... | |
| std::vector< double > | par_means |
| Mean values for all parameters. More... | |
| TMatrixDSym * | adaptive_covariance |
| Full adaptive covariance matrix. More... | |
| int | total_steps |
| Total number of MCMC steps. More... | |
| double | adaption_scale |
| Scaling factor. More... | |
| double | initial_scale |
| Initial scaling factor. More... | |
| const std::vector< double > * | _fFixedPars |
| Vector of fixed parameters. More... | |
| const std::vector< double > * | _fCurrVal |
| Current values of parameters. More... | |
| const std::vector< std::string > * | _ParamNames |
| Parameter names. More... | |
| int | acceptance_rate_batch_size |
| Acceptance rate in the current batch. More... | |
| bool | use_robbins_monro |
| Use Robbins Monro https://arxiv.org/pdf/1006.3690. More... | |
| double | target_acceptance |
| Target acceptance rate for Robbins Monro. More... | |
| double | c_robbins_monro |
| Constant "step scaling" factor for Robbins-Monro. More... | |
| int | n_rm_restarts |
| Number of restarts for Robbins Monro (so far) More... | |
| int | total_rm_restarts |
| Total number of restarts ALLOWED for Robbins Monro. More... | |
| bool | prev_step_accepted |
| Need to keep track of whether previous step was accepted for RM. More... | |
| const std::vector< bool > * | _param_skip_adapt_flags |
| Parameters to skip during adaption. More... | |
| const TMatrixDSym * | initial_throw_matrix |
| Initial throw matrix. More... | |
| bool | initial_throw_matrix_saved = false |
| Flag to check if initial throw matrix has been saved. More... | |
Contains information about adaptive covariance matrix [13] [10].
Adaptation can be performed in two ways:
\[ \frac{2.38}{\sqrt{\text{num\_params}}} \]
Definition at line 26 of file AdaptiveMCMCHandler.h.
| adaptive_mcmc::AdaptiveMCMCHandler::AdaptiveMCMCHandler | ( | ) |
Constructor.
Robbins-Monro adaption
Definition at line 6 of file AdaptiveMCMCHandler.cpp.
|
virtual |
| bool adaptive_mcmc::AdaptiveMCMCHandler::AdaptionUpdate | ( | ) | const |
|
private |
Calculate the constant step length for Robbins-Monro adaption.
Firstly we need to calculate the alpha value, this is in some sense "optimal"
Now we can calculate the scale factor
Definition at line 516 of file AdaptiveMCMCHandler.cpp.
| void adaptive_mcmc::AdaptiveMCMCHandler::CheckMatrixValidityForAdaption | ( | const TMatrixDSym * | covMatrix | ) | const |
Check if there are structures in matrix that could result in failure of adaption fits. this mostly cover cases of highly correlated block which seem to results in adaption failure.
| covMatrix | covariance matrix which we convert into correlation matrix |
Definition at line 450 of file AdaptiveMCMCHandler.cpp.
| void adaptive_mcmc::AdaptiveMCMCHandler::CreateNewAdaptiveCovariance | ( | ) |
If we don't have a covariance matrix to start from for adaptive tune we need to make one!
Definition at line 144 of file AdaptiveMCMCHandler.cpp.
| double adaptive_mcmc::AdaptiveMCMCHandler::CurrVal | ( | const int | par_index | ) | const |
Get Current value of parameter.
HW Implemented as its own method to allow for different behaviour in the future
Definition at line 508 of file AdaptiveMCMCHandler.cpp.
|
inline |
Get the current adaption scale.
Definition at line 223 of file AdaptiveMCMCHandler.h.
|
inline |
Increase by one number of total steps.
Definition at line 203 of file AdaptiveMCMCHandler.h.
|
inline |
Get the number of fixed parameters.
Definition at line 140 of file AdaptiveMCMCHandler.h.
|
inline |
Get the current values of the parameters.
Definition at line 159 of file AdaptiveMCMCHandler.h.
|
inline |
Get Name of Output File.
Definition at line 217 of file AdaptiveMCMCHandler.h.
|
inline |
Get the parameter means used in the adaptive handler.
Definition at line 210 of file AdaptiveMCMCHandler.h.
|
inline |
Get the index of the parameter given its name.
| name | Name of the parameter |
Definition at line 97 of file AdaptiveMCMCHandler.h.
|
inline |
Convert vector of parameter names to indices.
| param_names | Vector of parameter names |
Definition at line 112 of file AdaptiveMCMCHandler.h.
|
inline |
Get Total Number of Steps.
Definition at line 179 of file AdaptiveMCMCHandler.h.
|
inline |
Use Robbins-Monro approach?
Definition at line 229 of file AdaptiveMCMCHandler.h.
|
inline |
Definition at line 196 of file AdaptiveMCMCHandler.h.
|
inline |
Increase by one number of total steps.
Definition at line 191 of file AdaptiveMCMCHandler.h.
| bool adaptive_mcmc::AdaptiveMCMCHandler::IndivStepScaleAdapt | ( | ) | const |
Tell whether we want reset step scale or not.
Definition at line 401 of file AdaptiveMCMCHandler.cpp.
| bool adaptive_mcmc::AdaptiveMCMCHandler::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.
| adapt_manager | YAML node containing the configuration (AdaptionOptions). |
| matrix_name_str | Name of the covariance matrix block to configure. |
| parameters | Pointer to a vector of parameter values (nominal values). |
| fixed | Pointer to a vector of fixed parameter values. |
HW: This is technically wrong, should be across all systematics but will be addressed in a later PR
Definition at line 33 of file AdaptiveMCMCHandler.cpp.
|
inline |
| void adaptive_mcmc::AdaptiveMCMCHandler::Print | ( | ) | const |
Print all class members.
Definition at line 435 of file AdaptiveMCMCHandler.cpp.
| void adaptive_mcmc::AdaptiveMCMCHandler::SaveAdaptiveToFile | ( | const std::string & | outFileName, |
| const std::string & | systematicName, | ||
| const bool | is_final = false |
||
| ) |
HW: Save adaptive throw matrix to file.
Definition at line 194 of file AdaptiveMCMCHandler.cpp.
| void adaptive_mcmc::AdaptiveMCMCHandler::SetAdaptiveBlocks | ( | const std::vector< std::vector< int >> & | block_indices | ) |
HW: sets adaptive block matrix.
| block_indices | Values for sub-matrix blocks |
Definition at line 152 of file AdaptiveMCMCHandler.cpp.
|
inline |
Set the fixed parameters.
Definition at line 133 of file AdaptiveMCMCHandler.h.
|
inline |
Set the current values of the parameters.
Definition at line 127 of file AdaptiveMCMCHandler.h.
| void adaptive_mcmc::AdaptiveMCMCHandler::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
| matrix_file_name | name of file matrix lives in |
| matrix_name | name of matrix in file |
| means_name | name of means vec in file |
Definition at line 280 of file AdaptiveMCMCHandler.cpp.
|
inline |
Change Total Number of Steps to new value.
Definition at line 185 of file AdaptiveMCMCHandler.h.
| bool adaptive_mcmc::AdaptiveMCMCHandler::SkipAdaption | ( | ) | const |
| void adaptive_mcmc::AdaptiveMCMCHandler::UpdateAdaptiveCovariance | ( | ) |
Method to update adaptive MCMC [13].
| _fCurrVal | Value of each parameter necessary for updating throw matrix |
Definition at line 332 of file AdaptiveMCMCHandler.cpp.
| bool adaptive_mcmc::AdaptiveMCMCHandler::UpdateMatrixAdapt | ( | ) |
Tell whether matrix should be updated.
Definition at line 408 of file AdaptiveMCMCHandler.cpp.
| void adaptive_mcmc::AdaptiveMCMCHandler::UpdateRobbinsMonroScale | ( | ) |
Update the scale factor for Robbins-Monro adaption.
This allows to move towards a STABLE number of steps in the batch
Update the scale factor for Robbins-Monro adaption [200 is arbitrary for early stability but motivated by paper]
Now we either increase or decrease the scale
Definition at line 542 of file AdaptiveMCMCHandler.cpp.
|
private |
Current values of parameters.
Definition at line 287 of file AdaptiveMCMCHandler.h.
|
private |
Vector of fixed parameters.
Definition at line 284 of file AdaptiveMCMCHandler.h.
|
private |
Parameters to skip during adaption.
Definition at line 314 of file AdaptiveMCMCHandler.h.
|
private |
Parameter names.
Definition at line 290 of file AdaptiveMCMCHandler.h.
|
private |
Acceptance rate in the current batch.
Definition at line 293 of file AdaptiveMCMCHandler.h.
|
private |
Indices for block-matrix adaption.
Definition at line 262 of file AdaptiveMCMCHandler.h.
|
private |
Size of blocks for adaption.
Definition at line 265 of file AdaptiveMCMCHandler.h.
|
private |
Scaling factor.
Definition at line 278 of file AdaptiveMCMCHandler.h.
|
private |
Full adaptive covariance matrix.
Definition at line 272 of file AdaptiveMCMCHandler.h.
|
private |
If you don't want to save every adaption then you can specify this here
Definition at line 256 of file AdaptiveMCMCHandler.h.
|
private |
Steps between changing throw matrix.
Definition at line 252 of file AdaptiveMCMCHandler.h.
|
private |
Constant "step scaling" factor for Robbins-Monro.
Definition at line 302 of file AdaptiveMCMCHandler.h.
|
private |
Steps between changing throw matrix.
Definition at line 249 of file AdaptiveMCMCHandler.h.
|
private |
Initial scaling factor.
Definition at line 281 of file AdaptiveMCMCHandler.h.
|
private |
Initial throw matrix.
Definition at line 317 of file AdaptiveMCMCHandler.h.
|
private |
Flag to check if initial throw matrix has been saved.
Definition at line 320 of file AdaptiveMCMCHandler.h.
|
private |
Number of restarts for Robbins Monro (so far)
Definition at line 305 of file AdaptiveMCMCHandler.h.
|
private |
Name of the file to save the adaptive matrices into.
Definition at line 259 of file AdaptiveMCMCHandler.h.
|
private |
Mean values for all parameters.
Definition at line 269 of file AdaptiveMCMCHandler.h.
|
private |
Need to keep track of whether previous step was accepted for RM.
Definition at line 311 of file AdaptiveMCMCHandler.h.
|
private |
Meta variables related to adaption run time When do we start throwing
Definition at line 243 of file AdaptiveMCMCHandler.h.
|
private |
When do we stop update the adaptive matrix.
Definition at line 246 of file AdaptiveMCMCHandler.h.
|
private |
Target acceptance rate for Robbins Monro.
Definition at line 299 of file AdaptiveMCMCHandler.h.
|
private |
Total number of restarts ALLOWED for Robbins Monro.
Definition at line 308 of file AdaptiveMCMCHandler.h.
|
private |
Total number of MCMC steps.
Definition at line 275 of file AdaptiveMCMCHandler.h.
|
private |
Use Robbins Monro https://arxiv.org/pdf/1006.3690.
Definition at line 296 of file AdaptiveMCMCHandler.h.