![]() |
MaCh3
2.5.0
Reference Guide
|
Contains information about adaptive covariance matrix [15] [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 [15]. 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 [15] [10].
Adaptation can be performed in two ways:
\[ \frac{2.38}{\sqrt{\text{num\_params}}} \]
Definition at line 25 of file AdaptiveMCMCHandler.h.
| AdaptiveMCMCHandler::AdaptiveMCMCHandler | ( | ) |
Constructor.
Robbins-Monro adaption
Definition at line 4 of file AdaptiveMCMCHandler.cpp.
|
virtual |
| bool 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 514 of file AdaptiveMCMCHandler.cpp.
| void 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 448 of file AdaptiveMCMCHandler.cpp.
| void AdaptiveMCMCHandler::CreateNewAdaptiveCovariance | ( | ) |
If we don't have a covariance matrix to start from for adaptive tune we need to make one!
Definition at line 142 of file AdaptiveMCMCHandler.cpp.
| double 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 506 of file AdaptiveMCMCHandler.cpp.
|
inline |
Get the current adaption scale.
Definition at line 222 of file AdaptiveMCMCHandler.h.
|
inline |
Increase by one number of total steps.
Definition at line 202 of file AdaptiveMCMCHandler.h.
|
inline |
Get the number of fixed parameters.
Definition at line 139 of file AdaptiveMCMCHandler.h.
|
inline |
Get the current values of the parameters.
Definition at line 158 of file AdaptiveMCMCHandler.h.
|
inline |
Get Name of Output File.
Definition at line 216 of file AdaptiveMCMCHandler.h.
|
inline |
Get the parameter means used in the adaptive handler.
Definition at line 209 of file AdaptiveMCMCHandler.h.
|
inline |
Get the index of the parameter given its name.
| name | Name of the parameter |
Definition at line 96 of file AdaptiveMCMCHandler.h.
|
inline |
Convert vector of parameter names to indices.
| param_names | Vector of parameter names |
Definition at line 111 of file AdaptiveMCMCHandler.h.
|
inline |
Get Total Number of Steps.
Definition at line 178 of file AdaptiveMCMCHandler.h.
|
inline |
Use Robbins-Monro approach?
Definition at line 228 of file AdaptiveMCMCHandler.h.
|
inline |
Definition at line 195 of file AdaptiveMCMCHandler.h.
|
inline |
Increase by one number of total steps.
Definition at line 190 of file AdaptiveMCMCHandler.h.
| bool AdaptiveMCMCHandler::IndivStepScaleAdapt | ( | ) | const |
Tell whether we want reset step scale or not.
Definition at line 399 of file AdaptiveMCMCHandler.cpp.
| bool 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 31 of file AdaptiveMCMCHandler.cpp.
|
inline |
| void AdaptiveMCMCHandler::Print | ( | ) | const |
Print all class members.
Definition at line 433 of file AdaptiveMCMCHandler.cpp.
| void 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 192 of file AdaptiveMCMCHandler.cpp.
| void 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 150 of file AdaptiveMCMCHandler.cpp.
|
inline |
Set the fixed parameters.
Definition at line 132 of file AdaptiveMCMCHandler.h.
|
inline |
Set the current values of the parameters.
Definition at line 126 of file AdaptiveMCMCHandler.h.
| void 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 278 of file AdaptiveMCMCHandler.cpp.
|
inline |
Change Total Number of Steps to new value.
Definition at line 184 of file AdaptiveMCMCHandler.h.
| bool AdaptiveMCMCHandler::SkipAdaption | ( | ) | const |
| void AdaptiveMCMCHandler::UpdateAdaptiveCovariance | ( | ) |
Method to update adaptive MCMC [15].
| _fCurrVal | Value of each parameter necessary for updating throw matrix |
Definition at line 330 of file AdaptiveMCMCHandler.cpp.
| bool AdaptiveMCMCHandler::UpdateMatrixAdapt | ( | ) |
Tell whether matrix should be updated.
Definition at line 406 of file AdaptiveMCMCHandler.cpp.
| void 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 540 of file AdaptiveMCMCHandler.cpp.
|
private |
Current values of parameters.
Definition at line 286 of file AdaptiveMCMCHandler.h.
|
private |
Vector of fixed parameters.
Definition at line 283 of file AdaptiveMCMCHandler.h.
|
private |
Parameters to skip during adaption.
Definition at line 313 of file AdaptiveMCMCHandler.h.
|
private |
Parameter names.
Definition at line 289 of file AdaptiveMCMCHandler.h.
|
private |
Acceptance rate in the current batch.
Definition at line 292 of file AdaptiveMCMCHandler.h.
|
private |
Indices for block-matrix adaption.
Definition at line 261 of file AdaptiveMCMCHandler.h.
|
private |
Size of blocks for adaption.
Definition at line 264 of file AdaptiveMCMCHandler.h.
|
private |
Scaling factor.
Definition at line 277 of file AdaptiveMCMCHandler.h.
|
private |
Full adaptive covariance matrix.
Definition at line 271 of file AdaptiveMCMCHandler.h.
|
private |
If you don't want to save every adaption then you can specify this here
Definition at line 255 of file AdaptiveMCMCHandler.h.
|
private |
Steps between changing throw matrix.
Definition at line 251 of file AdaptiveMCMCHandler.h.
|
private |
Constant "step scaling" factor for Robbins-Monro.
Definition at line 301 of file AdaptiveMCMCHandler.h.
|
private |
Steps between changing throw matrix.
Definition at line 248 of file AdaptiveMCMCHandler.h.
|
private |
Initial scaling factor.
Definition at line 280 of file AdaptiveMCMCHandler.h.
|
private |
Initial throw matrix.
Definition at line 316 of file AdaptiveMCMCHandler.h.
|
private |
Flag to check if initial throw matrix has been saved.
Definition at line 319 of file AdaptiveMCMCHandler.h.
|
private |
Number of restarts for Robbins Monro (so far)
Definition at line 304 of file AdaptiveMCMCHandler.h.
|
private |
Name of the file to save the adaptive matrices into.
Definition at line 258 of file AdaptiveMCMCHandler.h.
|
private |
Mean values for all parameters.
Definition at line 268 of file AdaptiveMCMCHandler.h.
|
private |
Need to keep track of whether previous step was accepted for RM.
Definition at line 310 of file AdaptiveMCMCHandler.h.
|
private |
Meta variables related to adaption run time When do we start throwing
Definition at line 242 of file AdaptiveMCMCHandler.h.
|
private |
When do we stop update the adaptive matrix.
Definition at line 245 of file AdaptiveMCMCHandler.h.
|
private |
Target acceptance rate for Robbins Monro.
Definition at line 298 of file AdaptiveMCMCHandler.h.
|
private |
Total number of restarts ALLOWED for Robbins Monro.
Definition at line 307 of file AdaptiveMCMCHandler.h.
|
private |
Total number of MCMC steps.
Definition at line 274 of file AdaptiveMCMCHandler.h.
|
private |
Use Robbins Monro https://arxiv.org/pdf/1006.3690.
Definition at line 295 of file AdaptiveMCMCHandler.h.