MaCh3 2.2.1
Reference Guide
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PCAHandler Class Reference

Class responsible for handling Principal Component Analysis (PCA) of covariance matrix. More...

#include <Parameters/PCAHandler.h>

Collaboration diagram for PCAHandler:
[legend]

Public Member Functions

 PCAHandler ()
 Constructor.
 
virtual ~PCAHandler ()
 Destructor.
 
void Print ()
 KS: Print info about PCA parameters.
 
int GetNumberPCAedParameters () const
 Retrieve number of parameters in PCA base.
 
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 each step.
 
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.
 
void TransferToPCA ()
 Transfer param values from normal base to PCA base.
 
void TransferToParam ()
 Transfer param values from PCA base to normal base.
 
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 can break Detailed Balance;.
 
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 ThrowParProp (const double mag, const double *_restrict_ randParams)
 Throw the proposed parameter by mag sigma.
 
void ThrowParCurr (const double mag, const double *_restrict_ randParams)
 Helper function to throw the current parameter by mag sigma.
 
void SetBranches (TTree &tree, bool SaveProposal, const std::vector< std::string > &Names)
 set branches for output file
 
void ToggleFixAllParameters ()
 fix parameters at prior values
 
void ToggleFixParameter (const int i, const std::vector< std::string > &Names)
 fix parameters at prior values
 
void SetParametersPCA (const std::vector< double > &pars)
 Set values for PCA parameters in PCA base.
 
bool IsParameterFixedPCA (const int i) const
 Is parameter fixed in PCA base or not.
 
const TMatrixD GetEigenVectors () const
 Get eigen vectors of covariance matrix, only works with PCA.
 
void SetParPropPCA (const int i, const double value)
 Set proposed value for parameter in PCA base.
 
void SetParCurrPCA (const int i, const double value)
 Set current value for parameter in PCA base.
 
double GetParPropPCA (const int i) const
 Get current parameter value using PCA.
 
double GetPreFitValuePCA (const int i) const
 Get current parameter value using PCA.
 
double GetParCurrPCA (const int i) const
 Get current parameter value using PCA.
 
const TMatrixD GetTransferMatrix () const
 Get transfer matrix allowing to go from PCA base to normal base.
 
const TVectorD GetEigenValues () const
 Get eigen values for all parameters, if you want for decomposed only parameters use GetEigenValuesMaster.
 
const std::vector< double > GetEigenValuesMaster () const
 Get eigen value of only decomposed parameters, if you want for all parameters use GetEigenValues.
 
bool IsParameterDecomposed (const int i) const
 Check if parameter in PCA base is decomposed or not.
 

Private Member Functions

void SanitisePCA (TMatrixDSym *CovMatrix)
 @biref KS: Make sure decomposed matrix isn't correlated with undecomposed
 

Private Attributes

std::vector< double > _fPreFitValuePCA
 Prefit value for PCA params.
 
TVectorD _fParPropPCA
 CW: Current parameter value in PCA base.
 
TVectorD _fParCurrPCA
 CW: Proposed parameter value in PCA base.
 
std::vector< double > _fErrorPCA
 Tells if parameter is fixed in PCA base or not.
 
std::vector< int > isDecomposedPCA
 If param is decomposed this will return -1, if not this will return enumerator to param in normal base. This way we can map stuff like step scale etc between normal base and undecomposed param in eigen base.
 
int NumParPCA
 Number of parameters in PCA base.
 
TMatrixD TransferMat
 Matrix used to converting from PCA base to normal base.
 
TMatrixD TransferMatT
 Matrix used to converting from normal base to PCA base.
 
TVectorD eigen_values
 Eigen value only of particles which are being decomposed.
 
TMatrixD eigen_vectors
 Eigen vectors only of params which are being decomposed.
 
std::vector< double > eigen_values_master
 Eigen values which have dimension equal to _fNumParPCA, and can be used in CorrelateSteps.
 
int nKeptPCApars
 Total number that remained after applying PCA Threshold.
 
int FirstPCAdpar
 Index of the first param that is being decomposed.
 
int LastPCAdpar
 Index of the last param that is being decomposed.
 
double eigen_threshold
 CW: Threshold based on which we remove parameters in eigen base.
 
std::vector< double > * _pCurrVal
 Pointer to current value of the parameter.
 
std::vector< double > * _pPropVal
 Pointer to proposed value of the parameter.
 

Detailed Description

Class responsible for handling Principal Component Analysis (PCA) of covariance matrix.

See also
For more details, visit the Wiki.
Author
Clarence Wret

Definition at line 30 of file PCAHandler.h.

Constructor & Destructor Documentation

◆ PCAHandler()

PCAHandler::PCAHandler ( )

Constructor.

Definition at line 5 of file PCAHandler.cpp.

5 {
6// ********************************************
7 _pCurrVal = nullptr;
8 _pPropVal = nullptr;
9}
std::vector< double > * _pCurrVal
Pointer to current value of the parameter.
Definition: PCAHandler.h:236
std::vector< double > * _pPropVal
Pointer to proposed value of the parameter.
Definition: PCAHandler.h:238

◆ ~PCAHandler()

PCAHandler::~PCAHandler ( )
virtual

Destructor.

Definition at line 12 of file PCAHandler.cpp.

12 {
13// ********************************************
14
15}

Member Function Documentation

◆ AcceptStep()

void PCAHandler::AcceptStep ( )

Accepted this step.

Definition at line 183 of file PCAHandler.cpp.

183 {
184// ********************************************
185 // Update the book-keeping for the output
186 #ifdef MULTITHREAD
187 #pragma omp parallel for
188 #endif
189 for (int i = 0; i < NumParPCA; ++i) {
191 }
192 // Then update the parameter basis
194}
TVectorD _fParPropPCA
CW: Current parameter value in PCA base.
Definition: PCAHandler.h:205
int NumParPCA
Number of parameters in PCA base.
Definition: PCAHandler.h:213
void TransferToParam()
Transfer param values from PCA base to normal base.
Definition: PCAHandler.cpp:264
TVectorD _fParCurrPCA
CW: Proposed parameter value in PCA base.
Definition: PCAHandler.h:207

◆ ConstructPCA()

void PCAHandler::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.

Parameters
CovMatrixSymmetric covariance matrix used for eigen decomposition.
firstPCAdIndex of the first PCA component to include.
lastPCAdIndex of the last PCA component to include.
eigen_threshThreshold for eigenvalues below which parameters are discarded.
_fNumParTotal number of parameters in the original (non-PCA) basis.

Definition at line 26 of file PCAHandler.cpp.

27 {
28// ********************************************
29 FirstPCAdpar = firstPCAd;
30 LastPCAdpar = lastPCAd;
31 eigen_threshold = eigen_thresh;
32
33 // Check that covariance matrix exists
34 if (CovMatrix == NULL) {
35 MACH3LOG_ERROR("Covariance matrix for has not yet been set");
36 MACH3LOG_ERROR("Can not construct PCA until it is set");
37 throw MaCh3Exception(__FILE__ , __LINE__ );
38 }
39
40 if(FirstPCAdpar > CovMatrix->GetNrows()-1 || LastPCAdpar>CovMatrix->GetNrows()-1) {
41 MACH3LOG_ERROR("FirstPCAdpar and LastPCAdpar are higher than the number of parameters");
42 MACH3LOG_ERROR("first: {} last: {}, params: {}", FirstPCAdpar, LastPCAdpar, CovMatrix->GetNrows()-1);
43 throw MaCh3Exception(__FILE__ , __LINE__ );
44 }
45 if(FirstPCAdpar < 0 || LastPCAdpar < 0){
46 MACH3LOG_ERROR("FirstPCAdpar and LastPCAdpar are less than 0 but not default -999");
47 MACH3LOG_ERROR("first: {} last: {}", FirstPCAdpar, LastPCAdpar);
48 throw MaCh3Exception(__FILE__ , __LINE__ );
49 }
50 MACH3LOG_INFO("PCAing parameters {} through {} inclusive", FirstPCAdpar, LastPCAdpar);
51 int numunpcadpars = CovMatrix->GetNrows()-(LastPCAdpar-FirstPCAdpar+1);
52
53 // KS: Make sure we are not doing anything silly with PCA
54 SanitisePCA(CovMatrix);
55
56 TMatrixDSym submat(CovMatrix->GetSub(FirstPCAdpar,LastPCAdpar,FirstPCAdpar,LastPCAdpar));
57
58 //CW: Calculate how many eigen values this threshold corresponds to
59 TMatrixDSymEigen eigen(submat);
60 eigen_values.ResizeTo(eigen.GetEigenValues());
61 eigen_vectors.ResizeTo(eigen.GetEigenVectors());
62 eigen_values = eigen.GetEigenValues();
63 eigen_vectors = eigen.GetEigenVectors();
64 double sum = 0;
65 // Loop over eigen values and sum them up
66 for (int i = 0; i < eigen_values.GetNrows(); ++i) {
67 sum += eigen_values(i);
68 }
69 nKeptPCApars = eigen_values.GetNrows();
70 //CW: Now go through again and see how many eigen values correspond to threshold
71 for (int i = 0; i < eigen_values.GetNrows(); ++i) {
72 // Get the relative size of the eigen value
73 double sig = eigen_values(i)/sum;
74 // Check against the threshold
75 if (sig < eigen_threshold) {
76 nKeptPCApars = i;
77 break;
78 }
79 }
80 NumParPCA = numunpcadpars+nKeptPCApars;
81 MACH3LOG_INFO("Threshold of {} on eigen values relative sum of eigen value ({}) generates {} eigen vectors, plus we have {} unpcad pars, for a total of {}", eigen_threshold, sum, nKeptPCApars, numunpcadpars, NumParPCA);
82
83 //DB Create array of correct size so eigen_values can be used in CorrelateSteps
84 eigen_values_master = std::vector<double>(NumParPCA, 1.0);
86
87 // Now construct the transfer matrices
88 //These matrices will be as big as number of unPCAd pars plus number of eigenvalues kept
89 TransferMat.ResizeTo(CovMatrix->GetNrows(), NumParPCA);
90 TransferMatT.ResizeTo(CovMatrix->GetNrows(), NumParPCA);
91
92 // Get a subset of the eigen vector matrix
93 TMatrixD temp(eigen_vectors.GetSub(0, eigen_vectors.GetNrows()-1, 0, nKeptPCApars-1));
94
95 //Make transfer matrix which is two blocks of identity with a block of the PCA transfer matrix in between
96 TMatrixD temp2;
97 temp2.ResizeTo(CovMatrix->GetNrows(), NumParPCA);
98
99 //First set the whole thing to 0
100 for(int iRow = 0; iRow < CovMatrix->GetNrows(); iRow++){
101 for(int iCol = 0; iCol < NumParPCA; iCol++){
102 temp2[iRow][iCol] = 0;
103 }
104 }
105 //Set the first identity block
106 if(FirstPCAdpar != 0){
107 for(int iRow = 0; iRow < FirstPCAdpar; iRow++){
108 temp2[iRow][iRow] = 1;
109 }
110 }
111
112 //Set the transfer matrix block for the PCAd pars
113 temp2.SetSub(FirstPCAdpar,FirstPCAdpar,temp);
114
115 //Set the second identity block
116 if(LastPCAdpar != CovMatrix->GetNrows()-1){
117 for(int iRow = 0;iRow < (CovMatrix->GetNrows()-1)-LastPCAdpar; iRow++){
118 temp2[LastPCAdpar+1+iRow][FirstPCAdpar+nKeptPCApars+iRow] = 1;
119 }
120 }
121
122 TransferMat = temp2;
123 // Copy the contents
125 // And then transpose
126 TransferMatT.T();
127
128 #ifdef DEBUG_PCA
129 //KS: Let's dump all useful matrices to properly validate PCA
130 DebugPCA(sum, temp, submat, CovMatrix->GetNrows());
131 #endif
132
133 // Make the PCA parameter arrays
134 _fParCurrPCA.ResizeTo(NumParPCA);
135 _fParPropPCA.ResizeTo(NumParPCA);
137
138 //KS: make easy map so we could easily find un-decomposed parameters
140 _fErrorPCA.resize(NumParPCA);
141 for (int i = 0; i < NumParPCA; ++i)
142 {
143 _fErrorPCA[i] = 1;
144 isDecomposedPCA[i] = -1;
145 }
146 for (int i = 0; i < FirstPCAdpar; ++i) isDecomposedPCA[i] = i;
147
148 for (int i = FirstPCAdpar+nKeptPCApars+1; i < NumParPCA; ++i) isDecomposedPCA[i] = i+(_fNumPar-NumParPCA);
149}
#define MACH3LOG_ERROR
Definition: MaCh3Logger.h:25
#define MACH3LOG_INFO
Definition: MaCh3Logger.h:23
Custom exception class for MaCh3 errors.
std::vector< int > isDecomposedPCA
If param is decomposed this will return -1, if not this will return enumerator to param in normal bas...
Definition: PCAHandler.h:211
TMatrixD TransferMat
Matrix used to converting from PCA base to normal base.
Definition: PCAHandler.h:216
std::vector< double > eigen_values_master
Eigen values which have dimension equal to _fNumParPCA, and can be used in CorrelateSteps.
Definition: PCAHandler.h:224
TMatrixD eigen_vectors
Eigen vectors only of params which are being decomposed.
Definition: PCAHandler.h:222
TMatrixD TransferMatT
Matrix used to converting from normal base to PCA base.
Definition: PCAHandler.h:218
TVectorD eigen_values
Eigen value only of particles which are being decomposed.
Definition: PCAHandler.h:220
int LastPCAdpar
Index of the last param that is being decomposed.
Definition: PCAHandler.h:231
int nKeptPCApars
Total number that remained after applying PCA Threshold.
Definition: PCAHandler.h:227
std::vector< double > _fErrorPCA
Tells if parameter is fixed in PCA base or not.
Definition: PCAHandler.h:209
std::vector< double > _fPreFitValuePCA
Prefit value for PCA params.
Definition: PCAHandler.h:203
void SanitisePCA(TMatrixDSym *CovMatrix)
@biref KS: Make sure decomposed matrix isn't correlated with undecomposed
Definition: PCAHandler.cpp:154
int FirstPCAdpar
Index of the first param that is being decomposed.
Definition: PCAHandler.h:229
double eigen_threshold
CW: Threshold based on which we remove parameters in eigen base.
Definition: PCAHandler.h:233

◆ CorrelateSteps()

void PCAHandler::CorrelateSteps ( const std::vector< double > &  IndivStepScale,
const double  GlobalStepScale,
const double *_restrict_  randParams,
const double *_restrict_  corr_throw 
)

Use Cholesky throw matrix for better step proposal.

Definition at line 198 of file PCAHandler.cpp.

201 {
202// ************************************************
203 // Throw around the current step
204 #ifdef MULTITHREAD
205 #pragma omp parallel for
206 #endif
207 for (int i = 0; i < NumParPCA; ++i)
208 {
209 if (_fErrorPCA[i] > 0.)
210 {
211 double IndStepScale = 1.;
212 //KS: If undecomposed parameter apply individual step scale and Cholesky for better acceptance rate
213 if(isDecomposedPCA[i] >= 0)
214 {
215 IndStepScale *= IndivStepScale[isDecomposedPCA[i]];
216 IndStepScale *= corr_throw[isDecomposedPCA[i]];
217 }
218 //If decomposed apply only random number
219 else
220 {
221 IndStepScale *= randParams[i];
222 //KS: All PCA-ed parameters have the same step scale
223 IndStepScale *= IndivStepScale[FirstPCAdpar];
224 }
225 _fParPropPCA(i) = _fParCurrPCA(i)+GlobalStepScale*IndStepScale*eigen_values_master[i];
226 }
227 }
228 // Then update the parameter basis
230}

◆ GetNumberPCAedParameters()

int PCAHandler::GetNumberPCAedParameters ( ) const
inline

Retrieve number of parameters in PCA base.

Definition at line 41 of file PCAHandler.h.

41{ return NumParPCA; }

◆ Print()

void PCAHandler::Print ( )

KS: Print info about PCA parameters.

Definition at line 303 of file PCAHandler.cpp.

303 {
304// ********************************************
305 MACH3LOG_INFO("PCA:");
306 for (int i = 0; i < NumParPCA; ++i) {
307 MACH3LOG_INFO("PCA {:<2} Current: {:<10.2f} Proposed: {:<10.2f}", i, _fParCurrPCA(i), _fParPropPCA(i));
308 }
309}

◆ SanitisePCA()

void PCAHandler::SanitisePCA ( TMatrixDSym *  CovMatrix)
private

@biref KS: Make sure decomposed matrix isn't correlated with undecomposed

Definition at line 154 of file PCAHandler.cpp.

154 {
155// ********************************************
156 constexpr double correlation_threshold = 1e-6;
157
158 bool found_significant_correlation = false;
159
160 int N = CovMatrix->GetNrows();
161 for (int i = FirstPCAdpar; i <= LastPCAdpar; ++i) {
162 for (int j = 0; j < N; ++j) {
163 // Skip if j is inside the decomposed range (we only want cross-correlations)
164 if (j >= FirstPCAdpar && j <= LastPCAdpar) continue;
165
166 double corr_val = (*CovMatrix)(i, j);
167 if (std::fabs(corr_val) > correlation_threshold) {
168 found_significant_correlation = true;
169 MACH3LOG_ERROR("Significant correlation detected between decomposed parameter '{}' "
170 "and undecomposed parameter '{}': {:.6e}", i, j, corr_val);
171 }
172 }
173 }
174
175 if (found_significant_correlation) {
176 MACH3LOG_ERROR("There are correlations between undecomposed and decomposed part of matrices, this will not work");
177 throw MaCh3Exception(__FILE__ , __LINE__);
178 }
179}

◆ SetInitialParameters()

void PCAHandler::SetInitialParameters ( std::vector< double > &  IndStepScale)

KS: Transfer the starting parameters to the PCA basis, you don't want to start with zero..

Parameters
IndStepScalePer parameter step scale, we set so each PCA param uses same step scale [eigen value takes care of size]

Definition at line 249 of file PCAHandler.cpp.

249 {
250// ********************************************
252 for (int i = 0; i < NumParPCA; ++i) {
254 }
255 //DB Set Individual Step scale for PCA parameters to the LastPCAdpar fIndivStepScale because the step scale for those parameters is set by 'eigen_values[i]' but needs an overall step scale
256 // However, individual step scale for non-PCA parameters needs to be set correctly
257 for (int i = FirstPCAdpar; i <= LastPCAdpar; i++) {
258 IndStepScale[i] = IndStepScale[LastPCAdpar-1];
259 }
260}
void TransferToPCA()
Transfer param values from normal base to PCA base.
Definition: PCAHandler.cpp:234

◆ SetupPointers()

void PCAHandler::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 each step.

Parameters
fCurr_Valpointer to current position of parameter
fProp_Valpointer to proposed position of parameter

Definition at line 18 of file PCAHandler.cpp.

19 {
20// ********************************************
21 _pCurrVal = fCurr_Val;
22 _pPropVal = fProp_Val;
23}

◆ ThrowParameters()

void PCAHandler::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 can break Detailed Balance;.

Todo:
KS: We don't check if param is out of bounds. This is more problematic for PCA params.

Definition at line 352 of file PCAHandler.cpp.

359 {
360// ********************************************
361 //KS: Do not multithread!
362 for (int i = 0; i < NumParPCA; ++i) {
363 // Check if parameter is fixed first: if so don't randomly throw
364 if (IsParameterFixedPCA(i)) continue;
365
367 {
368 (*_pPropVal)[i] = fPreFitValue[i] + corr_throw[i];
369 int throws = 0;
370 // Try again if we the initial parameter proposal falls outside of the range of the parameter
371 while ((*_pPropVal)[i] > fUpBound[i] || (*_pPropVal)[i] < fLowBound[i]) {
372 randParams[i] = random_number[M3::GetThreadIndex()]->Gaus(0, 1);
373 const double corr_throw_single = M3::MatrixVectorMultiSingle(throwMatrixCholDecomp, randParams, _fNumPar, i);
374 (*_pPropVal)[i] = fPreFitValue[i] + corr_throw_single;
375 if (throws > 10000)
376 {
377 //KS: Since we are multithreading there is danger that those messages
378 //will be all over the place, small price to pay for faster code
379 MACH3LOG_WARN("Tried {} times to throw parameter {} but failed", throws, i);
380 MACH3LOG_WARN("Setting _fPropVal: {} to {}", (*_pPropVal)[i], fPreFitValue[i]);
381 MACH3LOG_WARN("I live at {}:{}", __FILE__, __LINE__);
382 (*_pPropVal)[i] = fPreFitValue[i];
383 }
384 throws++;
385 }
386 (*_pCurrVal)[i] = (*_pPropVal)[i];
387
388 } else {
389 // KS: We have to multiply by number of parameters in PCA base
392 }
393 } // end of parameter loop
394
396 for (int i = 0; i < _fNumPar; ++i) {
397 (*_pPropVal)[i] = std::max(fLowBound[i], std::min((*_pPropVal)[i], fUpBound[i]));
398 (*_pCurrVal)[i] = (*_pPropVal)[i];
399 }
400}
#define MACH3LOG_WARN
Definition: MaCh3Logger.h:24
bool IsParameterFixedPCA(const int i) const
Is parameter fixed in PCA base or not.
Definition: PCAHandler.h:117
double GetParPropPCA(const int i) const
Get current parameter value using PCA.
Definition: PCAHandler.h:150
double GetPreFitValuePCA(const int i) const
Get current parameter value using PCA.
Definition: PCAHandler.h:157
bool IsParameterDecomposed(const int i) const
Check if parameter in PCA base is decomposed or not.
Definition: PCAHandler.h:188
void SetParPropPCA(const int i, const double value)
Set proposed value for parameter in PCA base.
Definition: PCAHandler.h:132
void SetParCurrPCA(const int i, const double value)
Set current value for parameter in PCA base.
Definition: PCAHandler.h:141
int GetThreadIndex()
thread index inside parallel loop
Definition: Monitor.h:82
double MatrixVectorMultiSingle(double **_restrict_ matrix, const double *_restrict_ vector, const int Length, const int i)
KS: Custom function to perform multiplication of matrix and single element which is thread safe.

◆ ThrowParCurr()

void PCAHandler::ThrowParCurr ( const double  mag,
const double *_restrict_  randParams 
)

Helper function to throw the current parameter by mag sigma.

Definition at line 292 of file PCAHandler.cpp.

292 {
293// ********************************************
294 for (int i = 0; i < NumParPCA; i++) {
295 if (_fErrorPCA[i] > 0.) {
296 _fParPropPCA(i) = mag*randParams[i];
297 }
298 }
300}

◆ ThrowParProp()

void PCAHandler::ThrowParProp ( const double  mag,
const double *_restrict_  randParams 
)

Throw the proposed parameter by mag sigma.

Definition at line 280 of file PCAHandler.cpp.

280 {
281// ********************************************
282 for (int i = 0; i < NumParPCA; i++) {
283 if (_fErrorPCA[i] > 0.) {
284 _fParPropPCA(i) = _fParCurrPCA(i)+mag*randParams[i];
285 }
286 }
288}

◆ TransferToParam()

void PCAHandler::TransferToParam ( )

Transfer param values from PCA base to normal base.

Definition at line 264 of file PCAHandler.cpp.

264 {
265// ********************************************
266 // Make the temporary vectors
267 TVectorD fParProp_vec = TransferMat*_fParPropPCA;
268 TVectorD fParCurr_vec = TransferMat*_fParCurrPCA;
269 #ifdef MULTITHREAD
270 #pragma omp parallel for
271 #endif
272 for(int i = 0; i < static_cast<int>(_pCurrVal->size()); ++i) {
273 (*_pPropVal)[i] = fParProp_vec(i);
274 (*_pCurrVal)[i] = fParCurr_vec(i);
275 }
276}

◆ TransferToPCA()

void PCAHandler::TransferToPCA ( )

Transfer param values from normal base to PCA base.

Definition at line 234 of file PCAHandler.cpp.

234 {
235// ********************************************
236 // Make the temporary vectors
237 TVectorD fParCurr_vec(static_cast<Int_t>(_pCurrVal->size()));
238 TVectorD fParProp_vec(static_cast<Int_t>(_pCurrVal->size()));
239 for(int i = 0; i < static_cast<int>(_pCurrVal->size()); ++i) {
240 fParCurr_vec(i) = (*_pCurrVal)[i];
241 fParProp_vec(i) = (*_pPropVal)[i];
242 }
243
244 _fParCurrPCA = TransferMatT*fParCurr_vec;
245 _fParPropPCA = TransferMatT*fParProp_vec;
246}

Member Data Documentation

◆ _fErrorPCA

std::vector<double> PCAHandler::_fErrorPCA
private

Tells if parameter is fixed in PCA base or not.

Definition at line 209 of file PCAHandler.h.

◆ _fParCurrPCA

TVectorD PCAHandler::_fParCurrPCA
private

CW: Proposed parameter value in PCA base.

Definition at line 207 of file PCAHandler.h.

◆ _fParPropPCA

TVectorD PCAHandler::_fParPropPCA
private

CW: Current parameter value in PCA base.

Definition at line 205 of file PCAHandler.h.

◆ _fPreFitValuePCA

std::vector<double> PCAHandler::_fPreFitValuePCA
private

Prefit value for PCA params.

Definition at line 203 of file PCAHandler.h.

◆ _pCurrVal

std::vector<double>* PCAHandler::_pCurrVal
private

Pointer to current value of the parameter.

Definition at line 236 of file PCAHandler.h.

◆ _pPropVal

std::vector<double>* PCAHandler::_pPropVal
private

Pointer to proposed value of the parameter.

Definition at line 238 of file PCAHandler.h.

◆ eigen_threshold

double PCAHandler::eigen_threshold
private

CW: Threshold based on which we remove parameters in eigen base.

Definition at line 233 of file PCAHandler.h.

◆ eigen_values

TVectorD PCAHandler::eigen_values
private

Eigen value only of particles which are being decomposed.

Definition at line 220 of file PCAHandler.h.

◆ eigen_values_master

std::vector<double> PCAHandler::eigen_values_master
private

Eigen values which have dimension equal to _fNumParPCA, and can be used in CorrelateSteps.

Definition at line 224 of file PCAHandler.h.

◆ eigen_vectors

TMatrixD PCAHandler::eigen_vectors
private

Eigen vectors only of params which are being decomposed.

Definition at line 222 of file PCAHandler.h.

◆ FirstPCAdpar

int PCAHandler::FirstPCAdpar
private

Index of the first param that is being decomposed.

Definition at line 229 of file PCAHandler.h.

◆ isDecomposedPCA

std::vector<int> PCAHandler::isDecomposedPCA
private

If param is decomposed this will return -1, if not this will return enumerator to param in normal base. This way we can map stuff like step scale etc between normal base and undecomposed param in eigen base.

Definition at line 211 of file PCAHandler.h.

◆ LastPCAdpar

int PCAHandler::LastPCAdpar
private

Index of the last param that is being decomposed.

Definition at line 231 of file PCAHandler.h.

◆ nKeptPCApars

int PCAHandler::nKeptPCApars
private

Total number that remained after applying PCA Threshold.

Definition at line 227 of file PCAHandler.h.

◆ NumParPCA

int PCAHandler::NumParPCA
private

Number of parameters in PCA base.

Definition at line 213 of file PCAHandler.h.

◆ TransferMat

TMatrixD PCAHandler::TransferMat
private

Matrix used to converting from PCA base to normal base.

Definition at line 216 of file PCAHandler.h.

◆ TransferMatT

TMatrixD PCAHandler::TransferMatT
private

Matrix used to converting from normal base to PCA base.

Definition at line 218 of file PCAHandler.h.


The documentation for this class was generated from the following files: