BAT  0.9.4
The Bayesian analysis toolkit
 All Classes Namespaces Functions Variables Enumerations
BCSummaryPriorModel.cxx
1 /*
2  * Copyright (C) 2007-2014, 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 "BCSummaryPriorModel.h"
12 
13 #include "BCH1D.h"
14 #include "BCLog.h"
15 #include "BCParameter.h"
16 
17 #include <TH1D.h>
18 
19 // ---------------------------------------------------------
21  : BCModel()
22  , fTestModel(0)
23 {
24 }
25 
26 // ---------------------------------------------------------
28  : BCModel(name)
29  , fTestModel(0)
30 {
31 }
32 
33 // ---------------------------------------------------------
35 {}
36 
37 // ---------------------------------------------------------
39 {
40  fTestModel = model;
41 
42  // copy parameters
43  int npar = fTestModel->GetNParameters();
44  for (int i = 0; i < npar; ++i) {
45  BCParameter * par = const_cast<BCParameter *>(fTestModel->GetParameter(i));
46  AddParameter(par);
47  }
48 
49  // set default histogram binning to the one of the original model
50  for (int i = 0; i < npar; ++i) {
51  // this construct has to go here, because otherwise there is a
52  // warning from BCEngineMCMC:: MCMCGetH1Marginalized
53  if (fTestModel->GetBestFitParameters().size() > 0){
54  BCH1D* hist = fTestModel->GetMarginalized( fTestModel->GetParameter(i) );
55  if (hist) {
56  int nbins = hist->GetHistogram()->GetNbinsX();
57  fTestModel->GetParameter(i)->SetNbins(nbins);
58  }
59  }
60  }
61 
62  // set default MCMC setup to the one of the original model
63  MCMCSetNChains( fTestModel->MCMCGetNChains() );
64  MCMCSetNLag( fTestModel->MCMCGetNLag() );
65  MCMCSetNIterationsMax( fTestModel->MCMCGetNIterationsMax() );
66  MCMCSetNIterationsRun( fTestModel->MCMCGetNIterationsRun() );
67  MCMCSetNIterationsPreRunMin( fTestModel->MCMCGetNIterationsPreRunMin() );
68  MCMCSetNIterationsUpdate( fTestModel->MCMCGetNIterationsUpdate() );
69  MCMCSetNIterationsUpdateMax( fTestModel->MCMCGetNIterationsUpdateMax() );
70  MCMCSetRValueCriterion( fTestModel->MCMCGetRValueCriterion() );
71  MCMCSetRValueParametersCriterion( fTestModel->MCMCGetRValueParametersCriterion() );
72 
73 }
74 
75 // ---------------------------------------------------------
76 double BCSummaryPriorModel::LogLikelihood(const std::vector<double> & parameters)
77 {
78  return fTestModel->LogAPrioriProbability(parameters);
79 }
80 
81 // ---------------------------------------------------------
82 double BCSummaryPriorModel::LogAPrioriProbability(const std::vector<double> & /*parameters*/)
83 {
84  return 0;
85 }
The base class for all user-defined models.
Definition: BCModel.h:50
double LogAPrioriProbability(const std::vector< double > &parameters)
void SetModel(BCModel *model)
A class representing a parameter of a model.
Definition: BCParameter.h:28
virtual int AddParameter(BCParameter *parameter)
Definition: BCModel.cxx:225
TH1D * GetHistogram()
Definition: BCH1D.h:53
A class for handling 1D distributions.
Definition: BCH1D.h:31
virtual double LogAPrioriProbability(const std::vector< double > &parameters)
Definition: BCModel.cxx:273
double LogLikelihood(const std::vector< double > &parameters)