BCEngineMCMC.h
1 #ifndef __BCENGINEMCMC__H
2 #define __BCENGINEMCMC__H
3 
16 /*
17  * Copyright (C) 2007-2013, the BAT core developer team
18  * All rights reserved.
19  *
20  * For the licensing terms see doc/COPYING.
21  * For documentation see http://mpp.mpg.de/bat
22  */
23 
24 // ---------------------------------------------------------
25 
26 #include "BCH1D.h"
27 #include "BCH2D.h"
28 #include "BCLog.h"
29 #include "BCObservable.h"
30 #include "BCParameter.h"
31 #include "BCParameterSet.h"
32 
33 #include <TMatrixD.h>
34 #include <TMatrixDSym.h>
35 #include <TRandom3.h>
36 #include <TVectorD.h>
37 
38 #include <algorithm>
39 #include <limits>
40 #include <string>
41 #include <utility>
42 #include <vector>
43 
44 // ROOT classes
45 class TF1;
46 class TFile;
47 class TH1;
48 class TH2;
49 class TTree;
50 
51 class BCVariable;
52 
53 // ---------------------------------------------------------
54 
56 {
57 
58 public:
59 
65  enum Precision {
66  kLow,
67  kQuick,
68  kMedium,
69  kHigh,
70  kVeryHigh
71  };
72 
75  enum Phase {
76  kPreRun = -1,
78  kMainRun = +1
79  };
80 
87  };
88 
93 private:
94  // grant friendship to BCModel to access the ThreadLocalStorage
95  friend class BCModel;
96 
100  struct ThreadLocalStorage {
103  std::vector<double> parameters;
104 
107  double log_prior;
108 
111  double log_likelihood;
112 
115  double log_probability;
116 
119  TRandom3* rng;
120 
123  TVectorD yLocal;
124 
129  ThreadLocalStorage(unsigned dim);
130 
133  ThreadLocalStorage(const ThreadLocalStorage& other);
134 
137  ThreadLocalStorage& operator = (ThreadLocalStorage other);
138 
140  void swap(BCEngineMCMC::ThreadLocalStorage& A, BCEngineMCMC::ThreadLocalStorage& B);
141 
144  virtual ~ThreadLocalStorage();
145 
153  double scale(double dof);
154  };
155 
156 public:
157 
159  struct ChainState {
160  unsigned iteration;
161  std::vector<double> parameters;
162  std::vector<double> observables;
164  double log_likelihood;
165  double log_prior;
166 
168  ChainState(int n_obs = 0) : iteration(0),
169  observables(std::vector<double>(n_obs, 0.)),
170  log_probability(-std::numeric_limits<double>::infinity()),
171  log_likelihood(-std::numeric_limits<double>::infinity()),
172  log_prior(-std::numeric_limits<double>::infinity())
173  {}
174 
176  ChainState& operator=(const ThreadLocalStorage& tls)
177  {
178  parameters = tls.parameters;
179  log_prior = tls.log_prior;
180  log_likelihood = tls.log_likelihood;
181  log_probability = tls.log_probability;
182  return *this;
183  }
184  };
185 
187  struct Statistics {
188 
192  Statistics(unsigned n_par = 0, unsigned n_obs = 0);
193 
194  unsigned n_samples;
195  std::vector<double> mean;
196  std::vector<double> variance;
197  std::vector<double> stderrpar;
198  std::vector<double> stderrobs;
199  std::vector<std::vector<double> > covariance;
200  std::vector<double> minimum;
201  std::vector<double> maximum;
204  std::vector<double> modepar;
205  std::vector<double> modeobs;
208  std::vector<double> efficiency;
209 
213  void Clear(bool clear_mode = true, bool clear_efficiency = true);
214 
218  void Init(unsigned n_par, unsigned n_obs);
219 
223  void Reset(bool reset_mode = true, bool reset_efficiency = true);
224 
226  void ResetEfficiencies();
227 
229  Statistics& operator += (const Statistics& rhs);
230 
233  void Update(const ChainState& cs);
234  };
235 
242  BCEngineMCMC(const std::string& name = "model");
243 
246  BCEngineMCMC(const BCEngineMCMC& enginemcmc);
247 
254  BCEngineMCMC(const std::string& filename, const std::string& name, bool loadObservables = true);
255 
259 
262  virtual ~BCEngineMCMC();
263 
269  const std::string& GetName() const
270  { return fName; }
271 
274  const std::string& GetSafeName() const
275  { return fSafeName; }
276 
279  unsigned GetNChains() const
280  { return fMCMCNChains; }
281 
284  unsigned GetNLag() const
285  { return fMCMCNLag; }
286 
290  { return fMCMCCurrentIteration; }
291 
295  unsigned GetCurrentChain() const;
296 
303 
309  unsigned GetNIterationsPreRun() const;
310 
313  unsigned GetNIterationsPreRunMin() const
314  { return fMCMCNIterationsPreRunMin; }
315 
318  unsigned GetNIterationsPreRunMax() const
319  { return fMCMCNIterationsPreRunMax; }
320 
323  unsigned GetNIterationsRun() const
324  { return fMCMCNIterationsRun; }
325 
328  unsigned GetNIterationsPreRunCheck() const
329  { return fMCMCNIterationsPreRunCheck; }
330 
334  { return fMCMCPreRunCheckClear; }
335 
338  double GetMinimumEfficiency() const
339  { return fMCMCEfficiencyMin; }
340 
343  double GetMaximumEfficiency() const
344  { return fMCMCEfficiencyMax; }
345 
349  { return fMCMCScaleFactorLowerLimit; }
350 
354  { return fMCMCScaleFactorUpperLimit; }
355 
358  const std::vector<std::vector<double> >& GetScaleFactors() const
360 
364  const ChainState& GetChainState(unsigned c) const
365  { return fMCMCStates.at(c); }
366 
370  const std::vector<double>& Getx(unsigned c) const
371  { return fMCMCStates.at(c).parameters; }
372 
377  double Getx(unsigned c, unsigned p) const
378  { return fMCMCStates.at(c).parameters.at(p); }
379 
383  double GetLogProbx(unsigned c) const
384  { return fMCMCStates.at(c).log_probability; }
385 
389  { return fMCMCPhase; }
390 
394  { return fInitialPositionScheme; }
395 
399  { return fInitialPositionAttemptLimit; }
400 
404  { return fMCMCProposeMultivariate; }
405 
411  double GetProposalFunctionDof() const
412  { return fMCMCProposalFunctionDof; }
413 
418 
419  /*
420  * @return weighting parameter for multivariate proposal function covariance update. */
421  double GetMultivariateCovarianceUpdateLambda() const
423 
426  double GetMultivariateEpsilon() const
427  { return fMultivariateEpsilon; }
428 
432  { return fMultivariateScaleMultiplier; }
433 
438 
441  const std::vector<double>& GetRValueParameters() const
442  { return fMCMCRValueParameters; }
443 
447  double GetRValueParameters(unsigned index) const
448  { return fMCMCRValueParameters.at(index); }
449 
453 
456  bool GetFlagRun() const
457  { return fMCMCPhase == kMainRun; }
458 
461  TTree* GetMarkovChainTree() const
462  { return fMCMCTree;}
463 
466  TTree* GetParameterTree() const
467  { return fParameterTree;}
468 
471  TFile* GetOutputFile() const
472  { return fMCMCOutputFile; }
473 
477  { return fMCMCStatistics_AllChains; }
478 
482  const BCEngineMCMC::Statistics& GetStatistics(unsigned c) const
483  { return fMCMCStatistics.at(c); }
484 
487  const std::vector<BCEngineMCMC::Statistics>& GetStatisticsVector() const
488  { return fMCMCStatistics; }
489 
494 
498  { return fHistogramRescalePadding; }
499 
502  virtual std::vector<unsigned> GetH1DPrintOrder() const;
503 
506  virtual std::vector<std::pair<unsigned, unsigned> > GetH2DPrintOrder() const;
507 
511  bool MarginalizedHistogramExists(unsigned index) const
512  { return index < fH1Marginalized.size() and fH1Marginalized[index]; }
513 
518  bool MarginalizedHistogramExists(unsigned index1, unsigned index2) const
519  { return index1 < fH2Marginalized.size() and index2 < fH2Marginalized[index1].size() and fH2Marginalized[index1][index2]; }
520 
527  TH1* GetMarginalizedHistogram(const std::string& name) const
528  { return GetMarginalizedHistogram(fParameters.Index(name)); }
529 
535  TH1* GetMarginalizedHistogram(unsigned index) const;
536 
544  TH2* GetMarginalizedHistogram(const std::string& name1, const std::string& name2) const
545  { return GetMarginalizedHistogram(fParameters.Index(name1), fParameters.Index(name2)); }
546 
553  TH2* GetMarginalizedHistogram(unsigned index1, unsigned index2) const;
554 
561  BCH1D GetMarginalized(const std::string& name) const
562  { return GetMarginalized(fParameters.Index(name)); }
563 
569  BCH1D GetMarginalized(unsigned index) const;
570 
578  BCH2D GetMarginalized(const std::string& name1, const std::string& name2) const
579  { return GetMarginalized(fParameters.Index(name1), fParameters.Index(name2)); }
580 
587  BCH2D GetMarginalized(unsigned index1, unsigned index2) const;
588 
592  unsigned GetMaximumParameterNameLength(bool observables = true) const
593  { return (observables) ? std::max(fParameters.MaxNameLength(), fObservables.MaxNameLength()) : fParameters.MaxNameLength(); }
594 
600  BCVariable& GetVariable(unsigned index)
601  { return (index < GetNParameters()) ? static_cast<BCVariable&>(fParameters[index]) : static_cast<BCVariable&>(fObservables.At(index - GetNParameters())); }
602 
608  const BCVariable& GetVariable(unsigned index) const
609  { return (index < GetNParameters()) ? static_cast<const BCVariable&>(fParameters[index]) : static_cast<const BCVariable&>(fObservables.At(index - GetNParameters())); }
610 
613  unsigned GetNVariables() const
614  { return fParameters.Size() + fObservables.Size(); }
615 
619  { return fParameters; }
620 
624  { return fParameters; }
625 
630  BCParameter& GetParameter(unsigned index)
631  { return fParameters.At(index); }
632 
637  const BCParameter& GetParameter(unsigned index) const
638  { return fParameters.At(index); }
639 
644  BCParameter& GetParameter(const std::string& name)
645  { return fParameters.Get(name); }
646 
651  const BCParameter& GetParameter(const std::string& name) const
652  { return fParameters.Get(name); }
653 
656  unsigned GetNParameters() const
657  { return fParameters.Size(); }
658 
662  unsigned GetNFixedParameters() const
663  { return fParameters.GetNFixedParameters(); }
664 
668  unsigned GetNFreeParameters() const
669  { return fParameters.GetNFreeParameters(); }
670 
674  { return fObservables; }
675 
679  { return fObservables; }
680 
685  BCObservable& GetObservable(unsigned index)
686  { return fObservables.At(index); }
687 
692  const BCObservable& GetObservable(unsigned index) const
693  { return fObservables.At(index); }
694 
699  BCObservable& GetObservable(const std::string& name)
700  { return fObservables.Get(name); }
701 
706  const BCObservable& GetObservable(const std::string& name) const
707  { return fObservables.Get(name); }
708 
711  unsigned GetNObservables() const
712  { return fObservables.Size(); }
713 
716  virtual const std::vector<double>& GetBestFitParameters() const;
717 
720  virtual const std::vector<double>& GetBestFitParameterErrors() const;
721 
725  const std::vector<double>& GetLocalModes(bool force_recalculation = false);
726 
729  virtual double GetLogMaximum() const
731 
734  bool GetReuseObservables() const
735  { return fMCMCTreeReuseObservables; }
736 
740  { return fBCH1DdrawingOptions; }
741 
745  { return fBCH2DdrawingOptions; }
746 
754  void SetName(const std::string& name);
755 
760 
765 
770  void SetInitialScaleFactors(const std::vector<double>& scale)
771  { fMCMCInitialScaleFactors = scale; }
772 
775  void SetNChains(unsigned n)
776  { fMCMCNChains = n; }
777 
780  void SetNLag(unsigned n);
781 
784  void SetNIterationsPreRunMax(unsigned n)
786 
789  void SetNIterationsRun(unsigned n)
790  { fMCMCNIterationsRun = n; }
791 
794  void SetNIterationsPreRunMin(unsigned n)
796 
800  void SetNIterationsPreRunCheck(unsigned n)
802 
805  void SetPreRunCheckClear(unsigned n)
806  { fMCMCPreRunCheckClear = n; }
807 
810  void SetMinimumEfficiency(double efficiency)
811  { fMCMCEfficiencyMin = efficiency; }
812 
815  void SetMaximumEfficiency(double efficiency)
816  { fMCMCEfficiencyMax = efficiency; }
817 
820  void SetRandomSeed(unsigned seed);
821 
825  void SetInitialPositions(const std::vector<double>& x0s);
826 
830  void SetInitialPositions(const std::vector< std::vector<double> >& x0s)
832 
836  { fInitialPositionScheme = scheme; }
837 
842 
859  void SetProposeMultivariate(bool flag)
860  {
862  BCLog::OutWarning("You have changed the proposal function flag, but not required the prerun be rerun.");
864  }
865 
878  void SetProposalFunctionDof(double dof = 1)
879  {
881  }
882 
887  { fMultivariateCovarianceUpdateLambda = std::max<double>(0, std::min<double>(1, l)); }
888 
891  void SetMultivariateEpsilon(double epsilon)
892  { fMultivariateEpsilon = epsilon; }
893 
898 
901  void SetFlagFillHistograms(bool flag)
903 
906  void SetFlagFillHistograms(bool flag_1d, bool flag_2d)
907  { fParameters.FillHistograms(flag_1d, flag_2d); fObservables.FillHistograms(flag_1d, flag_2d); }
908 
913  void SetFillHistogramParPar(unsigned x, unsigned y, bool flag = true)
914  { SetFillHistogram(x, y, flag); }
915 
920  void SetFillHistogramParPar(const std::string& x, const std::string& y, bool flag = true)
922 
927  void SetFillHistogramParObs(unsigned x, unsigned y, bool flag = true)
928  { SetFillHistogram(x, -(y + 1), flag); }
929 
934  void SetFillHistogramParObs(const std::string& x, const std::string& y, bool flag = true)
936 
941  void SetFillHistogramObsObs(unsigned x, unsigned y, bool flag = true)
942  { SetFillHistogram(-(x + 1), -(y + 1), flag); }
943 
948  void SetFillHistogramObsObs(const std::string& x, const std::string& y, bool flag = true)
950 
955  void SetFillHistogramObsPar(unsigned x, unsigned y, bool flag = true)
956  { SetFillHistogram(-(x + 1), y, flag); }
957 
962  void SetFillHistogramObsPar(const std::string& x, const std::string& y, bool flag = true)
964 
966  void SetFlagPreRun(bool flag)
967  { if (flag) fMCMCPhase = kUnsetPhase; }
968 
973 
977 
980  void SetPrecision(BCEngineMCMC::Precision precision);
981 
984  void SetPrecision(const BCEngineMCMC* other)
985  { if (other) SetPrecision(*other); }
986 
989  void SetPrecision(const BCEngineMCMC& other);
990 
994  void SetNbins(unsigned int nbins)
995  { fParameters.SetNBins(nbins); fObservables.SetNBins(nbins); }
996 
999  void SetReuseObservables(bool flag)
1000  { fMCMCTreeReuseObservables = flag; }
1001 
1006 
1009  void SetHistogramRescalingPadding(double factor)
1010  { fHistogramRescalePadding = factor; }
1011 
1016  void WriteMarkovChain(bool flag)
1018 
1023  void WriteMarkovChainRun(bool flag);
1024 
1029  void WriteMarkovChainPreRun(bool flag);
1030 
1037  void WriteMarkovChain(const std::string& filename, const std::string& option, bool flag_run = true, bool flag_prerun = true);
1038 
1051  void SetPriorConstant(unsigned index)
1052  { fParameters.At(index).SetPriorConstant(); }
1053 
1058  void SetPriorConstant(const std::string& name)
1059  { SetPriorConstant(fParameters.Index(name)); }
1060 
1067  void SetPrior(unsigned index, TF1& f, bool logL = true);
1068 
1075  void SetPrior(const std::string& name, TF1& f, bool logL = true)
1076  { return SetPrior(fParameters.Index(name), f, logL); }
1077 
1083  void SetPriorDelta(unsigned index, double value)
1084  { fParameters.At(index).Fix(value); }
1085 
1091  void SetPriorDelta(const std::string& name, double value)
1092  { SetPriorDelta(fParameters.Index(name), value); }
1093 
1100  void SetPriorGauss(unsigned index, double mean, double sigma);
1101 
1108  void SetPriorGauss(const std::string& name, double mean, double sigma)
1109  { SetPriorGauss(fParameters.Index(name), mean, sigma); }
1110 
1118  void SetPriorGauss(unsigned index, double mode, double sigma_below, double sigma_above);
1119 
1127  void SetPriorGauss(const std::string& name, double mode, double sigma_below, double sigma_above)
1128  { SetPriorGauss(fParameters.Index(name), mode, sigma_below, sigma_above); }
1129 
1136  void SetPrior(unsigned index, TH1& h, bool interpolate = false);
1137 
1145  void SetPrior(const std::string& name, TH1& h, bool interpolate = false)
1146  { SetPrior(fParameters.Index(name), h, interpolate); }
1147 
1152 
1163  void WriteMarginalizedDistributions(const std::string& filename, const std::string& option, bool closeExistingFile = false);
1164 
1167  virtual void PrintSummary() const;
1168 
1173  void PrintParameters(const std::vector<double>& P, void (*output)(const std::string&) = BCLog::OutSummary) const;
1174 
1181  unsigned PrintAllMarginalized(const std::string& filename, unsigned hdiv = 1, unsigned vdiv = 1) const;
1182 
1191  unsigned PrintParameterPlot(const std::string& filename, int npar = 10, double interval_content = 68e-2, std::vector<double> quantile_values = std::vector<double>(0), bool rescale_ranges = true) const;
1192 
1201  bool DrawParameterPlot(unsigned i0, unsigned npar = 0, double interval_content = 68e-2, std::vector<double> quantile_values = std::vector<double>(0), bool rescale_ranges = true) const;
1202 
1207  bool PrintCorrelationMatrix(const std::string& filename = "matrix.pdf") const;
1208 
1214  bool PrintCorrelationPlot(const std::string& filename = "correlation.pdf", bool include_observables = true) const;
1215 
1220  bool PrintParameterLatex(const std::string& filename) const;
1221 
1229  virtual void CreateHistograms(bool rescale_ranges = false);
1230 
1235  virtual void InitializeMarkovChainTree(bool replacetree = false, bool replacefile = false);
1236 
1246  virtual bool AddParameter(const std::string& name, double min, double max, const std::string& latexname = "", const std::string& unitstring = "")
1247  { return fParameters.Add(name, min, max, latexname, unitstring); }
1248 
1254  virtual bool AddParameter(BCParameter& parameter)
1255  { return fParameters.Add(parameter); }
1256 
1266  virtual bool AddObservable(const std::string& name, double min, double max, const std::string& latexname = "", const std::string& unitstring = "")
1267  { return fObservables.Add(name, min, max, latexname, unitstring); }
1268 
1274  virtual bool AddObservable(BCObservable& obs)
1275  { return fObservables.Add(obs); }
1276 
1280  virtual void EvaluateObservables();
1281 
1286  virtual void EvaluateObservables(unsigned chain);
1287 
1292  virtual void CalculateObservables(const std::vector<double>& pars)
1293  { (void)pars; }
1294 
1302  virtual double ProposalFunction(unsigned ichain, unsigned ipar);
1303 
1309  bool GetProposalPointMetropolis(unsigned chain, std::vector<double>& x);
1310 
1317  bool GetProposalPointMetropolis(unsigned chain, unsigned parameter, std::vector<double>& x);
1318 
1322  bool GetNewPointMetropolis();
1323 
1328  bool GetNewPointMetropolis(unsigned chain);
1329 
1335  bool GetNewPointMetropolis(unsigned chain, unsigned parameter);
1336 
1342  bool AcceptOrRejectPoint(unsigned chain, unsigned parameter);
1343 
1346  void InChainFillHistograms(const ChainState& cs);
1347 
1350  void InChainFillHistograms();
1351 
1354  void InChainFillTree(const ChainState& cs, unsigned chain_number);
1355 
1358  void InChainFillTree();
1359 
1364  virtual double LogEval(const std::vector<double>& parameters) = 0;
1365 
1369  bool Metropolis();
1370 
1374  bool MetropolisPreRun();
1375 
1386  static double RValue(const std::vector<double>& means, const std::vector<double>& variances, unsigned n, bool correctForSamplingVariability = true);
1387 
1390  void MCMCInitialize();
1391 
1404  virtual void MCMCUserInitialize()
1405  {}
1406 
1409  virtual void ResetResults();
1410 
1429  {}
1430 
1441  virtual void MCMCCurrentPointInterface(const std::vector<double>& point, int ichain, bool accepted)
1442  {
1443  (void)point;
1444  (void)ichain;
1445  (void)accepted;
1446  }
1447 
1452  void LoadParametersFromTree(TTree* partree, bool loadObservables = true);
1453 
1457  void LoadMCMCParameters(TTree& partree);
1458 
1464  virtual bool ParameterTreeMatchesModel(TTree* partree, bool checkObservables = true);
1465 
1472  void LoadMCMC(const std::string& filename, std::string mcmcTreeName = "", std::string parameterTreeName = "", bool loadObservables = true);
1473 
1479  void LoadMCMC(TTree* mcmcTree, TTree* parTree, bool loadObservables = true);
1480 
1486  bool ValidMCMCTree(TTree* tree, bool checkObservables = true) const;
1487 
1492  bool ValidParameterTree(TTree* tree) const;
1493 
1496  void CloseOutputFile();
1497 
1501  virtual void Remarginalize(bool autorange = true);
1502 
1505  void PrepareToContinueMarginalization(const std::string& filename, const std::string& mcmcTreeName = "", const std::string& parameterTreeName = "", bool loadObservables = true, bool autorange = true);
1506 
1510  virtual bool UpdateMultivariateProposalFunctionCovariances(double a);
1511 
1515 
1519 
1525  void UpdateChainIndex(int chain);
1526 
1529 private:
1530 
1533  std::vector<ThreadLocalStorage> fMCMCThreadLocalStorage;
1534 
1537  void SyncThreadStorage();
1538 
1542  typedef std::vector<unsigned> ChainIndex_t;
1543  ChainIndex_t fChainIndex;
1544 
1547  void DeleteMarginals();
1548 
1551  void CloneMarginals(const BCEngineMCMC&);
1552 
1553 protected:
1554 
1562  void SetFillHistogram(int x, int y, bool flag);
1563 
1566  virtual void PrintModelSummary() const;
1567 
1570  virtual void PrintBestFitSummary() const;
1571 
1575  virtual std::string GetBestFitSummary(unsigned i) const;
1576 
1579  virtual void PrintMarginalizationSummary() const;
1580 
1583  void UpdateParameterTree();
1584 
1589  unsigned UpdateFrequency(unsigned N) const;
1590 
1593  std::string fName;
1594 
1597  std::string fSafeName;
1598 
1602 
1606 
1609  unsigned fMCMCNChains;
1610 
1613  unsigned fMCMCNLag;
1614 
1619 
1624 
1628 
1633 
1637 
1641 
1645 
1649 
1653 
1657 
1660  std::string fMCMCOutputFilename;
1661 
1665 
1669 
1673 
1678  std::vector<std::vector<double> > fMCMCProposalFunctionScaleFactor;
1679 
1682  std::vector<double> fMCMCInitialScaleFactors;
1683 
1687 
1692 
1696 
1700 
1704 
1708 
1714  std::vector<std::vector<double> > fMCMCInitialPosition;
1715 
1719 
1723 
1728 
1732 
1736 
1741 
1745 
1748  std::vector<ChainState> fMCMCStates;
1749 
1752  std::vector<BCEngineMCMC::Statistics> fMCMCStatistics;
1753 
1757 
1761 
1765 
1767  std::vector<double> fMCMCRValueParameters;
1768 
1771  TRandom3 fRandom;
1772 
1775  std::vector<TH1*> fH1Marginalized;
1776 
1779  std::vector<std::vector<TH2*> > fH2Marginalized;
1780 
1785  std::vector<std::pair<int, int> > fRequestedH2;
1786 
1789  TTree* fMCMCTree;
1790 
1794 
1798 
1802 
1805  unsigned int fMCMCTree_Chain;
1806 
1810 
1813  std::vector<double> fLocalModes;
1814 
1818 
1822 
1826 
1830 
1833 
1834 };
1835 
1836 // ---------------------------------------------------------
1837 
1838 #endif
void SetProposeMultivariate(bool flag)
Set flag to true to turn on the multivariate proposal for MCMC based on (Haario et al...
Definition: BCEngineMCMC.h:859
const BCParameterSet & GetParameters() const
Definition: BCEngineMCMC.h:623
BCEngineMCMC & operator=(const BCEngineMCMC &)
Copy-assignment operator.
std::vector< double > maximum
maximum value of variables
Definition: BCEngineMCMC.h:201
BCH2D fBCH2DdrawingOptions
A BCH2D (with no histogram) for storing BCH2D drawing options.
InitialPositionScheme
An enumerator for markov-chain position initialization.
Definition: BCEngineMCMC.h:82
void SetNIterationsPreRunCheck(unsigned n)
Sets the number of iterations between scale adjustments and convergence checks in the pre-run...
Definition: BCEngineMCMC.h:800
double GetMinimumEfficiency() const
Definition: BCEngineMCMC.h:338
void SetPrior(const std::string &name, TH1 &h, bool interpolate=false)
void SetMinimumEfficiency(double efficiency)
Sets the minimum efficiency required for a chain.
Definition: BCEngineMCMC.h:810
virtual void ResetResults()
Reset the MCMC variables.
bool GetRescaleHistogramRangesAfterPreRun() const
Definition: BCEngineMCMC.h:492
std::vector< TMatrixDSym > fMultivariateProposalFunctionCovariance
Covariance matrices used in multivariate proposal functions.
void SetPrecision(const BCEngineMCMC *other)
Copy precision for the MCMC run from other model.
Definition: BCEngineMCMC.h:984
void SetNIterationsPreRunMax(unsigned n)
Sets the maximum number of iterations in the pre-run.
Definition: BCEngineMCMC.h:784
bool MetropolisPreRun()
Runs a pre run for the Metropolis algorithm.
bool MarginalizedHistogramExists(unsigned index) const
Definition: BCEngineMCMC.h:511
ChainState fMCMCTree_State
MC state object for storing into tree.
std::vector< std::vector< double > > fMCMCInitialPosition
The intial position of each Markov chain.
void SetName(const std::string &name)
Sets the name of the engine.
double GetScaleFactorUpperLimit() const
Definition: BCEngineMCMC.h:353
void SetFillHistogramParObs(const std::string &x, const std::string &y, bool flag=true)
Sets whether to fill particular H2 histogram: obs(y) vs.
Definition: BCEngineMCMC.h:934
BCObservable & GetObservable(unsigned index)
Definition: BCEngineMCMC.h:685
virtual unsigned Index(const std::string &name) const
Find index of parameter identified by name; return Size() if name not found.
const std::vector< BCEngineMCMC::Statistics > & GetStatisticsVector() const
Get vector of MCMC statistics for each chain separately.
Definition: BCEngineMCMC.h:487
BCObservableSet fObservables
User-calculated Observables Set.
void SetFillHistogramObsPar(const std::string &x, const std::string &y, bool flag=true)
Sets whether to fill particular H2 histogram: par(y) vs.
Definition: BCEngineMCMC.h:962
void SetNLag(unsigned n)
Sets the lag of the Markov chains.
virtual unsigned Size() const
Number of variables contained.
virtual void Remarginalize(bool autorange=true)
Marginalize from TTree.
bool fCorrectRValueForSamplingVariability
flag for correcting R value for initial sampling variability.
void SetProposalFunctionDof(double dof=1)
Set the degree of freedom of the proposal function for MCMC.
Definition: BCEngineMCMC.h:878
const BCObservable & GetObservable(const std::string &name) const
Definition: BCEngineMCMC.h:706
BCObservableSet & GetObservables()
Definition: BCEngineMCMC.h:673
virtual bool Fix(double value)
Fix parameter to value (set prior to delta).
Definition: BCParameter.h:141
unsigned n_samples
number of samples used to calculate statistics
Definition: BCEngineMCMC.h:194
void InChainFillTree()
Write all chain states to the tree.
virtual void CalculateObservables(const std::vector< double > &pars)
Evaluates user-defined observables.
unsigned GetNChains() const
Definition: BCEngineMCMC.h:279
TTree * GetMarkovChainTree() const
Retrieve the tree containing the Markov chain.
Definition: BCEngineMCMC.h:461
virtual unsigned int GetNFixedParameters() const
virtual ~BCEngineMCMC()
Destructor.
virtual bool AddParameter(const std::string &name, double min, double max, const std::string &latexname="", const std::string &unitstring="")
void UpdateChainIndex(int chain)
Keep track of which chain is currently computed (within a thread).
TTree * fParameterTree
The tree containing the parameter information.
void LoadMCMC(const std::string &filename, std::string mcmcTreeName="", std::string parameterTreeName="", bool loadObservables=true)
Load previous MCMC run.
unsigned n_samples_efficiency
number of samples used to calculate efficiencies
Definition: BCEngineMCMC.h:207
virtual void MCMCUserIterationInterface()
Interface allowing to execute arbitrary code for each iteration of the MCMC while running the chains ...
bool GetNewPointMetropolis()
Generate a new point using the Metropolis algorithm for all chains.
std::string fMCMCOutputFileOption
Output file open option for for writing MCMC Tree.
static double RValue(const std::vector< double > &means, const std::vector< double > &variances, unsigned n, bool correctForSamplingVariability=true)
Calculate R value of set of batches of samples—represented by their means and variances, all batches containing the same number of samples—according to Brooks & Gelman, "General Methods for Monitoring Convergence of Iterative Simulations," (1988)
const BCParameter & GetParameter(const std::string &name) const
Definition: BCEngineMCMC.h:651
const BCParameter & GetParameter(unsigned index) const
Definition: BCEngineMCMC.h:637
Wrapper to allow access by name into list of BCParameter.
bool Metropolis()
Runs Metropolis algorithm.
virtual std::vector< std::pair< unsigned, unsigned > > GetH2DPrintOrder() const
virtual void PrintBestFitSummary() const
Print best fit to log.
void SetMultivariateCovarianceUpdateLambda(double l)
Set weighting for multivariate proposal function covariance update.
Definition: BCEngineMCMC.h:886
std::vector< std::vector< double > > fMCMCProposalFunctionScaleFactor
Scale factors for proposal functions.
std::string fMCMCOutputFilename
Output filename for for writing MCMC Tree.
double GetMultivariateScaleMultiplier() const
Definition: BCEngineMCMC.h:431
BCParameter & GetParameter(unsigned index)
Definition: BCEngineMCMC.h:630
TTree * fMCMCTree
The tree containing the Markov chains.
const std::vector< double > & GetLocalModes(bool force_recalculation=false)
void SetInitialPositions(const std::vector< std::vector< double > > &x0s)
Sets the initial positions for all chains.
Definition: BCEngineMCMC.h:830
void WriteMarginalizedDistributions(const std::string &filename, const std::string &option, bool closeExistingFile=false)
Write marginalization histograms to file.
double GetRValueParameters(unsigned index) const
Definition: BCEngineMCMC.h:447
unsigned fMultivariateCovarianceUpdates
Number of multivariate-proposal-function covariance updates performed.
unsigned GetInitialPositionAttemptLimit() const
Definition: BCEngineMCMC.h:398
The base class for all user-defined models.
Definition: BCModel.h:39
const BCObservable & GetObservable(unsigned index) const
Definition: BCEngineMCMC.h:692
A class for handling 2D distributions.
Definition: BCH2D.h:37
double probability_mean
mean of probability
Definition: BCEngineMCMC.h:202
unsigned GetNIterationsPreRunCheck() const
Definition: BCEngineMCMC.h:328
unsigned PrintParameterPlot(const std::string &filename, int npar=10, double interval_content=68e-2, std::vector< double > quantile_values=std::vector< double >(0), bool rescale_ranges=true) const
Print a summary plot for the parameters and user-defined observables.
TTree * GetParameterTree() const
Retrieve the tree containing the parameter information.
Definition: BCEngineMCMC.h:466
A class representing a variable of a model.
Definition: BCVariable.h:35
void WriteMarkovChain(bool flag)
Turn on/off writing of Markov chain to root file.
Phase
An enumerator for the phase of the Markov chain.
Definition: BCEngineMCMC.h:75
const BCEngineMCMC::Statistics & GetStatistics() const
Get combined statistics for all chains.
Definition: BCEngineMCMC.h:476
void CalculateCholeskyDecompositions()
Calculate Cholesky decompositions needed for multivariate proposal function.
double fMCMCScaleFactorLowerLimit
Lower limit for scale factors.
void PrintParameters(const std::vector< double > &P, void(*output)(const std::string &)=BCLog::OutSummary) const
Print parameters.
BCH1D fBCH1DdrawingOptions
A BCH1D (with no histogram) for storing BCH1D drawing options.
std::vector< std::pair< int, int > > fRequestedH2
Vector of pairs of indices for which 2D histograms should be stored.
unsigned GetNIterationsPreRunMax() const
Definition: BCEngineMCMC.h:318
unsigned GetNLag() const
Definition: BCEngineMCMC.h:284
double log_prior
log(prior)
Definition: BCEngineMCMC.h:165
bool PrintCorrelationPlot(const std::string &filename="correlation.pdf", bool include_observables=true) const
Print a correlation plot for the parameters.
void SetFlagPreRun(bool flag)
Set if a (new) prerun should be performed.
Definition: BCEngineMCMC.h:966
BCH2D & GetBCH2DdrawingOptions()
Definition: BCEngineMCMC.h:744
virtual bool Add(const T &var)
Add a variable if no variable of same name exists yet.
Definition: BCVariableSet.h:56
virtual void CreateHistograms(bool rescale_ranges=false)
Create histograms from parameter and observable sets.
A class representing a variable of a model.
Definition: BCObservable.h:32
const std::vector< double > & GetRValueParameters() const
Definition: BCEngineMCMC.h:441
void SetFillHistogramObsPar(unsigned x, unsigned y, bool flag=true)
Sets whether to fill particular H2 histogram: par(y) vs.
Definition: BCEngineMCMC.h:955
virtual void FillHistograms(bool flag)
Set fill-histograms flag for 1D and 2D histograms for all parameters.
randomly distribute according to factorized priors
Definition: BCEngineMCMC.h:86
std::vector< double > modepar
mode of parameters
Definition: BCEngineMCMC.h:204
bool GetProposalPointMetropolis(unsigned chain, std::vector< double > &x)
Return a proposal point for the Metropolis algorithm.
std::vector< double > efficiency
efficiencies for each parameter (NB: not stored for observables)
Definition: BCEngineMCMC.h:208
virtual bool ParameterTreeMatchesModel(TTree *partree, bool checkObservables=true)
Check parameter tree against model.
bool PrintParameterLatex(const std::string &filename) const
Print a LaTeX table of the parameters.
void SetRescaleHistogramRangesAfterPreRun(bool flag=true)
Set flag for rescaling histogram ranges after pre-run.
TH2 * GetMarginalizedHistogram(const std::string &name1, const std::string &name2) const
Obtain the individual marginalized distributions with respect to two parameters as a ROOT TH2...
Definition: BCEngineMCMC.h:544
bool GetCorrectRValueForSamplingVariability() const
Flag for correcting convergence checking for initial sampling variability.
Definition: BCEngineMCMC.h:451
unsigned fInitialPositionAttemptLimit
Maximum number of attempts to make to set the initial position.
void SetNIterationsRun(unsigned n)
Sets the number of iterations.
Definition: BCEngineMCMC.h:789
void SetPrior(unsigned index, TF1 &f, bool logL=true)
void SetScaleFactorUpperLimit(double l)
Set scale factor upper limit.
Definition: BCEngineMCMC.h:763
const BCEngineMCMC::Statistics & GetStatistics(unsigned c) const
Get MCMC statistics for one chain.
Definition: BCEngineMCMC.h:482
bool GetFlagRun() const
Definition: BCEngineMCMC.h:456
double GetHistogramRescalePadding() const
Definition: BCEngineMCMC.h:497
void SetPrior(const std::string &name, TF1 &f, bool logL=true)
unsigned GetMaximumParameterNameLength(bool observables=true) const
Definition: BCEngineMCMC.h:592
virtual void MCMCCurrentPointInterface(const std::vector< double > &point, int ichain, bool accepted)
Interface allowing to execute arbitrary code for each new point of the MCMC whether it is accepted or...
double fMCMCProposalFunctionDof
Degree of freedom of Student&#39;s t proposal.
std::vector< double > observables
observables at parameter point
Definition: BCEngineMCMC.h:162
double fMCMCEfficiencyMax
The maximum allowed efficiency for MCMC.
bool DrawParameterPlot(unsigned i0, unsigned npar=0, double interval_content=68e-2, std::vector< double > quantile_values=std::vector< double >(0), bool rescale_ranges=true) const
Draw a summary plot for the parameters in the range provided to current pad.
unsigned GetMultivariateCovarianceUpdates() const
Definition: BCEngineMCMC.h:416
void SetPriorConstantAll()
unsigned GetNObservables() const
Definition: BCEngineMCMC.h:711
double fMCMCEfficiencyMin
The minimum required efficiency for MCMC.
virtual void MCMCUserInitialize()
User hook called from MCMCInitialize().
unsigned fMCMCNIterationsPreRunMin
Minimum number of iterations for the pre-run.
void SetInitialPositionScheme(BCEngineMCMC::InitialPositionScheme scheme)
Sets flag which defines initial position.
Definition: BCEngineMCMC.h:835
std::string fName
Name of the engine.
void UpdateParameterTree()
Update Paramater TTree with scales and efficiencies.
virtual unsigned int GetNFreeParameters() const
int fMCMCNIterationsConvergenceGlobal
Number of iterations needed for all chains to convergence simultaneously.
virtual double GetLogMaximum() const
Definition: BCEngineMCMC.h:729
void SetPrecision(BCEngineMCMC::Precision precision)
Set the precision for the MCMC run.
std::vector< double > fMCMCInitialScaleFactors
User-provided initial values of the scale factors of the factorized proposal function.
void SetReuseObservables(bool flag)
Definition: BCEngineMCMC.h:999
virtual std::vector< unsigned > GetH1DPrintOrder() const
BCAux::BCTrash< TObject > fObjectTrash
Storage for plot objects with proper clean-up.
initialize to user-provided points
Definition: BCEngineMCMC.h:85
bool fMCMCProposeMultivariate
Flag for using multivariate proposal function.
BCObservable & GetObservable(const std::string &name)
Definition: BCEngineMCMC.h:699
virtual void InitializeMarkovChainTree(bool replacetree=false, bool replacefile=false)
Initialize the trees containing the Markov chains and parameter info.
double fHistogramRescalePadding
factor for enlarging range of histograms when rescaling.
double fMultivariateEpsilon
multivariate-proposal-function cholesky-decomposition nudge.
virtual const std::vector< double > & GetBestFitParameterErrors() const
A struct for holding statistical information about samples.
Definition: BCEngineMCMC.h:187
std::vector< TMatrixD > fMultivariateProposalFunctionCholeskyDecomposition
Cholesky decompositions for multivariate proposal function.
void SetNbins(unsigned int nbins)
Set the number of bins for the marginalized distribution of all parameters.
Definition: BCEngineMCMC.h:994
int GetNIterationsConvergenceGlobal() const
Definition: BCEngineMCMC.h:301
bool fMCMCFlagWritePreRunToFile
Flag to write pre run to file.
virtual bool AddObservable(const std::string &name, double min, double max, const std::string &latexname="", const std::string &unitstring="")
void SetRValueParametersCriterion(double r)
Sets the parameter R-value criterion for convergence of all chains.
Definition: BCEngineMCMC.h:971
select centers of parameter ranges
Definition: BCEngineMCMC.h:83
std::vector< double > variance
variances of all variables
Definition: BCEngineMCMC.h:196
virtual void PrintModelSummary() const
Print model summary to log.
BCEngineMCMC::Statistics fMCMCStatistics_AllChains
Statistics across all Markov chains.
void SetNChains(unsigned n)
Sets the number of Markov chains which are run in parallel.
Definition: BCEngineMCMC.h:775
std::vector< double > stderrobs
sqrt(variance) of all observables
Definition: BCEngineMCMC.h:198
unsigned fMCMCPreRunCheckClear
Number of iterations between clearing of convergence stats in pre-run.
unsigned fMCMCNIterationsRun
Number of iterations for a Markov chain run.
A class representing a parameter of a model.
Definition: BCParameter.h:34
const std::vector< std::vector< double > > & GetScaleFactors() const
Definition: BCEngineMCMC.h:358
TFile * GetOutputFile() const
Retrieve output file for MCMC.
Definition: BCEngineMCMC.h:471
const std::string & GetName() const
Definition: BCEngineMCMC.h:269
unsigned PrintAllMarginalized(const std::string &filename, unsigned hdiv=1, unsigned vdiv=1) const
Print all marginalizations.
std::vector< double > parameters
parameter point
Definition: BCEngineMCMC.h:161
ChainState(int n_obs=0)
Constructor.
Definition: BCEngineMCMC.h:168
An engine class for Markov Chain Monte Carlo.
Definition: BCEngineMCMC.h:55
bool MarginalizedHistogramExists(unsigned index1, unsigned index2) const
Definition: BCEngineMCMC.h:518
virtual void PrintMarginalizationSummary() const
Print marginalization to log.
std::vector< std::vector< TH2 * > > fH2Marginalized
Vector of 2D marginalized distributions.
std::string fSafeName
Safe name of the engine for use in naming ROOT objects.
double fMCMCScaleFactorUpperLimit
Upper limit for scale factors.
double log_probability
log(probability)
Definition: BCEngineMCMC.h:163
bool fMCMCTreeLoaded
flag for whether MCMC Tree successfully loaded.
std::vector< BCEngineMCMC::Statistics > fMCMCStatistics
Statistics for each Markov chain.
virtual double LogEval(const std::vector< double > &parameters)=0
Needs to be overloaded in the derived class.
std::vector< TH1 * > fH1Marginalized
Vector of 1D marginalized distributions.
void SetFillHistogramObsObs(const std::string &x, const std::string &y, bool flag=true)
Sets whether to fill particular H2 histogram: obs(y) vs.
Definition: BCEngineMCMC.h:948
void SetMultivariateEpsilon(double epsilon)
Sets multivariate-proposal-function cholesky-decomposition nudge.
Definition: BCEngineMCMC.h:891
bool fMCMCTreeReuseObservables
flag for whether to reuse MCMC Tree&#39;s observables.
virtual bool UpdateMultivariateProposalFunctionCovariances()
Update multivariate proposal function covariances.
unsigned fMCMCNChains
Number of Markov chains ran in parallel.
bool ValidParameterTree(TTree *tree) const
Check tree structure for parameter tree.
double GetRValueParametersCriterion() const
Definition: BCEngineMCMC.h:436
std::vector< double > mean
means of all variables
Definition: BCEngineMCMC.h:195
bool GetProposeMultivariate() const
Definition: BCEngineMCMC.h:403
virtual void SetPriorConstantAll()
Set all priors to constant.
std::vector< double > minimum
minimum value of variables
Definition: BCEngineMCMC.h:200
void LoadMCMCParameters(TTree &partree)
Load MCMC parameters from parameter tree: nchains, proposal function type, scales.
void WriteMarkovChainRun(bool flag)
Turn on/off writing of Markov chain to root file during run.
void SetScaleFactorLowerLimit(double l)
Set scale factor lower limit.
Definition: BCEngineMCMC.h:758
const ChainState & GetChainState(unsigned c) const
Definition: BCEngineMCMC.h:364
const std::vector< double > & Getx(unsigned c) const
Definition: BCEngineMCMC.h:370
void SetFillHistogramObsObs(unsigned x, unsigned y, bool flag=true)
Sets whether to fill particular H2 histogram: obs(y) vs.
Definition: BCEngineMCMC.h:941
void SetFillHistogramParObs(unsigned x, unsigned y, bool flag=true)
Sets whether to fill particular H2 histogram: obs(y) vs.
Definition: BCEngineMCMC.h:927
std::vector< ChainState > fMCMCStates
The current states of each Markov chain.
void SetFlagFillHistograms(bool flag_1d, bool flag_2d)
Sets the whether to fill histograms.
Definition: BCEngineMCMC.h:906
void SetPriorGauss(unsigned index, double mean, double sigma)
void LoadParametersFromTree(TTree *partree, bool loadObservables=true)
Load parameters and observables from tree.
BCEngineMCMC::InitialPositionScheme GetInitialPositionScheme() const
Definition: BCEngineMCMC.h:393
double GetProposalFunctionDof() const
Definition: BCEngineMCMC.h:411
bool PrintCorrelationMatrix(const std::string &filename="matrix.pdf") const
Print a correlation matrix for the parameters.
const std::string & GetSafeName() const
Definition: BCEngineMCMC.h:274
bool GetReuseObservables() const
Definition: BCEngineMCMC.h:734
void SetInitialPositionAttemptLimit(unsigned n)
Sets maximum number of attempts to find a valid initial position.
Definition: BCEngineMCMC.h:840
TRandom3 fRandom
Random number generator.
std::vector< double > stderrpar
sqrt(variance) of all parameters
Definition: BCEngineMCMC.h:197
BCEngineMCMC::InitialPositionScheme fInitialPositionScheme
Variable which defines the initial position.
A class for handling 1D distributions.
Definition: BCH1D.h:34
void MCMCInitialize()
Resets all containers used in MCMC and initializes starting points.
unsigned GetNIterationsPreRun() const
const BCVariable & GetVariable(unsigned index) const
Definition: BCEngineMCMC.h:608
double GetLogProbx(unsigned c) const
Definition: BCEngineMCMC.h:383
virtual const std::vector< double > & GetBestFitParameters() const
unsigned GetPreRunCheckClear()
Definition: BCEngineMCMC.h:333
BCParameterSet fParameters
Parameter settings.
unsigned GetNFixedParameters() const
Definition: BCEngineMCMC.h:662
void SetPriorGauss(const std::string &name, double mean, double sigma)
virtual bool AddObservable(BCObservable &obs)
void SetFillHistogram(int x, int y, bool flag)
Set whether to fill 2D histogram y vs x: positive indices for parameters; negative for observables...
virtual std::string GetBestFitSummary(unsigned i) const
Get string summarizing best fit for single variable.
void SetPriorConstant(const std::string &name)
bool fMCMCFlagWriteChainToFile
Flag to write Markov chains to file.
double log_likelihood
log(likelihood)
Definition: BCEngineMCMC.h:164
double fMultivariateScaleMultiplier
factor to multiply or divide scale factors by in adjusting multivariate-proposal-function scales...
TH1 * GetMarginalizedHistogram(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter as a ROOT TH1...
Definition: BCEngineMCMC.h:527
unsigned fMCMCNIterationsPreRunCheck
Number of iterations between scale adjustments and convergence checks in pre-run. ...
unsigned GetNIterationsPreRunMin() const
Definition: BCEngineMCMC.h:313
double GetScaleFactorLowerLimit() const
Definition: BCEngineMCMC.h:348
BCH2D GetMarginalized(const std::string &name1, const std::string &name2) const
Obtain the individual marginalized distributions with respect to two parameters.
Definition: BCEngineMCMC.h:578
void SetMultivariateScaleMultiplier(double s)
Sets multivariate-proposal-function scale multiplier.
Definition: BCEngineMCMC.h:896
int fMCMCCurrentIteration
The current iteration number.
TFile * fMCMCOutputFile
Output file for for writing MCMC Tree.
virtual void EvaluateObservables()
Evaluates user-defined observables at current state of all chains and stores results in fMCMCState...
virtual void PrintSummary() const
Prints a summary to the logs.
void SetRandomSeed(unsigned seed)
Set the random number seed.
virtual void SetNBins(unsigned nbins)
Set number of bins for all parameters.
unsigned GetNIterationsRun() const
Definition: BCEngineMCMC.h:323
void SetPreRunCheckClear(unsigned n)
Sets the number of prerun checks to make inbetween statistics clearing.
Definition: BCEngineMCMC.h:805
virtual unsigned MaxNameLength() const
bool fRescaleHistogramRangesAfterPreRun
flag for rescaling of histograms after pre-run.
void SetFillHistogramParPar(unsigned x, unsigned y, bool flag=true)
Sets whether to fill particular H2 histogram: par(y) vs.
Definition: BCEngineMCMC.h:913
virtual bool AddParameter(BCParameter &parameter)
void WriteMarkovChainPreRun(bool flag)
Turn on/off writing of Markov chain to root file during prerun.
double GetMultivariateEpsilon() const
Definition: BCEngineMCMC.h:426
void SetCorrectRValueForSamplingVariability(bool flag=true)
Set flag to correct convergence checking for initial sampling variability.
Definition: BCEngineMCMC.h:975
double fMCMCRValueParametersCriterion
The R-value criterion for convergence of parameters.
double fMultivariateCovarianceUpdateLambda
weighting parameter for multivariate-proposal-function covariance update.
const BCObservableSet & GetObservables() const
Definition: BCEngineMCMC.h:678
void SetMaximumEfficiency(double efficiency)
Sets the maximum efficiency required for a chain.
Definition: BCEngineMCMC.h:815
virtual double ProposalFunction(unsigned ichain, unsigned ipar)
The default proposal function is a Breit-Wigner random walk.
double GetMaximumEfficiency() const
Definition: BCEngineMCMC.h:343
BCParameter & GetParameter(const std::string &name)
Definition: BCEngineMCMC.h:644
unsigned fMCMCNLag
The lag for the Markov Chain.
int GetCurrentIteration() const
Definition: BCEngineMCMC.h:289
unsigned fMCMCNIterationsPreRunMax
Maximum number of iterations for a Markov chain prerun.
void SetHistogramRescalingPadding(double factor)
Set enlargement factor of range for when rescaling.
void InChainFillHistograms()
Fill marginalized distributions from all chain states.
ChainState & operator=(const ThreadLocalStorage &tls)
assignment
Definition: BCEngineMCMC.h:176
unsigned GetNVariables() const
Definition: BCEngineMCMC.h:613
std::vector< double > fMCMCRValueParameters
The R-values for each parameter.
void PrepareToContinueMarginalization(const std::string &filename, const std::string &mcmcTreeName="", const std::string &parameterTreeName="", bool loadObservables=true, bool autorange=true)
Continue the marginalization already stored in another file.
bool AcceptOrRejectPoint(unsigned chain, unsigned parameter)
Accept or rejects a point for a chain and updates efficiency.
void SetPriorDelta(unsigned index, double value)
unsigned GetCurrentChain() const
double probability_variance
variance of probability
Definition: BCEngineMCMC.h:203
virtual void SetPriorConstant()
Set constant prior.
BCEngineMCMC(const std::string &name="model")
Default constructor.
Precision
An enumerator for the status of a test.
Definition: BCEngineMCMC.h:65
void SetNIterationsPreRunMin(unsigned n)
Sets the minimum number of iterations in the pre-run.
Definition: BCEngineMCMC.h:794
virtual T & Get(const std::string &name)
Safe access, but slightly less efficient access to parameter.
double probability_at_mode
mode of probability
Definition: BCEngineMCMC.h:206
BCH1D & GetBCH1DdrawingOptions()
Definition: BCEngineMCMC.h:739
std::vector< double > fLocalModes
Vector of local modes.
BCEngineMCMC::Phase GetPhase() const
Definition: BCEngineMCMC.h:388
void SetPriorConstant(unsigned index)
BCH1D GetMarginalized(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter.
Definition: BCEngineMCMC.h:561
void SetFillHistogramParPar(const std::string &x, const std::string &y, bool flag=true)
Sets whether to fill particular H2 histogram: par(y) vs.
Definition: BCEngineMCMC.h:920
unsigned GetNParameters() const
Definition: BCEngineMCMC.h:656
std::vector< double > modeobs
mode of observables
Definition: BCEngineMCMC.h:205
virtual T & At(unsigned index)
Safe access, but slightly less efficient access to parameter.
BCVariable & GetVariable(unsigned index)
Definition: BCEngineMCMC.h:600
unsigned iteration
iteration number
Definition: BCEngineMCMC.h:160
BCParameterSet & GetParameters()
Definition: BCEngineMCMC.h:618
void SetPriorDelta(const std::string &name, double value)
void SetInitialScaleFactors(const std::vector< double > &scale)
Set the initial scale factors for the factorized proposal function.
Definition: BCEngineMCMC.h:770
bool ValidMCMCTree(TTree *tree, bool checkObservables=true) const
Check tree structure for MCMC tree.
A struct for holding a state in a Markov chain.
Definition: BCEngineMCMC.h:159
std::vector< std::vector< double > > covariance
covariances of all pairs of variables
Definition: BCEngineMCMC.h:199
randomly distribute uniformly over parameter ranges
Definition: BCEngineMCMC.h:84
unsigned UpdateFrequency(unsigned N) const
return appropriate update interval
unsigned GetNFreeParameters() const
Definition: BCEngineMCMC.h:668
unsigned int fMCMCTree_Chain
Chain number for storing into tree.
BCEngineMCMC::Phase fMCMCPhase
The phase of the run.
void SetFlagFillHistograms(bool flag)
Sets whether to fill histograms.
Definition: BCEngineMCMC.h:901
void CloseOutputFile()
Close the root output file.
void SetInitialPositions(const std::vector< double > &x0s)
Sets the initial positions for all chains.
double Getx(unsigned c, unsigned p) const
Definition: BCEngineMCMC.h:377
void SetPriorGauss(const std::string &name, double mode, double sigma_below, double sigma_above)