15 MACH3LOG_ERROR(
"MCMC chain length must be at least 10 steps, otherwise this will result in a floating point exception.");
28 multicanonical = GetFromManager<bool>(
fitMan->
raw()[
"General"][
"MCMC"][
"Multicanonical"][
"Enabled"],
false, __FILE__, __LINE__);
86 if (syst->GetDoAdaption())
88 auto adaptive_handler = syst->GetAdaptiveHandler();
89 adaptive_handler->SaveAdaptiveToFile(adaptive_handler->GetOutFileName(), syst->GetName(),
true);
123 int originalErrorLevel = gErrorIgnoreLevel;
124 gErrorIgnoreLevel = kFatal;
138 gErrorIgnoreLevel = originalErrorLevel;
148 for (
size_t i = 0; i <
samples.size(); ++i) {
153 cov->PrintPreFitCurrPropValues();
158 debugFile <<
"\n-------------------------------------------------------" << std::endl;
171 if(
step -
stepStart < std::min(10.0,
static_cast<double>(StepEnd)/10)) {
181 if (acc_rate < 0.01) {
182 MACH3LOG_WARN(
"Acceptance rate is very low: {:.4f}. This may indicate that the proposal distribution is not well-tuned. Consider reducing the step size.", acc_rate);
183 }
else if (acc_rate > 0.5) {
184 MACH3LOG_WARN(
"Acceptance rate is very high: {:.4f}. This may indicate that the proposal distribution is too narrow. Consider increasing the step sizes.", acc_rate);
195 TFile *infile = M3::Open(FitName,
"READ", __FILE__, __LINE__);
196 TTree *posts = infile->Get<TTree>(
"posteriors");
197 unsigned int step_val = 0;
199 posts->SetBranchAddress(
"step", &step_val);
200 posts->GetEntry(posts->GetEntries() - 1);
204 for (
unsigned int i = 0; i <
systematics.size(); ++i) {
219 if (syst->GetDoAdaption()){
220 syst->UpdateAdaptiveCovariance();
232 debugFile <<
" logLProp: " <<
logLProp <<
" logLCurr: " <<
logLCurr <<
" acc_prob: " << acc_prob <<
" fRandom: " << fRandom << std::endl;
235 if (fRandom > acc_prob)
260 std::string OutName =
"";
262 OutName +=
"MultiCanonical_";
265 for(
unsigned int i = 0; i <
systematics.size(); ++i){
267 if(
systematics[i]->GetAdaptiveHandler()->GetUseRobbinsMonro()){
268 OutName +=
"RobbinsMonro_";
270 OutName +=
"Adaptive_";
275 OutName += originalName;
#define MACH3LOG_CRITICAL
bool CheckNodeExists(const YAML::Node &node, Args... args)
KS: Wrapper function to call the recursive helper.
Base class for implementing fitting algorithms.
std::string GetName() const
Get name of class.
double logLProp
proposed likelihood
void ProcessMCMC()
Process MCMC output.
int accCount
counts accepted steps
void SaveOutput()
Save output and close files.
void SaveSettings()
Save the settings that the MCMC was run with.
unsigned int step
current state
void PrepareOutput()
Prepare the output file.
virtual void StartFromPreviousFit(const std::string &FitName)
Allow to start from previous fit/chain.
std::vector< SampleHandlerInterface * > samples
Sample holder.
double stepTime
Time of single step.
Manager * fitMan
The manager for configuration handling.
unsigned int stepStart
step start, by default 0 if we start from previous chain then it will be different
std::unique_ptr< TStopwatch > stepClock
tells how long single step/fit iteration took
double logLCurr
current likelihood
int auto_save
auto save every N steps
TTree * outTree
Output tree with posteriors.
void SanitiseInputs()
Remove obsolete memory and make other checks before fit starts.
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
std::unique_ptr< MulticanonicalMCMCHandler > multicanonicalHandler
multicanonical handler for umbrella sampling
MCMCBase(Manager *const fitMan)
Constructor.
void RunMCMC() final
Actual implementation of MCMC fitting algorithm.
unsigned int chainLength
number of steps in chain
void StartFromPreviousFit(const std::string &FitName) final
Allow to start from previous fit/chain.
void AcceptStep()
Accept a step.
std::string GetFancyName() const final
This name is to get include some special algorithm extensions.
bool out_of_bounds
Do we reject based on hitting boundaries in systs.
bool IsStepAccepted(const double acc_prob)
Is step accepted?
void DoMCMCStep()
The full StartStep->DoStep->EndStep chain.
void PreStepProcess()
Actions before step proposal [start stopwatch].
bool multicanonical
multi-canonical method toggle on/off
virtual void ProposeStep()=0
Propose a step.
void CheckAcceptanceRates()
Check the acceptance rates.
void PrintProgress(const bool StepsPrint=true)
Print the progress.
virtual void DoStep()=0
The MCMC step proposal and acceptance.
void PostStepProcess()
Actions after step proposal [end stopwatch, fill tree].
void AdaptiveStep()
Adaptive MCMC step.
Custom exception class used throughout MaCh3.
The manager class is responsible for managing configurations and settings.
YAML::Node const & raw() const
Return config.
Base class for handling systematic uncertainty parameters.
double Uniform(const double min=0.0, const double max=1.0)
Generate a uniform random number in [min, max).