2 #include "Utils/IOUtils.h"
8 : inputFile(file), pca(true) {
14 if (threshold < 0 || threshold >= 1) {
16 MACH3LOG_INFO(
"Principal component analysis but given the threshold for the principal components to be less than 0, or greater than (or equal to) 1. This will not work");
19 MACH3LOG_INFO(
"Am instead calling the usual non-PCA constructor...");
49 MACH3LOG_ERROR(
"Adaption has been enabled and now trying to enable PCA. Right now both configuration don't work with each other");
53 PCAObj = std::make_unique<PCAHandler>();
55 if(FirstPCAdpar == -999 || LastPCAdpar == -999) {
56 if(FirstPCAdpar == -999 && LastPCAdpar == -999) {
61 MACH3LOG_ERROR(
"You must either leave FirstPCAdpar and LastPCAdpar at -999 or set them both to something");
76 TFile *infile =
new TFile(file.c_str(),
"READ");
77 if (infile->IsZombie()) {
78 MACH3LOG_ERROR(
"Could not open input covariance ROOT file {} !!!", file);
83 TMatrixDSym *CovMat =
static_cast<TMatrixDSym*
>(infile->Get(name.c_str()));
86 MACH3LOG_ERROR(
"Could not find covariance matrix name {} in file {}", name, file);
87 MACH3LOG_ERROR(
"Are you really sure {} exists in the file?", name);
109 std::vector<PendingFunctionalFlipProposal>& PendingFunctionalFlipParameters){
113 bool CircEnabled =
false;
114 std::pair<double, double> circular_bounds;
116 bool FlipEnabled =
false;
117 std::string flip_group;
120 bool FunctionalFlipEnabled =
false;
121 YAML::Node functional_flip;
123 if (param[
"CircularBounds"]) {
125 circular_bounds = Get<std::pair<double, double>>(param[
"CircularBounds"], __FILE__, __LINE__);
128 if (param[
"FlipParameter"]) {
131 if (param[
"FlipGroup"]) {
132 flip_group = Get<std::string>(param[
"FlipGroup"], __FILE__, __LINE__);
136 flip_point = Get<double>(param[
"FlipParameter"], __FILE__, __LINE__);
139 if (param[
"FunctionalFlip"]) {
140 FunctionalFlipEnabled =
true;
142 if (param[
"FlipGroup"]) {
143 flip_group = Get<std::string>(param[
"FlipGroup"], __FILE__, __LINE__);
147 functional_flip = param[
"FunctionalFlip"];
150 if (!CircEnabled && !FlipEnabled && !FunctionalFlipEnabled) {
156 if (FlipEnabled && FunctionalFlipEnabled) {
164 MACH3LOG_INFO(
"Enabling CircularBounds for parameter {} with range [{}, {}]",
166 circular_bounds.first,
167 circular_bounds.second);
169 if (circular_bounds.first <
_fLowBound.at(Index) || circular_bounds.second >
_fUpBound.at(Index)) {
170 MACH3LOG_ERROR(
"Circular bounds [{}, {}] for parameter {} exceed physical bounds [{}, {}]",
171 circular_bounds.first, circular_bounds.second,
179 MACH3LOG_ERROR(
"This is not supported, CircularPrior only works with flat prior");
190 MACH3LOG_INFO(
"Enabling Flipping for parameter {} in group {} with value {}",
196 if (FunctionalFlipEnabled) {
200 MACH3LOG_INFO(
"Enabling Functional Flipping for parameter {} in group {} with config {}",
203 YAML::Dump(functional_flip));
206 if (CircEnabled && FlipEnabled) {
207 if (flip_point < circular_bounds.first || flip_point > circular_bounds.second) {
208 MACH3LOG_ERROR(
"FlipParameter value {} for parameter {} is outside the CircularBounds [{}, {}]",
209 flip_point,
GetParFancyName(Index), circular_bounds.first, circular_bounds.second);
213 const double low = circular_bounds.first;
214 const double high = circular_bounds.second;
217 const double flipped_low = 2 * flip_point - low;
218 const double flipped_high = 2 * flip_point - high;
219 const double min_flip = std::min(flipped_low, flipped_high);
220 const double max_flip = std::max(flipped_low, flipped_high);
222 if (min_flip < low || max_flip > high) {
223 MACH3LOG_ERROR(
"Flipping about point {} for parameter {} would leave circular bounds [{}, {}]",
232 const YAML::Node& param,
const int index,
const std::string& group_name) {
237 pending_flip.
config = YAML::Clone(param);
238 PendingFunctionalFlipParameters.push_back(std::move(pending_flip));
244 for (
const auto& pending_flip : PendingFunctionalFlipParameters) {
245 AddFunctionalFlip(pending_flip.config, pending_flip.target_index, pending_flip.group_name);
248 PendingFunctionalFlipParameters.clear();
254 YAML::Node functional_flip = YAML::Clone(param);
255 const YAML::Node formula = functional_flip[
"Formula"];
256 const YAML::Node parameters = functional_flip[
"Parameters"];
269 auto formula_name = Get<std::string>(formula, __FILE__, __LINE__);
270 flip.
argument_names = Get<std::vector<std::string>>(parameters, __FILE__, __LINE__);
275 MACH3LOG_ERROR(
"FunctionalFlip for parameter {} refers to unknown parameter {}",
282 const std::string flip_name = fmt::format(
"{}_{}_functional_flip_{}",
285 FlipGroups[group_name].FunctionalFlipParameters.size());
286 flip.
evaluator = std::make_unique<TF1>(flip_name.c_str(), formula_name.c_str(), 0.0, 1.0);
289 MACH3LOG_ERROR(
"Failed to parse FunctionalFlip formula for parameter {}: {}",
295 MACH3LOG_ERROR(
"FunctionalFlip formula for parameter {} expects {} auxiliary parameters, but {} names were provided",
297 MACH3LOG_ERROR(
"Use x for the target parameter and [0], [1], ... for the listed Parameters entries");
301 MACH3LOG_INFO(
"Enabling FunctionalFlip for parameter {} with formula '{}'",
303 FlipGroups[group_name].FunctionalFlipParameters.push_back(std::move(flip));
310 if (cov ==
nullptr) {
311 MACH3LOG_ERROR(
"Could not find covariance matrix you provided to {}", __func__ );
316 invCovMatrix =
static_cast<TMatrixDSym *
>(cov->Clone());
337 _fNames = std::vector<std::string>(SizeVec);
340 _fError = std::vector<double>(SizeVec, 1.0);
341 _fCurrVal = std::vector<double>(SizeVec, 0.0);
342 _fPropVal = std::vector<M3::float_t>(SizeVec, 0.0);
343 _fLowBound = std::vector<double>(SizeVec, -999.99);
344 _fUpBound = std::vector<double>(SizeVec, 999.99);
353 for(
int i = 0; i < SizeVec; i++) {
361 for(
int i = 0; i < SizeVec; i++) {
363 for (
int j = 0; j < SizeVec; j++) {
376 MACH3LOG_DEBUG(
"Over-riding {}: _fPropVal ({}), _fCurrVal ({}), _fPreFitValue ({}) to ({})",
396 #pragma GCC diagnostic push
397 #pragma GCC diagnostic ignored "-Wuseless-cast"
401 if (__builtin_expect(!
pca, 1)) {
403 #pragma omp parallel for
405 for (
int i = 0; i <
_fNumPar; ++i) {
420 MACH3LOG_WARN(
"Tried {} times to throw parameter {} but failed",
throws, i);
439 #pragma GCC diagnostic pop
449 #pragma GCC diagnostic push
450 #pragma GCC diagnostic ignored "-Wuseless-cast"
455 for (
int i = 0; i <
_fNumPar; ++i) {
461 const double sigma = sqrt((*
covMatrix)(i,i));
462 double throwrange = sigma;
463 if (paramrange < sigma) throwrange = paramrange;
470 MACH3LOG_WARN(
"Tried {} times to throw parameter {} but failed",
throws, i);
481 #pragma GCC diagnostic pop
536 for (
const auto& [group_name, group] :
FlipGroups) {
550 #pragma omp parallel for
552 for (
int i = 0; i <
_fNumPar; ++i) {
565 #pragma omp parallel for
567 for (
int i = 0; i <
PCAObj->GetNumberPCAedParameters(); ++i)
570 if (
PCAObj->IsParameterFixedPCA(i)) {
589 #pragma omp parallel for
591 for (
int i = 0; i <
_fNumPar; ++i) {
593 #pragma GCC diagnostic push
594 #pragma GCC diagnostic ignored "-Wuseless-cast"
596 #pragma GCC diagnostic pop
610 #pragma omp parallel for
612 for (
int i = 0; i <
_fNumPar; ++i) {
625 #pragma GCC diagnostic push
626 #pragma GCC diagnostic ignored "-Wuseless-cast"
633 }
else if (
_fPropVal[index] < LowBound) {
651 std::vector<double> proposed_values(
_fNumPar, 0.0);
652 for (
int i = 0; i <
_fNumPar; ++i) {
678 const std::vector<double>& proposed_values)
const {
685 const double target_value = proposed_values[flip.
target_index];
686 const double flipped_value = flip.
evaluator->EvalPar(&target_value, parameter_values.data());
689 #pragma GCC diagnostic pop
699 for (
int i = 0; i <
_fNumPar; ++i) {
703 for (
const auto& line : table.Render()) {
722 for (
int i = 0; i <
_fNumPar; ++i) {
729 for (
const auto& line : table.Render()) {
743 #pragma omp parallel for reduction(+:logL)
755 for (
int j = 0; j <= i; ++j) {
758 double scale = (i != j) ? 1. : 0.5;
770 for (
int i = 0; i <
_fNumPar; ++i) {
794 #pragma GCC diagnostic push
795 #pragma GCC diagnostic ignored "-Wuseless-cast"
798 for (
int i = 0; i <
_fNumPar; i++) {
803 if (pars.size() !=
static_cast<size_t>(
_fNumPar)) {
807 int parsSize = int(pars.size());
808 for (
int i = 0; i < parsSize; i++) {
810 if(std::isnan(pars[i])) {
821 PCAObj->TransferToParam();
823 #pragma GCC diagnostic pop
830 for (
int i = 0; i <
_fNumPar; ++i) {
840 for (
int i = 0; i <
_fNumPar; ++i) {
853 MACH3LOG_ERROR(
"You are trying so set StepScale to 0 or negative this will not work");
859 const double SuggestedScale = 2.38/std::sqrt(
_fNumPar);
860 if(std::fabs(scale - SuggestedScale)/SuggestedScale > 1) {
861 MACH3LOG_WARN(
"Defined Global StepScale is {}, while suggested suggested {}", scale, SuggestedScale);
954 MACH3LOG_WARN(
"I couldn't find parameter with name {}, therefore will not fix it", name);
965 MACH3LOG_WARN(
"I couldn't find parameter with name {}, therefore don't know if it fixed", name);
991 if (
static_cast<int>(stepscale.size()) !=
_fNumPar)
993 MACH3LOG_WARN(
"Stepscale vector not equal to number of parameters. Quitting..");
994 MACH3LOG_WARN(
"Size of argument vector: {}", stepscale.size());
999 for (
int iParam = 0 ; iParam <
_fNumPar; iParam++) {
1011 for (
int iParam = 0; iParam <
_fNumPar; ++iParam) {
1015 for (
const auto& line : table.Render()) {
1031 if(n_attempts > 0 && verbose) {
1032 MACH3LOG_WARN(
"Covariance matrix {} was not positive-definite, made it positive-definite after {} attempts",
matrixName, n_attempts);
1039 std::vector<double> stepScales(
_fNumPar, 1.0);
1048 MACH3LOG_ERROR(
"Parameter skip adapt flags not set, cannot set individual step scales for skipped parameters.");
1052 for (
int i = 0; i <
_fNumPar; i++) {
1057 MACH3LOG_DEBUG(
"Updating individual step scales for non-adapting parameters to cancel global step scale change.");
1065 if (cov ==
nullptr) {
1066 MACH3LOG_ERROR(
"Could not find covariance matrix you provided to {}", __func__);
1070 if (
covMatrix->GetNrows() != cov->GetNrows()) {
1071 MACH3LOG_ERROR(
"Matrix given for throw Matrix is not the same size as the covariance matrix stored in object!");
1077 throwMatrix =
static_cast<TMatrixDSym*
>(cov->Clone());
1087 for (
int i = 0; i <
_fNumPar; ++i) {
1088 const double variance = (*throwMatrix)(i, i);
1089 if(!std::isfinite(variance) || variance <= 0.) {
1090 MACH3LOG_WARN(
"Invalid variance for param {} ({}): {}, after posdef this will cause proposal to fail",
1099 #pragma omp parallel for collapse(2)
1112 TMatrixDSym
const &subcov) {
1114 if ((last_index - first_index) >= subcov.GetNrows()) {
1115 MACH3LOG_ERROR(
"Trying to SetSubThrowMatrix into range: ({},{}) with a "
1116 "submatrix with only {} rows {}",
1117 first_index, last_index, subcov.GetNrows(), __func__);
1121 TMatrixDSym *current_ThrowMatrix =
1123 for (
int i = first_index; i <= last_index; ++i) {
1124 for (
int j = first_index; j <= last_index; ++j) {
1125 current_ThrowMatrix->operator()(i, j) =
1126 subcov(i - first_index, j - first_index);
1131 delete current_ThrowMatrix;
1146 for (
size_t i = 0; i < group.FlipParameterIndex.size(); ++i) {
1147 const int index = group.FlipParameterIndex[i];
1150 MACH3LOG_ERROR(
"Right now flipping and adapting doesn't work very well");
1160 constexpr
double max_correlation = 0.01;
1161 for (
int i = 0; i <
_fNumPar; ++i) {
1162 for (
int j = 0; j <= i; ++j) {
1166 if(std::fabs(corr) > max_correlation) {
1167 MACH3LOG_ERROR(
"Correlation between skipped parameter {} ({}) and non-skipped parameter {} ({}) is {:.6e}, above the allowed threshold of {:.6e}.",
1181 MACH3LOG_ERROR(
"PCA has been enabled and now trying to enable Adaption. Right now both configuration don't work with each other");
1185 MACH3LOG_ERROR(
"Adaptive Handler has already been initialise can't do it again so skipping.");
1195 auto params_to_skip = GetFromManager<std::vector<std::string>>(adapt_manager[
"AdaptionOptions"][
"Covariance"][
matrixName][
"ParametersToSkip"], {}, __FILE__ , __LINE__);
1198 for (
int i = 0; i <
_fNumPar; ++i) {
1225 if(GetFromManager<bool>(adapt_manager[
"AdaptionOptions"][
"Covariance"][
matrixName][
"UseExternalMatrix"],
false, __FILE__ , __LINE__)) {
1227 auto external_file_name = GetFromManager<std::string>(adapt_manager[
"AdaptionOptions"][
"Covariance"][
matrixName][
"ExternalMatrixFileName"],
"", __FILE__ , __LINE__);
1228 auto external_matrix_name = GetFromManager<std::string>(adapt_manager[
"AdaptionOptions"][
"Covariance"][
matrixName][
"ExternalMatrixName"],
"", __FILE__ , __LINE__);
1229 auto external_mean_name = GetFromManager<std::string>(adapt_manager[
"AdaptionOptions"][
"Covariance"][
matrixName][
"ExternalMeansName"],
"", __FILE__ , __LINE__);
1239 MACH3LOG_INFO(
"Successfully Set External Throw Matrix Stored in {}", external_file_name);
1242 if (!success)
return;
1287 TMatrixDSym* update_matrix =
static_cast<TMatrixDSym*
>(
AdaptiveHandler->GetAdaptiveCovariance()->Clone());
1309 TMatrixDSym* cov_trans = cov;
1311 TMatrixDSym cov_sym = 0.5*(*cov+*cov_trans);
1314 TDecompSVD cov_sym_svd=TDecompSVD(cov_sym);
1315 if(!cov_sym_svd.Decompose()){
1316 MACH3LOG_WARN(
"Cannot do SVD on input matrix, trying MakePosDef() first!");
1320 TMatrixD cov_sym_v = cov_sym_svd.GetV();
1321 TMatrixD cov_sym_vt = cov_sym_v;
1324 TVectorD cov_sym_sigvect = cov_sym_svd.GetSig();
1326 const Int_t nCols = cov_sym_v.GetNcols();
1327 TMatrixDSym cov_sym_sig(nCols);
1328 TMatrixDDiag cov_sym_sig_diag(cov_sym_sig);
1329 cov_sym_sig_diag=cov_sym_sigvect;
1332 TMatrixDSym cov_sym_polar = cov_sym_sig.SimilarityT(cov_sym_vt);
1335 TMatrixDSym cov_closest_approx = 0.5*(cov_sym+cov_sym_polar);
1340 *cov = cov_closest_approx;
1350 hMatrix->SetDirectory(
nullptr);
1353 hMatrix->SetBinContent(i+1, i+1, 1.);
1359 #pragma omp parallel for
1363 for(
int j = 0; j <= i; j++)
1366 hMatrix->SetBinContent(i+1, j+1, Corr);
1367 hMatrix->SetBinContent(j+1, i+1, Corr);
1387 for (YAML::Node param : copyNode[
"Systematics"])
1394 std::ofstream fout(
"Modified_Matrix.yaml");
1403 if(
Tunes ==
nullptr) {
1404 MACH3LOG_ERROR(
"Tunes haven't been initialised, which are being loaded from YAML, have you used some deprecated constructor");
1407 auto Values =
Tunes->GetTune(TuneName);
1414 std::vector<double>& BranchValues,
1415 std::vector<std::string>& BranchNames,
1416 const std::vector<std::string>& FancyNames) {
1424 if(FancyNames.size() != 0){
1429 bool matched =
false;
1430 for (
size_t iPar = 0; iPar < FancyNames.size(); ++iPar) {
1433 PosteriorFile->SetBranchStatus(BranchNames[iPar].c_str(),
true);
1434 PosteriorFile->SetBranchAddress(BranchNames[iPar].c_str(), &BranchValues[i]);
1447 if (!PosteriorFile->GetBranch(BranchNames[i].c_str())) {
1448 MACH3LOG_WARN(
"Branch '{}' does not exist in the TTree, is this what you want?", BranchNames[i]);
1451 PosteriorFile->SetBranchStatus(BranchNames[i].c_str(),
true);
1452 PosteriorFile->SetBranchAddress(BranchNames[i].c_str(), &BranchValues[i]);
#define _noexcept_
KS: noexcept can help with performance but is terrible for debugging, this is meant to help easy way ...
#define MACH3LOG_CRITICAL
Creates fancy formatted text tables for terminal output.
void AddRow(Args &&... args)
Add a row to the table.
Custom exception class used throughout MaCh3.
std::vector< int > CircularBoundsIndex
Indices of parameters with circular bounds.
int GetNumParams() const
Get total number of parameters.
std::vector< bool > param_skip_adapt_flags
Flags telling if parameter should be skipped during adaption.
void ToggleFixParameter(const int i)
Toggle fixing parameter at prior values.
bool use_adaptive
Are we using AMCMC?
void SetFixAllParameters()
Set all parameters to be fixed at prior values.
virtual void ProposeStep()
Generate a new proposed state.
void EnableSpecialProposal(const YAML::Node ¶m, const int Index, std::vector< PendingFunctionalFlipProposal > &PendingFunctionalFlipParameters)
Enable special proposal.
TH2D * GetCorrelationMatrix() const
KS: Convert covariance matrix to correlation matrix and return TH2D which can be used for fancy plott...
void SanitizeAdaption() const
Perform sanity check to ensure adaption isn't misbehaving before fit starts.
double * randParams
Random number taken from gaussian around prior error used for corr_throw.
void SetName(const std::string &name)
Set matrix name.
std::map< std::string, FlipGroup > FlipGroups
Map of flip groups, where the key is the group name and the value is a FlipGroup struct.
void AddFunctionalFlip(const YAML::Node ¶m, const int index, const std::string &group_name)
Parse and register a functional flip defined in YAML.
double ** throwMatrixCholDecomp
Throw matrix that is being used in the fit, much faster as TMatrixDSym cache miss.
void SetStepScale(const double scale, const bool verbose=true)
Set global step scale for covariance object.
virtual ~ParameterHandlerBase()
Destructor.
TMatrixDSym * invCovMatrix
The inverse covariance matrix.
void SetCovMatrix(TMatrixDSym *cov)
Set covariance matrix.
std::string GetParName(const int i) const
Get name of parameter.
void SetFlatPrior(const int i, const bool eL)
Set if parameter should have flat prior or not.
void AcceptStep() _noexcept_
Accepted this step.
virtual double GetLikelihood()
Return CalcLikelihood if some params were thrown out of boundary return LARGE_LOGL
std::unique_ptr< AdaptiveMCMCHandler > AdaptiveHandler
Struct containing information about adaption.
std::vector< M3::float_t > _fPropVal
Proposed value of the parameter.
std::unique_ptr< ParameterTunes > Tunes
Struct containing information about adaption.
void InitialiseAdaption(const YAML::Node &adapt_manager)
Initialise adaptive MCMC.
TMatrixDSym * throwMatrix
Matrix which we use for step proposal before Cholesky decomposition (not actually used for step propo...
double _fGlobalStepScale
Global step scale applied to all params in this class.
void FlipParameterGroup(const std::string &group)
With a 50% chance, flip all parameters in a group around their respective flip points.
int GetParIndex(const std::string &name) const
Get index based on name.
void ReserveMemory(const int size)
Initialise vectors with parameters information.
M3::float_t EvaluateFunctionalFlip(const FunctionalFlipProposal &flip, const std::vector< double > &proposed_values) const
Evaluate a formula-driven flip for a target parameter.
std::vector< std::string > _fFancyNames
Fancy name for example rather than param_0 it is MAQE, useful for human reading.
bool doSpecialStepProposal
Check if any of special step proposal were enabled.
std::vector< bool > _fFlatPrior
Whether to apply flat prior or not.
void ThrowParameters()
Throw the parameters according to the covariance matrix. This shouldn't be used in MCMC code ase it c...
double _fGlobalStepScaleInitial
Backup of _fGlobalStepScale for parameters which are skipped during adaption.
std::string matrixName
Name of cov matrix.
void MakeClosestPosDef(TMatrixDSym *cov)
HW: Finds closest possible positive definite matrix in Frobenius Norm ||.||_frob Where ||X||_frob=sqr...
void RandomConfiguration()
Randomly throw the parameters in their 1 sigma range.
TMatrixDSym * GetCovMatrix() const
Return covariance matrix.
void UpdateAdaptiveCovariance()
Method to update adaptive MCMC .
std::string GetParFancyName(const int i) const
Get fancy name of the Parameter.
std::vector< double > _fError
Prior error on the parameter.
void SetFreeAllParameters()
Set all parameters to be treated as free.
void SetFixParameter(const int i)
Set parameter to be fixed at prior value.
void SetParameters(const std::vector< double > &pars={})
Set parameter values using vector, it has to have same size as covariance class.
YAML::Node _fYAMLDoc
Stores config describing systematics.
void SetThrowMatrix(const TMatrixDSym *cov)
Use new throw matrix, used in adaptive MCMC.
bool IsParameterFixed(const int i) const
Is parameter fixed or not.
void MatchMaCh3OutputBranches(TTree *PosteriorFile, std::vector< double > &BranchValues, std::vector< std::string > &BranchNames, const std::vector< std::string > &FancyNames={})
Matches branches in a TTree to parameters in a systematic handler.
void UpdateThrowMatrix(TMatrixDSym *cov)
Replaces old throw matrix with new one.
void CircularParBounds(const int i, const double LowBound, const double UpBound)
HW :: This method is a tad hacky but modular arithmetic gives me a headache.
void SetBranches(TTree &tree, const bool SaveProposal=false)
set branches for output file
void SaveUpdatedMatrixConfig()
KS: After step scale, prefit etc. value were modified save this modified config.
void InitFromFile(const std::string &name, const std::string &file)
Initialisation of the class using matrix from root file.
void ResetIndivStepScale()
Adaptive Step Tuning Stuff.
std::unique_ptr< PCAHandler > PCAObj
Struct containing information about PCA.
int _fNumPar
Number of systematic parameters.
double CalcLikelihood() const _noexcept_
Calc penalty term based on inverted covariance matrix.
void ConstructPCA(const double eigen_threshold, int FirstPCAdpar, int LastPCAdpar)
CW: Calculate eigen values, prepare transition matrices and remove param based on defined threshold.
std::vector< double > _fIndivStepScaleInitial
Backup of _fIndivStepScale for parameters which are skipped during adaption.
std::vector< double > _fLowBound
Lowest physical bound, parameter will not be able to go beyond it.
std::vector< double > _fCurrVal
Current value of the parameter.
std::vector< std::vector< double > > InvertCovMatrix
KS: Same as above but much faster as TMatrixDSym cache miss.
TMatrixDSym * covMatrix
The covariance matrix.
std::vector< double > _fPreFitValue
Parameter value dictated by the prior model. Based on it penalty term is calculated.
void Randomize() _noexcept_
"Randomize" the parameters in the covariance class for the proposed step. Used the proposal kernel an...
void PrintIndivStepScale() const
Print step scale for each parameter.
std::vector< std::string > _fNames
ETA _fNames is set automatically in the covariance class to be something like param_i,...
std::vector< std::pair< double, double > > CircularBoundsValues
Circular bounds for each parameter (lower, upper)
double * corr_throw
Result of multiplication of Cholesky matrix and randParams.
bool GetFlatPrior(const int i) const
Get if param has flat prior or not.
std::string GetName() const
Get name of covariance.
double GetParPreFit(const int i) const
Get prior parameter value.
void SetParCurrProp(const int i, const double val)
Set current parameter value.
void ResolveFunctionalFlips(std::vector< PendingFunctionalFlipProposal > &PendingFunctionalFlipParameters)
Resolve queued functional flips after parameter names are known.
void SetFreeParameter(const int i)
Set parameter to be treated as free.
std::vector< double > _fUpBound
Upper physical bound, parameter will not be able to go beyond it.
void SetSingleParameter(const int parNo, const double parVal)
Set value of single param to a given value.
void SetPar(const int i, const double val)
Set all the covariance matrix parameters to a user-defined value.
void SetIndivStepScale(const int ParameterIndex, const double StepScale)
DB Function to set fIndivStepScale from a vector (Can be used from execs and inside covariance constr...
void SetIndivStepScaleForSkippedAdaptParams()
Set individual step scale for parameters which are skipped during adaption to initial values.
double GetDiagonalError(const int i) const
Get diagonal error for ith parameter.
ParameterHandlerBase()=default
void SetSubThrowMatrix(int first_index, int last_index, TMatrixDSym const &subcov)
void SetTune(const std::string &TuneName)
KS: Set proposed parameter values vector to be base on tune values, for example set proposed values t...
bool pca
perform PCA or not
std::vector< double > _fIndivStepScale
Individual step scale used by MCMC algorithm.
void PrintPreFitValues() const
Print prior value for every parameter.
void QueueFunctionalFlip(std::vector< PendingFunctionalFlipProposal > &PendingFunctionalFlipParameters, const YAML::Node ¶m, const int index, const std::string &group_name)
Queue a functional flip until all parameters have been loaded.
void SpecialStepProposal()
Perform Special Step Proposal.
void PrintPreFitCurrPropValues() const
Print prior, current and proposed value for each parameter.
void CorrelateSteps() _noexcept_
Use Cholesky throw matrix for better step proposal.
void MakePosDef(TMatrixDSym *cov=nullptr, bool verbose=true)
Make matrix positive definite by adding small values to diagonal, necessary for inverting matrix.
int CheckBounds() const _noexcept_
Check if parameters were proposed outside physical boundary.
static std::string Cell(T &&value, std::string_view format)
Format a value using a runtime fmt format string.
std::string FormatDouble(const double value, const int precision)
Convert double into string for precision, useful for playing with yaml if you don't want to have in c...
@ Right
Align text to the right.
@ Left
Align text to the left.
double Uniform(const double min=0.0, const double max=1.0)
Generate a uniform random number in [min, max).
double Gaus(const double mean=0.0, const double sigma=1.0)
Generate a Gaussian random number.
constexpr static const double _LARGE_LOGL_
Large Likelihood is used it parameter go out of physical boundary, this indicates in MCMC that such s...
void MatrixVectorMulti(double *_restrict_ VecMulti, double **_restrict_ matrix, const double *_restrict_ vector, const int n)
KS: Custom function to perform multiplication of matrix and vector with multithreading.
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.
int MakeMatrixPosDef(TMatrixDSym *cov)
Makes sure that matrix is positive-definite by adding a small number to on-diagonal elements.
constexpr static const int _BAD_INT_
Default value used for int initialisation.
bool CaseInsensitiveMatchAny(std::string Text, const std::vector< std::string > &Patterns)
Matches a string against a simple wildcard Pattern using regex. Is not case sensitive.
std::vector< std::vector< double > > GetCholeskyDecomposedMatrix(const TMatrixDSym &matrix, const std::string &matrixName)
Computes Cholesky decomposition of a symmetric positive definite matrix using custom function which c...
Struct to hold information about a group of parameters that flip together at the same time.
std::vector< int > FlipParameterIndex
Indices of parameters with flip symmetry.
std::vector< double > FlipParameterPoint
Central points around which parameters are flipped.
std::vector< FunctionalFlipProposal > FunctionalFlipParameters
Formula-driven flips that should be applied when this group flips.
Configuration for a formula-based functional flip.
std::vector< int > argument_indices
parameter indices passed to evaluator
std::vector< std::string > argument_names
Parameter names that are passed to evaluator.
std::unique_ptr< TF1 > evaluator
function used to evaluate flipping formula
Configuration for a pending functional flip awaiting all parameters to be initialised.