22#include "Eigen/Eigenvalues"
47 std::vector<double>* fProp_Val);
55 void ConstructPCA(TMatrixDSym * CovMatrix,
const int firstPCAd,
const int lastPCAd,
56 const double eigen_thresh,
const int _fNumPar);
64 void ThrowParameters(
const std::vector<std::unique_ptr<TRandom3>>& random_number,
65 double** throwMatrixCholDecomp,
68 const std::vector<double>& fPreFitValue,
69 const std::vector<double>& fLowBound,
70 const std::vector<double>& fUpBound,
77 const
double GlobalStepScale,
90 void SetBranches(TTree &tree,
bool SaveProposal, const std::vector<std::
string>& Names);
103 MACH3LOG_ERROR(
"Parameter arrays of incompatible size! Not changing parameters! has size {} but was expecting {}", pars.size(),
NumParPCA);
106 int parsSize = int(pars.size());
107 for (
int i = 0; i < parsSize; i++) {
119 else {
return false; }
195 void DebugPCA(
const double sum, TMatrixD temp, TMatrixDSym submat,
int NumPar);
#define _noexcept_
KS: noexcept can help with performance but is terrible for debugging, this is meant to help easy way ...
#define _restrict_
KS: Using restrict limits the effects of pointer aliasing, aiding optimizations. While reading I foun...
Custom exception class for MaCh3 errors.
Class responsible for handling Principal Component Analysis (PCA) of covariance matrix.
std::vector< int > isDecomposedPCA
If param is decomposed this will return -1, if not this will return enumerator to param in normal bas...
TMatrixD TransferMat
Matrix used to converting from PCA base to normal base.
std::vector< double > eigen_values_master
Eigen values which have dimension equal to _fNumParPCA, and can be used in CorrelateSteps.
TMatrixD eigen_vectors
Eigen vectors only of params which are being decomposed.
TVectorD _fParPropPCA
CW: Current parameter value in PCA base.
void ThrowParProp(const double mag, const double *_restrict_ randParams)
Throw the proposed parameter by mag sigma.
void ThrowParameters(const std::vector< std::unique_ptr< TRandom3 > > &random_number, double **throwMatrixCholDecomp, double *randParams, double *corr_throw, const std::vector< double > &fPreFitValue, const std::vector< double > &fLowBound, const std::vector< double > &fUpBound, int _fNumPar)
Throw the parameters according to the covariance matrix. This shouldn't be used in MCMC code ase it c...
int NumParPCA
Number of parameters in PCA base.
int GetNumberPCAedParameters() const
Retrieve number of parameters in PCA base.
std::vector< double > * _pCurrVal
Pointer to current value of the parameter.
TMatrixD TransferMatT
Matrix used to converting from normal base to PCA base.
void AcceptStep() _noexcept_
Accepted this step.
void CorrelateSteps(const std::vector< double > &IndivStepScale, const double GlobalStepScale, const double *_restrict_ randParams, const double *_restrict_ corr_throw) _noexcept_
Use Cholesky throw matrix for better step proposal.
void SetInitialParameters(std::vector< double > &IndStepScale)
KS: Transfer the starting parameters to the PCA basis, you don't want to start with zero....
void TransferToPCA()
Transfer param values from normal base to PCA base.
virtual ~PCAHandler()
Destructor.
void SetupPointers(std::vector< double > *fCurr_Val, std::vector< double > *fProp_Val)
KS: Setup pointers to current and proposed parameter value which we need to convert them to PCA base ...
std::vector< double > * _pPropVal
Pointer to proposed value of the parameter.
TVectorD eigen_values
Eigen value only of particles which are being decomposed.
void TransferToParam()
Transfer param values from PCA base to normal base.
int LastPCAdpar
Index of the last param that is being decomposed.
int nKeptPCApars
Total number that remained after applying PCA Threshold.
std::vector< double > _fErrorPCA
Tells if parameter is fixed in PCA base or not.
void Print()
KS: Print info about PCA parameters.
std::vector< double > _fPreFitValuePCA
Prefit value for PCA params.
void ThrowParCurr(const double mag, const double *_restrict_ randParams)
Helper function to throw the current parameter by mag sigma.
TVectorD _fParCurrPCA
CW: Proposed parameter value in PCA base.
void SanitisePCA(TMatrixDSym *CovMatrix)
@biref KS: Make sure decomposed matrix isn't correlated with undecomposed
void ConstructPCA(TMatrixDSym *CovMatrix, const int firstPCAd, const int lastPCAd, const double eigen_thresh, const int _fNumPar)
CW: Calculate eigen values, prepare transition matrices and remove param based on defined threshold.
int FirstPCAdpar
Index of the first param that is being decomposed.
double eigen_threshold
CW: Threshold based on which we remove parameters in eigen base.
const TMatrixD GetTransferMatrix() const
Get transfer matrix allowing to go from PCA base to normal base.
double GetParCurrPCA(const int i) const
Get current parameter value using PCA.
const std::vector< double > GetEigenValuesMaster() const
Get eigen value of only decomposed parameters, if you want for all parameters use GetEigenValues.
bool IsParameterFixedPCA(const int i) const
Is parameter fixed in PCA base or not.
double GetParPropPCA(const int i) const
Get current parameter value using PCA.
double GetPreFitValuePCA(const int i) const
Get current parameter value using PCA.
bool IsParameterDecomposed(const int i) const
Check if parameter in PCA base is decomposed or not.
const TVectorD GetEigenValues() const
Get eigen values for all parameters, if you want for decomposed only parameters use GetEigenValuesMas...
const TMatrixD GetEigenVectors() const
Get eigen vectors of covariance matrix, only works with PCA.
void ToggleFixAllParameters()
fix parameters at prior values
void SetBranches(TTree &tree, bool SaveProposal, const std::vector< std::string > &Names)
set branches for output file
void SetParPropPCA(const int i, const double value)
Set proposed value for parameter in PCA base.
void ToggleFixParameter(const int i, const std::vector< std::string > &Names)
fix parameters at prior values
void SetParCurrPCA(const int i, const double value)
Set current value for parameter in PCA base.
void SetParametersPCA(const std::vector< double > &pars)
Set values for PCA parameters in PCA base.