MaCh3  2.2.3
Reference Guide
MR2T2.cpp
Go to the documentation of this file.
1 #include "Fitters/MR2T2.h"
2 
3 
4 // ***************
6 // ***************
7  AlgorithmName = "MR2T2";
8 }
9 
10 // *******************
11 void MR2T2::DoStep() {
12 // *******************
13  ProposeStep();
14  // Does the MCMC accept this step?
16 
18  {
19  AcceptStep();
20  }
21 }
22 
23 // *******************
24 // Do the initial reconfigure of the MCMC
26 // *******************
27  // Initial likelihood
28  out_of_bounds = false;
29 
30  double llh = 0.0;
31 
32  // Loop over the systematics and propose the initial step
33  for (size_t s = 0; s < systematics.size(); ++s)
34  {
35  // Could throw the initial value here to do MCMC stability studies
36  // Propose the steps for the systematics
37  systematics[s]->ProposeStep();
38 
39  // Get the likelihood from the systematics
40  syst_llh[s] = systematics[s]->GetLikelihood();
41  llh += syst_llh[s];
42 
43 #ifdef DEBUG
44  if (debug)
45  debugFile << "LLH after " << systematics[s]->GetName() << " " << llh << std::endl;
46 #endif
47  }
48 
49  // Check if we've hit a boundary in the systematics
50  // In this case we can save time by not having to reconfigure the simulation
51  if (llh >= M3::_LARGE_LOGL_)
52  {
53  out_of_bounds = true;
54 #ifdef DEBUG
55  if (debug)
56  debugFile << "Rejecting based on boundary" << std::endl;
57 #endif
58  }
59 
60  // Only reweight when we have a good parameter configuration
61  // This speeds things up considerably because for every bad parameter configuration we don't have to reweight the MC
62  if (!out_of_bounds)
63  {
64  // Could multi-thread this
65  // But since sample reweight is multi-threaded it's probably better to do that
66  for (size_t i = 0; i < samples.size(); ++i)
67  {
68  samples[i]->Reweight();
69  }
70 
71  // DB for atmospheric event by event sample migration, need to fully reweight all samples to allow event passing prior to likelihood evaluation
72  for (size_t i = 0; i < samples.size(); ++i)
73  {
74  // Get the sample likelihoods and add them
75  sample_llh[i] = samples[i]->GetLikelihood();
76  llh += sample_llh[i];
77 #ifdef DEBUG
78  if (debug)
79  debugFile << "LLH after sample " << i << " " << llh << std::endl;
80 #endif
81  }
82 
83  // For when we don't have to reweight, set sample to madness
84  }
85  else
86  {
87  for (size_t i = 0; i < samples.size(); ++i)
88  {
89  // Set the sample_llh[i] to be madly high also to signify a step out of bounds
91 #ifdef DEBUG
92  if (debug)
93  debugFile << "LLH after REJECT sample " << i << " " << llh << std::endl;
94 #endif
95  }
96  }
97  // Save the proposed likelihood (class member)
98  logLProp = llh;
99 }
100 
101 // **********************
102 // Do we accept the proposed step for all the parameters?
104 // **********************
105  // Set the acceptance probability to zero
106  double acc_prob = 0.0;
107 
108  // Calculate acceptance probability
109  if (anneal)
110  acc_prob = std::min(1., std::exp(-(logLProp - logLCurr) / (std::exp(-step / AnnealTemp))));
111  else
112  acc_prob = std::min(1., std::exp(logLCurr - logLProp));
113 
114  return acc_prob;
115 }
MaCh3Plotting::PlottingManager * man
std::vector< SampleHandlerBase * > samples
Sample holder.
Definition: FitterBase.h:131
double logLProp
proposed likelihood
Definition: FitterBase.h:117
unsigned int step
current state
Definition: FitterBase.h:113
double accProb
current acceptance prob
Definition: FitterBase.h:119
std::string AlgorithmName
Name of fitting algorithm that is being used.
Definition: FitterBase.h:170
std::vector< double > sample_llh
store the llh breakdowns
Definition: FitterBase.h:126
double logLCurr
current likelihood
Definition: FitterBase.h:115
std::vector< double > syst_llh
systematic llh breakdowns
Definition: FitterBase.h:128
std::vector< ParameterHandlerBase * > systematics
Systematic holder.
Definition: FitterBase.h:136
Base class for MCMC fitting algorithms.
Definition: MCMCBase.h:8
bool anneal
simulated annealing
Definition: MCMCBase.h:70
void AcceptStep()
Accept a step.
Definition: MCMCBase.cpp:178
double AnnealTemp
simulated annealing temperature
Definition: MCMCBase.h:72
bool out_of_bounds
Do we reject based on hitting boundaries in systs.
Definition: MCMCBase.h:61
bool IsStepAccepted(const double acc_prob)
Is step accepted?
Definition: MCMCBase.cpp:160
void ProposeStep() override
Propose a step.
Definition: MR2T2.cpp:25
double AcceptanceProbability() override
Step acceptance probability.
Definition: MR2T2.cpp:103
MR2T2(manager *const manager)
Constructor.
Definition: MR2T2.cpp:5
void DoStep() override
The MCMC step proposal and acceptance.
Definition: MR2T2.cpp:11
The manager class is responsible for managing configurations and settings.
Definition: Manager.h:16
constexpr static const double _LARGE_LOGL_
Large Likelihood is used it parameter go out of physical boundary, this indicates in MCMC that such s...
Definition: Core.h:73