BCModel.cxx
1 /*
2  * Copyright (C) 2007-2018, the BAT core developer team
3  * All rights reserved.
4  *
5  * For the licensing terms see doc/COPYING.
6  * For documentation see http://mpp.mpg.de/bat
7  */
8 
9 // ---------------------------------------------------------
10 
11 #include "BCModel.h"
12 
13 #include "BCDataSet.h"
14 #include "BCH1D.h"
15 #include "BCH2D.h"
16 #include "BCLog.h"
17 #include "BCMath.h"
18 #include "BCParameter.h"
19 #include "BCPriorModel.h"
20 #include "BCPrior.h"
21 #include "BCConstantPrior.h"
22 
23 #include <TCanvas.h>
24 #include <TH1.h>
25 #include <TH2.h>
26 #include <TTree.h>
27 
28 // ---------------------------------------------------------
29 BCModel::BCModel(const std::string& name)
30  : BCIntegrate(name)
31  , fDataSet(0)
32  , fPriorModel(0)
33  , fDrawPriorFirst(true)
34  , fFactorizedPrior(false)
35 {
37 }
38 
39 // ---------------------------------------------------------
40 BCModel::BCModel(const std::string& filename, const std::string& name, bool loadObservables)
41  : BCIntegrate(filename, name, loadObservables)
42  , fDataSet(0)
43  , fPriorModel(0)
44  , fDrawPriorFirst(true)
45  , fFactorizedPrior(false)
46 {
49 }
50 
51 // ---------------------------------------------------------
53  : BCIntegrate(other),
54  fDataSet(other.fDataSet),
55  fPriorModel(NULL),
62 {
63 }
64 
65 // ---------------------------------------------------------
67 {
69  fDataSet = other.fDataSet;
70  fPriorModel = NULL;
77 
78  return *this;
79 }
80 
81 // ---------------------------------------------------------
83 {
84  delete fPriorModel;
85 }
86 
87 // ---------------------------------------------------------
88 double BCModel::LogProbabilityNN(const std::vector<double>& parameters)
89 {
90  ThreadLocalStorage& s = fMCMCThreadLocalStorage[GetCurrentChain()];
91 
92  // first calculate prior (which is usually cheaper than likelihood)
93  s.log_prior = LogAPrioriProbability(parameters);
94  // then calculate likelihood, or set to -inf, if prior already invalid
95  if (std::isfinite(s.log_prior))
96  s.log_likelihood = LogLikelihood(parameters);
97  else
98  s.log_likelihood = -std::numeric_limits<double>::infinity();
99 
100  s.log_probability = s.log_prior + s.log_likelihood;
101  return s.log_probability;
102 }
103 
104 // ---------------------------------------------------------
105 double BCModel::LogProbability(const std::vector<double>& parameters)
106 {
107  // check if normalized
108  if (GetIntegral() <= 0.) {
109  BCLog::OutError("BCModel::LogProbability. Normalization not available or zero.");
110  return 0.;
111  }
112 
113  return LogProbabilityNN(parameters) - log(GetIntegral());
114 }
115 
116 // ---------------------------------------------------------
117 void BCModel::InitializeMarkovChainTree(bool replacetree, bool replacefile)
118 {
119  BCEngineMCMC::InitializeMarkovChainTree(replacetree, replacefile);
120  if (!fMCMCTree)
121  return;
122  fMCMCTree->Branch("LogLikelihood", &fMCMCTree_State.log_likelihood, "log_likelihood/D");
123  fMCMCTree->Branch("LogPrior", &fMCMCTree_State.log_prior, "log_prior/D");
124 }
125 
126 // ---------------------------------------------------------
127 double BCModel::SamplingFunction(const std::vector<double>& /*parameters*/)
128 {
129  double probability = 1;
130  for (unsigned i = 0 ; i < GetNParameters() ; ++i)
131  probability *= 1. / GetParameter(i).GetRangeWidth();
132  return probability;
133 }
134 
135 // ---------------------------------------------------------
136 double BCModel::HessianMatrixElement(unsigned index1, unsigned index2, const std::vector<double>& point)
137 {
138  // check number of entries in vector
139  if (point.size() < GetNParameters()) {
140  BCLog::OutError("BCModel::HessianMatrixElement : Invalid number of entries in the vector.");
141  return -1;
142  }
143 
144  // define steps
145  double nsteps = 1e5;
146  double dx1 = GetVariable(index1).GetRangeWidth() / nsteps;
147  double dx2 = GetVariable(index2).GetRangeWidth() / nsteps;
148 
149  // define points at which to evaluate
150  std::vector<double> xpp = point;
151  std::vector<double> xpm = point;
152  std::vector<double> xmp = point;
153  std::vector<double> xmm = point;
154 
155  xpp[index1] += dx1;
156  xpp[index2] += dx2;
157 
158  xpm[index1] += dx1;
159  xpm[index2] -= dx2;
160 
161  xmp[index1] -= dx1;
162  xmp[index2] += dx2;
163 
164  xmm[index1] -= dx1;
165  xmm[index2] -= dx2;
166 
167  // calculate probability at these points
168  double ppp = Likelihood(xpp);
169  double ppm = Likelihood(xpm);
170  double pmp = Likelihood(xmp);
171  double pmm = Likelihood(xmm);
172 
173  // return derivative
174  return (ppp + pmm - ppm - pmp) / (4. * dx1 * dx2);
175 }
176 
177 // ---------------------------------------------------------
179 {
180  BCLog::OutSummary("---------------------------------------------------");
181  BCLog::OutSummary(Form("Fit summary for model \'%s\':", GetName().data()));
182  BCLog::OutSummary(Form(" Number of parameters: Npar = %i", GetNParameters()));
183  if (GetNDataPoints()) {
184  BCLog::OutSummary(Form(" Number of data points: Ndata = %i", GetNDataPoints()));
185  BCLog::OutSummary(Form(" Number of degrees of freedom = %i", GetNDoF()));
186  }
187  if (!GetBestFitParameters().empty())
188  BCLog::OutSummary(" Best fit parameters (global):");
189  PrintParameters(GetBestFitParameters(), BCLog::OutSummary);
190 
191  BCLog::OutSummary("---------------------------------------------------");
192 }
193 
194 // ---------------------------------------------------------
195 void BCModel::PrintHessianMatrix(std::vector<double> parameters)
196 {
197  // check number of entries in vector
198  if (parameters.size() != GetNParameters()) {
199  BCLog::OutError("BCModel::PrintHessianMatrix : Invalid number of entries in the vector");
200  return;
201  }
202 
203  // print to screen
204  BCLog::OutSummary("Hessian matrix elements: ");
205  BCLog::OutSummary("Parameter values:");
206 
207  for (unsigned i = 0; i < parameters.size(); ++i)
208  BCLog::OutSummary(Form("Parameter %d : %f", i, parameters.at(i)));
209 
210  BCLog::OutSummary("Hessian matrix:");
211  // loop over all parameter pairs
212  for (unsigned int i = 0; i < GetNParameters(); i++)
213  for (unsigned int j = 0; j < i; j++) {
214  // calculate Hessian matrix element
215  double hessianmatrixelement = HessianMatrixElement(i, j, parameters);
216 
217  // print to screen
218  BCLog::OutSummary(Form("%d %d : %f", i, j, hessianmatrixelement));
219  }
220 }
221 
222 // ---------------------------------------------------------
223 BCPriorModel* BCModel::GetPriorModel(bool prepare, bool call_likelihood)
224 {
225  if (!fPriorModel)
226  fPriorModel = new BCPriorModel(*this, call_likelihood);
227  else if (prepare)
229  fPriorModel->SetCallLikelihood(call_likelihood);
230  return fPriorModel;
231 }
232 
233 // ---------------------------------------------------------
234 BCH1D BCModel::GetPrior(unsigned index)
235 {
236  BCH1D prior;
237 
238  if (index > GetNVariables())
239  return prior;
240 
241  if (index < GetNParameters() && GetParameter(index).Fixed())
242  return prior;
243 
244  // check for factorized prior
245  if (fFactorizedPrior && index < GetNParameters() && GetParameter(index).GetPrior() != NULL) {
246  TH1* h = GetVariable(index).CreateH1("getprior1d_temp");
247  prior = GetParameter(index).GetPrior()->GetBCH1D(h, Form("%s_%d_prior", GetSafeName().data(), index));
248  delete h;
249 
250  if (prior.Valid()) {
251  // correct for flat prior
252  bool const_prior = (dynamic_cast<BCConstantPrior*>(GetParameter(index).GetPrior()) != NULL);
253  if (const_prior) {
254  prior.SetLocalMode((unsigned)0, GetParameter(index).GetRangeCenter());
255  prior.SetNBands(0);
256  prior.SetDrawLocalMode(0);
257  }
258  }
259  }
260 
261  // else use marginalized prior, if it exists
262  if (!prior.Valid() && fPriorModel->MarginalizedHistogramExists(index))
263  prior = fPriorModel->GetMarginalized(index);
264 
265  if (prior.Valid())
266  prior.GetHistogram()->SetTitle(Form("prior;%s;P(%s)", GetVariable(index).GetLatexNameWithUnits().data(), GetVariable(index).GetLatexName().data()));
267 
268  return prior;
269 }
270 
271 // ---------------------------------------------------------
272 BCH2D BCModel::GetPrior(unsigned index1, unsigned index2)
273 {
274  BCH2D prior;
275 
276  if (index1 > GetNVariables() || index2 > GetNVariables())
277  return prior;
278 
279  if (index1 < GetNParameters() && GetParameter(index1).Fixed())
280  return prior;
281 
282  if (index2 < GetNParameters() && GetParameter(index2).Fixed())
283  return prior;
284 
285  std::string title = "prior";
286 
287  // check for factorized priors
288  if (fFactorizedPrior &&
289  index1 < GetNParameters() && GetParameter(index1).GetPrior() != NULL &&
290  index2 < GetNParameters() && GetParameter(index2).GetPrior() != NULL) {
291 
292  TH2* h2 = fPriorModel->GetVariable(index1).CreateH2("getprior2d_temp", fPriorModel->GetVariable(index2));
293  prior = GetParameter(index1).GetPrior()->GetBCH2D(GetParameter(index2).GetPrior(), h2, Form("h2d_prior_%s_%d_%d", GetName().data(), index1, index2));
294  delete h2;
295 
296  if (prior.Valid()) {
297  // correct for flat prior
298  bool const_prior1 = (dynamic_cast<BCConstantPrior*>(GetParameter(index1).GetPrior()) != NULL);
299  bool const_prior2 = (dynamic_cast<BCConstantPrior*>(GetParameter(index2).GetPrior()) != NULL);
300  if (const_prior1)
301  prior.SetLocalMode((unsigned)0, GetParameter(index1).GetRangeCenter());
302  if (const_prior2)
303  prior.SetLocalMode((unsigned)1, GetParameter(index2).GetRangeCenter());
304  if (const_prior1 && !const_prior2)
305  title += " (flat in " + fPriorModel->GetVariable(index1).GetLatexName() + ")";
306  else if (!const_prior1 && const_prior2)
307  title += " (flat in " + fPriorModel->GetVariable(index2).GetLatexName() + ")";
308  else if (const_prior1 && const_prior2) {
309  title += " (flat in both "
311  + " and "
313  + ")";
314  prior.SetNBands(0);
315  prior.SetDrawLocalMode(false);
316  }
317  }
318  }
319 
320  // else use marginalized prior, if it exists
321  if (!prior.Valid() && (fPriorModel->MarginalizedHistogramExists(index1, index2) || fPriorModel->MarginalizedHistogramExists(index2, index1)))
322  prior = fPriorModel->GetMarginalized(index1, index2);
323 
324  if (prior.Valid())
325  prior.GetHistogram()->SetTitle(Form("%s;%s;%s;P(%s, %s)",
326  title.data(),
327  GetVariable(index1).GetLatexNameWithUnits().data(),
328  GetVariable(index2).GetLatexNameWithUnits().data(),
329  GetVariable(index1).GetLatexName().data(), GetVariable(index2).GetLatexName().data()));
330 
331  return prior;
332 }
333 
334 // ---------------------------------------------------------
335 unsigned BCModel::PrintKnowledgeUpdatePlots(const std::string& filename, unsigned hdiv, unsigned vdiv, bool call_likelihood)
336 {
337  if (GetNVariables() == 0) {
338  BCLog::OutError("BCModel::PrintKnowledgeUpdatePlots : No variables defined!");
339  return 0;
340  }
341 
342  // prepare prior
343  if (!GetPriorModel(true, call_likelihood) || fPriorModel->GetNParameters() == 0 )
344  return 0;
345 
346  std::string newFilename(filename);
347  BCAux::DefaultToPDF(newFilename);
348  if (newFilename.empty())
349  return 0;
350 
351  // call prior evalution once to set fFactorizedPrior:
352  LogAPrioriProbability(std::vector<double>(GetNParameters(), 0));
353 
354  if (!fFactorizedPrior || !GetParameters().ArePriorsSet(true) || GetNObservables() > 0) {
355  BCLog::OutSummary("Marginalizing prior...");
357  }
359 
360  // Find nonempty 1D prior--posterior pairs
361  std::vector<unsigned> H1Indices = GetH1DPrintOrder();
362  std::vector<std::pair<BCH1D, BCH1D> > h1;
363  h1.reserve(H1Indices.size());
364  for (unsigned i = 0; i < H1Indices.size(); ++i) {
365  BCH1D prior = GetPrior(H1Indices[i]);
366  if (!prior.Valid())
367  continue;
368  BCH1D posterior = GetMarginalized(H1Indices[i]);
369  if (!posterior.Valid())
370  continue;
371  posterior.GetHistogram()->SetTitle("posterior");
372  if (prior.GetNBands() == 0) {
374  prior.SetNBands(0);
375  prior.SetDrawLocalMode(false);
376  } else
379  h1.push_back(std::make_pair(prior, posterior));
380  }
381 
382  // Find nonempty 2D prior--posterior pairs
383  std::vector<std::pair<unsigned, unsigned> > H2Coords = GetH2DPrintOrder();
384  std::vector<std::pair<BCH2D, BCH2D> > h2;
385  h2.reserve(H2Coords.size());
386  for (unsigned i = 0; i < H2Coords.size(); ++i) {
387  BCH2D prior = GetPrior(H2Coords[i].first, H2Coords[i].second);
388  if (!prior.Valid())
389  continue;
390  BCH2D posterior = GetMarginalized(H2Coords[i].first, H2Coords[i].second);
391  if (!posterior.Valid())
392  continue;
393  posterior.GetHistogram()->SetTitle("posterior");
394  if (prior.GetNBands() == 0) {
396  prior.SetNBands(0);
397  prior.SetDrawLocalMode(false);
398  } else
401  h2.push_back(std::make_pair(prior, posterior));
402  }
403 
404  if (h1.empty() && h2.empty()) {
405  BCLog::OutWarning("BCModel::PrintKnowledgeUpdatePlots : No update plots to print.");
406  return 0;
407  }
408 
409  const unsigned nplots = h1.size() + h2.size();
410  BCLog::OutSummary(Form("Printing knowledge update plots (%lu x 1D + %lu x 2D = %u) into file %s", h1.size(), h2.size(), nplots, newFilename.data()));
411  if (nplots > 100)
412  BCLog::OutDetail("This can take a while...");
413 
414  if (hdiv < 1) hdiv = 1;
415  if (vdiv < 1) vdiv = 1;
416 
417  int c_width = 297 * 4;
418  int c_height = 210 * 4;
419  if (hdiv < vdiv)
420  std::swap(c_width, c_height);
421 
422  // create canvas and prepare postscript
423  TCanvas c("c", "canvas", c_width, c_height);
424  c.Divide(hdiv, vdiv);
425 
426  unsigned n = 0;
427 
428  // open file
429  c.Print((newFilename + "[").data());
430 
431  // Draw 1D Knowledge Update Plots
432  for (unsigned i = 0; i < h1.size(); ++i) {
433  // if current page is full, switch to new page
434  if (i != 0 && i % (hdiv * vdiv) == 0) {
435  c.Print(newFilename.c_str());
436  c.Clear("D");
437  }
438 
439  // go to next pad
440  c.cd(i % (hdiv * vdiv) + 1)->ResetAttPad();
441 
442  BCAux::DrawKnowledgeUpdate(h1[i].first, h1[i].second, fDrawPriorFirst, fObjectTrash);
443 
444  if (++n % 100 == 0)
445  BCLog::OutDetail(Form(" --> %d plots done", n));
446  }
447  if (h1.size() > 0) {
448  c.Print(newFilename.c_str());
449  c.Clear("D");
450  }
451 
452  // Draw 2D Knowledge Update Plots
453  for (unsigned i = 0; i < h2.size(); ++i) {
454  // if current page is full, switch to new page
455  if (i != 0 && i % (hdiv * vdiv) == 0) {
456  c.Print(newFilename.c_str());
457  c.Clear("D");
458  }
459 
460  // go to next pad
461  c.cd(i % (hdiv * vdiv) + 1)->ResetAttPad();
462 
463  // prior text?
464  BCAux::DrawKnowledgeUpdate(h2[i].first, h2[i].second, fDrawPriorFirst, fObjectTrash);
465 
466  if (++n % 100 == 0)
467  BCLog::OutDetail(Form(" --> %d plots done", n));
468  }
469  if (h2.size() > 0) {
470  c.Print(newFilename.c_str());
471  c.Clear("D");
472  }
473  c.Print(std::string(newFilename + "]").c_str());
474 
475  if (nplots > 100 && nplots % 100 != 0)
476  BCLog::OutDetail(Form(" --> %d plots done", nplots));
477 
478  // return total number of drawn histograms
479  return nplots;
480 
481 }
482 
483 // ---------------------------------------------------------
485 {
488 
489  switch (style) {
490 
492  SetDrawPriorFirst(false);
493  break;
494 
496  SetDrawPriorFirst(true);
497  break;
498 
500  default:
501  break;
502  }
503 }
Posterior drawn with detailed info, prior drawn as overlaid line.
Definition: BCAux.h:121
virtual TH1 * CreateH1(const std::string &name) const
Creates a 1D Histogram for this variable.
Definition: BCVariable.cxx:132
bool MarginalizedHistogramExists(unsigned index) const
Definition: BCEngineMCMC.h:511
void DrawKnowledgeUpdate(BCHistogramBase &prior, BCHistogramBase &posterior, bool draw_prior_first, BCTrash< TObject > &trash)
Draw knowledge update plot into current TPad.
Definition: BCAux.cxx:236
ChainState fMCMCTree_State
MC state object for storing into tree.
double GetIntegral() const
Definition: BCIntegrate.h:259
int GetNDoF() const
Definition: BCModel.h:89
virtual BCPriorModel * GetPriorModel(bool prepare=true, bool call_likelihood=false)
Definition: BCModel.cxx:223
virtual double LogLikelihood(const std::vector< double > &params)=0
Calculates natural logarithm of the likelihood.
BCH1D fBCH1DPosteriorDrawingOptions
knowledge update plot 1D posterior options.
Definition: BCModel.h:307
Class for sampling from prior of a BCModel.
Definition: BCPriorModel.h:30
virtual double LogProbability(const std::vector< double > &parameters)
Returns natural logarithm of the a posteriori probability given a set of parameter values...
Definition: BCModel.cxx:105
virtual std::vector< std::pair< unsigned, unsigned > > GetH2DPrintOrder() const
BCParameter & GetParameter(unsigned index)
Definition: BCEngineMCMC.h:630
TTree * fMCMCTree
The tree containing the Markov chains.
A class for handling numerical operations for models.
Definition: BCIntegrate.h:143
int MarginalizeAll()
Marginalize all probabilities wrt.
bool fDrawPriorFirst
flag for ordering of drawing of prior and posterior in knowledge update plots.
Definition: BCModel.h:315
The base class for all user-defined models.
Definition: BCModel.h:39
A class for handling 2D distributions.
Definition: BCH2D.h:37
A class to represent a constant prior of a parameter.
void CopyOptions(const BCH1D &other)
Copy options from other.
Definition: BCH1D.cxx:50
std::vector< double > FindMode(std::vector< double > start=std::vector< double >())
Do the mode finding using a method set via SetOptimizationMethod.
void PrintParameters(const std::vector< double > &P, void(*output)(const std::string &)=BCLog::OutSummary) const
Print parameters.
TH2 * GetHistogram()
Return the TH2 histogram.
Definition: BCH2D.h:100
double log_prior
log(prior)
Definition: BCEngineMCMC.h:165
void PrintHessianMatrix(std::vector< double > parameters)
Prints matrix elements of the Hessian matrix.
Definition: BCModel.cxx:195
void PrintShortFitSummary()
Prints a short summary of the fit results on the screen.
Definition: BCModel.cxx:178
void SetDrawPriorFirst(bool b=true)
Set drawing of prior first (true) or posterior first (false) for knowledge update plots...
Definition: BCModel.h:155
virtual double LogProbabilityNN(const std::vector< double > &parameters)
Returns the natural logarithm of likelihood times prior probability given a set of parameter values...
Definition: BCModel.cxx:88
void SetPriorConstantAll()
Prior drawn with detailed info, posterior drawn as overlaid line.
Definition: BCAux.h:122
BCH1D fBCH1DPriorDrawingOptions
knowledge update plot 1D prior options.
Definition: BCModel.h:299
virtual BCPrior * GetPrior()
Definition: BCParameter.h:91
unsigned GetNObservables() const
Definition: BCEngineMCMC.h:711
double HessianMatrixElement(unsigned index1, unsigned index2, const std::vector< double > &point)
Calculates the matrix element of the Hessian matrix.
Definition: BCModel.cxx:136
virtual std::vector< unsigned > GetH1DPrintOrder() const
BCAux::BCTrash< TObject > fObjectTrash
Storage for plot objects with proper clean-up.
virtual const std::string & GetLatexName() const
Definition: BCVariable.h:82
virtual void InitializeMarkovChainTree(bool replacetree=false, bool replacefile=false)
Initialize the trees containing the Markov chains and parameter info.
BCModel & operator=(const BCModel &)
Copy-assignment operator.
Definition: BCModel.cxx:66
void SetLocalMode(double x, double y)
Set local mode.
Definition: BCH2D.h:180
void SetKnowledgeUpdateDrawingStyle(BCH1D &prior, BCH1D &posterior, BCAux::BCKnowledgeUpdateDrawingStyle style=BCAux::kKnowledgeUpdateDefaultStyle)
Use pre-made drawing options for knowledge update plots.
Definition: BCAux.cxx:132
BCModel(const std::string &name="model")
Default constructor.
Definition: BCModel.cxx:29
const std::string & GetName() const
Definition: BCEngineMCMC.h:269
void SetDrawLocalMode(bool flag=true, bool arrows=true)
Set drawing of global mode.
virtual void InitializeMarkovChainTree(bool replacetree=false, bool replacefile=false)
Initialize the trees containing the Markov chains and parameter info.
Definition: BCModel.cxx:117
unsigned GetNDataPoints() const
Definition: BCModel.h:83
BCH2D fBCH2DPosteriorDrawingOptions
knowledge update plot 2D posterior options.
Definition: BCModel.h:311
BCKnowledgeUpdateDrawingStyle
An enumerator for the knowledge update drawing style presets.
Definition: BCAux.h:119
Simple line-drawn histograms.
Definition: BCAux.h:120
virtual unsigned PrintKnowledgeUpdatePlots(const std::string &filename, unsigned hdiv=1, unsigned vdiv=1, bool call_likelihood=false)
Print a comparison of the prior knowledge to the posterior knowledge for each parameter.
Definition: BCModel.cxx:335
BCH2D fBCH2DPriorDrawingOptions
knowledge update plot 2D prior options.
Definition: BCModel.h:303
virtual bool Valid() const
Whether histogram has been set and filled.
virtual std::string GetLatexNameWithUnits() const
Definition: BCVariable.h:92
void CopyOptions(const BCH2D &other)
copy options from
Definition: BCH2D.cxx:52
bool PreparePriorModel()
Prepare PriorModel from Model.
virtual ~BCModel()
Destructor.
Definition: BCModel.cxx:82
void SetCallLikelihood(bool cl)
Set calling of likelihood in model.
Definition: BCPriorModel.h:66
const std::string & GetSafeName() const
Definition: BCEngineMCMC.h:274
A class for handling 1D distributions.
Definition: BCH1D.h:34
virtual double LogAPrioriProbability(const std::vector< double > &parameters)
Returns natural logarithm of the prior probability.
Definition: BCModel.h:178
void SetNBands(unsigned n)
Sets number of credibility interval bands to draw.
BCDataSet * fDataSet
A data set.
Definition: BCModel.h:291
void DefaultToPDF(std::string &filename)
Force file extension to be .pdf if not already .pdf or .ps.
Definition: BCAux.cxx:36
double log_likelihood
log(likelihood)
Definition: BCEngineMCMC.h:164
BCIntegrate & operator=(const BCIntegrate &)
Copy-assignment operator.
virtual BCH2D GetBCH2D(BCPrior *ordinate, TH2 *bins, const std::string &name="prior")
Get BCH2D object for prior.
Definition: BCPrior.cxx:176
BCPriorModel * fPriorModel
BCPriorModel object for drawing of knowledge update, and saving of samples according to prior...
Definition: BCModel.h:295
virtual double SamplingFunction(const std::vector< double > &parameters)
Sampling function used for importance sampling.
Definition: BCModel.cxx:127
virtual BCH1D GetBCH1D(TH1 *bins, const std::string &name="prior")
Get BCH1D object for prior.
Definition: BCPrior.cxx:159
unsigned GetNBands() const
unsigned GetNVariables() const
Definition: BCEngineMCMC.h:613
void SetKnowledgeUpdateDrawingStyle(BCAux::BCKnowledgeUpdateDrawingStyle style=BCAux::kKnowledgeUpdateDefaultStyle)
Set default drawing options for knowledge update plots.
Definition: BCModel.cxx:484
unsigned GetCurrentChain() const
virtual double GetRangeWidth() const
Returns the range width of the variable values.
Definition: BCVariable.h:109
void SetLocalMode(double mode)
Set local mode.
Definition: BCH1D.h:158
BCH1D GetMarginalized(const std::string &name) const
Obtain the individual marginalized distributions with respect to one parameter.
Definition: BCEngineMCMC.h:561
virtual BCH1D GetPrior(unsigned index)
Get prior of a variable as a BCH1D.
Definition: BCModel.cxx:234
unsigned GetNParameters() const
Definition: BCEngineMCMC.h:656
bool fFactorizedPrior
flag for whether factorized prior has been used.
Definition: BCModel.h:319
BCVariable & GetVariable(unsigned index)
Definition: BCEngineMCMC.h:600
BCParameterSet & GetParameters()
Definition: BCEngineMCMC.h:618
virtual double Likelihood(const std::vector< double > &params)
Returns the likelihood.
Definition: BCModel.h:185
virtual const std::vector< double > & GetBestFitParameters() const