BayesianAnalysisToolkit  0.9.3
Protected Attributes | Private Member Functions | List of all members
BCModel Class Referenceabstract

The base class for all user-defined models. More...

#include <BCModel.h>

Inheritance diagram for BCModel:
Inheritance graph
[legend]
Collaboration diagram for BCModel:
Collaboration graph
[legend]

Public Member Functions

Constructors and destructors
 BCModel (const char *name="model")
 
 BCModel (const BCModel &bcmodel)
 
virtual ~BCModel ()
 
Assignment operators
BCModeloperator= (const BCModel &bcmodel)
 
Member functions (get)
const std::string & GetName () const
 
double GetModelAPrioriProbability () const
 
double GetModelAPosterioriProbability () const
 
BCDataSetGetDataSet () const
 
BCDataPointGetDataPointLowerBoundaries () const
 
BCDataPointGetDataPointUpperBoundaries () const
 
double GetDataPointLowerBoundary (unsigned int index) const
 
double GetDataPointUpperBoundary (unsigned int index) const
 
bool GetFlagBoundaries () const
 
unsigned GetNDataPoints () const
 
BCDataPointGetDataPoint (unsigned int index) const
 
Member functions (set)
void SetName (const char *name)
 
void SetModelAPrioriProbability (double probability)
 
void SetModelAPosterioriProbability (double probability)
 
virtual int AddParameter (BCParameter *parameter)
 
void SetDataSet (BCDataSet *dataset)
 
void SetSingleDataPoint (BCDataPoint *datapoint)
 
void SetSingleDataPoint (BCDataSet *dataset, unsigned int index)
 
void SetDataBoundaries (unsigned int index, double lowerboundary, double upperboundary, bool fixed=false)
 
void SetDataPointLowerBoundaries (BCDataPoint *datasetlowerboundaries)
 
void SetDataPointUpperBoundaries (BCDataPoint *datasetupperboundaries)
 
void SetDataPointLowerBoundary (int index, double lowerboundary)
 
void SetDataPointUpperBoundary (int index, double upperboundary)
 
int SetPrior (int index, TF1 *f)
 
int SetPrior (const char *name, TF1 *f)
 
int SetPriorDelta (int index, double value)
 
int SetPriorDelta (const char *name, double value)
 
int SetPriorGauss (int index, double mean, double sigma)
 
int SetPriorGauss (const char *name, double mean, double sigma)
 
int SetPriorGauss (int index, double mean, double sigmadown, double sigmaup)
 
int SetPriorGauss (const char *name, double mean, double sigmadown, double sigmaup)
 
int SetPrior (int index, TH1 *h, bool flag=false)
 
int SetPrior (const char *name, TH1 *h, bool flag=false)
 
int SetPriorConstant (int index)
 
int SetPriorConstant (const char *name)
 
int SetPriorConstantAll ()
 
Member functions (miscellaneous methods)
void Copy (const BCModel &bcmodel)
 
double APrioriProbability (const std::vector< double > &parameters)
 
virtual double LogAPrioriProbability (const std::vector< double > &parameters)
 
virtual double Likelihood (const std::vector< double > &params)
 
virtual double LogLikelihood (const std::vector< double > &params)=0
 
double ProbabilityNN (const std::vector< double > &params)
 
double LogProbabilityNN (const std::vector< double > &parameters)
 
double Probability (const std::vector< double > &parameter)
 
double LogProbability (const std::vector< double > &parameter)
 
virtual double SamplingFunction (const std::vector< double > &parameters)
 
double Eval (const std::vector< double > &parameters)
 
virtual double LogEval (const std::vector< double > &parameters)
 
virtual void CorrelateDataPointValues (std::vector< double > &x)
 
double GetPvalueFromChi2 (const std::vector< double > &par, int sigma_index)
 
double GetPvalueFromKolmogorov (const std::vector< double > &par, int index)
 
double GetPvalueFromChi2NDoF (std::vector< double > par, int sigma_index)
 
BCH1DCalculatePValue (std::vector< double > par, bool flag_histogram=false)
 
double GetPValue ()
 
double GetPValueNDoF ()
 
double GetChi2NDoF ()
 
std::vector< double > GetChi2Runs (int dataIndex, int sigmaIndex)
 
void SetGoFNIterationsMax (int n)
 
void SetGoFNIterationsRun (int n)
 
void SetGoFNChains (int n)
 
double HessianMatrixElement (const BCParameter *parameter1, const BCParameter *parameter2, std::vector< double > point)
 
void PrintSummary ()
 
void PrintResults (const char *file)
 
void PrintShortFitSummary (int chi2flag=0)
 
void PrintHessianMatrix (std::vector< double > parameters)
 
virtual double CDF (const std::vector< double > &, int, bool)
 
- Public Member Functions inherited from BCIntegrate
 BCIntegrate ()
 
 BCIntegrate (const BCIntegrate &bcintegrate)
 
virtual ~BCIntegrate ()
 
BCIntegrateoperator= (const BCIntegrate &bcintegrate)
 
int ReadMarginalizedFromFile (const char *file)
 
BCH1DGetMarginalized (const BCParameter *parameter)
 
BCH1DGetMarginalized (const char *name)
 
BCH1DGetMarginalized (unsigned index)
 
BCH2DGetMarginalized (const BCParameter *parameter1, const BCParameter *parameter2)
 
BCH2DGetMarginalized (const char *name1, const char *name2)
 
BCH2DGetMarginalized (unsigned index1, unsigned index2)
 
int PrintAllMarginalized1D (const char *filebase)
 
int PrintAllMarginalized2D (const char *filebase)
 
int PrintAllMarginalized (const char *file, std::string options1d="BTsiB3CS1D0pdf0Lmeanmode", std::string options2d="BTfB3CS1meangmode", unsigned int hdiv=1, unsigned int ndiv=1)
 
double GetIntegral () const
 
BCIntegrate::BCOptimizationMethod GetOptimizationMethod () const
 
BCIntegrate::BCIntegrationMethod GetIntegrationMethod () const
 
BCIntegrate::BCMarginalizationMethod GetMarginalizationMethod () const
 
BCIntegrate::BCSASchedule GetSASchedule () const
 
void GetRandomVectorUnitHypercube (std::vector< double > &x) const
 
void GetRandomVectorInParameterSpace (std::vector< double > &x) const
 
double GetRandomPoint (std::vector< double > &x)
 
int GetNIterationsMin () const
 
int GetNIterationsMax () const
 
int GetNIterationsPrecisionCheck () const
 
int GetNIterationsOutput () const
 
int GetNIterations () const
 
double GetRelativePrecision () const
 
double GetAbsolutePrecision () const
 
BCCubaMethod GetCubaIntegrationMethod () const
 
const BCCubaOptions::VegasGetCubaVegasOptions () const
 
const BCCubaOptions::SuaveGetCubaSuaveOptions () const
 
const BCCubaOptions::DivonneGetCubaDivonneOptions () const
 
const BCCubaOptions::CuhreGetCubaCuhreOptions () const
 
BCH1DGetSlice (const BCParameter *parameter, const std::vector< double > parameters=std::vector< double >(0), int bins=0, bool flag_norm=true)
 
BCH1DGetSlice (const char *name, const std::vector< double > parameters=std::vector< double >(0), int nbins=0, bool flag_norm=true)
 
BCH2DGetSlice (const BCParameter *parameter1, const BCParameter *parameter2, const std::vector< double > parameters=std::vector< double >(0), int bins=0, bool flag_norm=true)
 
BCH2DGetSlice (const char *name1, const char *name2, const std::vector< double > parameters=std::vector< double >(0), int nbins=0, bool flag_norm=true)
 
BCH2DGetSlice (unsigned index1, unsigned index2, const std::vector< double > parameters=std::vector< double >(0), int nbins=0, bool flag_norm=true)
 
double GetError () const
 
TMinuit * GetMinuit ()
 
int GetMinuitErrorFlag () const
 
double GetSAT0 () const
 
double GetSATmin () const
 
double GetBestFitParameter (unsigned index) const
 
double GetBestFitParameterError (unsigned index) const
 
double GetLogMaximum ()
 
const std::vector< double > & GetBestFitParameters () const
 
const std::vector< double > & GetBestFitParameterErrors () const
 
void SetMinuitArlist (double *arglist)
 
void SetFlagIgnorePrevOptimization (bool flag)
 
void SetOptimizationMethod (BCIntegrate::BCOptimizationMethod method)
 
void SetIntegrationMethod (BCIntegrate::BCIntegrationMethod method)
 
void SetMarginalizationMethod (BCIntegrate::BCMarginalizationMethod method)
 
void SetSASchedule (BCIntegrate::BCSASchedule schedule)
 
void SetNIterationsMin (int niterations)
 
void SetNIterationsMax (int niterations)
 
void SetNIterationsPrecisionCheck (int niterations)
 
void SetNIterationsOutput (int niterations)
 
void SetRelativePrecision (double relprecision)
 
void SetAbsolutePrecision (double absprecision)
 
void SetCubaIntegrationMethod (BCCubaMethod type)
 
void SetCubaOptions (const BCCubaOptions::Vegas &options)
 
void SetCubaOptions (const BCCubaOptions::Suave &options)
 
void SetCubaOptions (const BCCubaOptions::Divonne &options)
 
void SetCubaOptions (const BCCubaOptions::Cuhre &options)
 
void SetSAT0 (double T0)
 
void SetSATmin (double Tmin)
 
void SetFlagWriteSAToFile (bool flag)
 
TTree * GetSATree ()
 
void InitializeSATree ()
 
double Normalize ()
 
double Integrate (BCIntegrationMethod intmethod)
 
double Integrate ()
 
double Integrate (BCIntegrationMethod type, tRandomizer randomizer, tEvaluator evaluator, tIntegralUpdater updater, std::vector< double > &sums)
 
double EvaluatorMC (std::vector< double > &sums, const std::vector< double > &point, bool &accepted)
 
int MarginalizeAll ()
 
int MarginalizeAll (BCMarginalizationMethod margmethod)
 
virtual void MarginalizePreprocess ()
 
virtual void MarginalizePostprocess ()
 
void SAInitialize ()
 
std::vector< double > FindMode (std::vector< double > start=std::vector< double >())
 
std::vector< double > FindMode (BCIntegrate::BCOptimizationMethod optmethod, std::vector< double > start=std::vector< double >())
 
double SATemperature (double t)
 
double SATemperatureBoltzmann (double t)
 
double SATemperatureCauchy (double t)
 
virtual double SATemperatureCustom (double t)
 
std::vector< double > GetProposalPointSA (const std::vector< double > &x, int t)
 
std::vector< double > GetProposalPointSABoltzmann (const std::vector< double > &x, int t)
 
std::vector< double > GetProposalPointSACauchy (const std::vector< double > &x, int t)
 
virtual std::vector< double > GetProposalPointSACustom (const std::vector< double > &x, int t)
 
std::vector< double > SAHelperGetRandomPointOnHypersphere ()
 
double SAHelperGetRadialCauchy ()
 
double SAHelperSinusToNIntegral (int dim, double theta)
 
virtual void ResetResults ()
 
std::string DumpIntegrationMethod (BCIntegrationMethod type)
 
std::string DumpCurrentIntegrationMethod ()
 
std::string DumpUsedIntegrationMethod ()
 
std::string DumpMarginalizationMethod (BCMarginalizationMethod type)
 
std::string DumpCurrentMarginalizationMethod ()
 
std::string DumpUsedMarginalizationMethod ()
 
std::string DumpOptimizationMethod (BCOptimizationMethod type)
 
std::string DumpCurrentOptimizationMethod ()
 
std::string DumpUsedOptimizationMethod ()
 
std::string DumpCubaIntegrationMethod (BCCubaMethod type)
 
std::string DumpCubaIntegrationMethod ()
 
void SetBestFitParameters (const std::vector< double > &x)
 
void SetBestFitParameters (const std::vector< double > &x, const double &new_value, double &old_value)
 
unsigned GetNIntegrationVariables ()
 
double CalculateIntegrationVolume ()
 
bool CheckMarginalizationAvailability (BCMarginalizationMethod type)
 
bool CheckMarginalizationIndices (TH1 *hist, const std::vector< unsigned > &index)
 
- Public Member Functions inherited from BCEngineMCMC
void WriteMarkovChain (bool flag)
 
 BCEngineMCMC ()
 
 BCEngineMCMC (const BCEngineMCMC &enginemcmc)
 
virtual ~BCEngineMCMC ()
 
BCEngineMCMCoperator= (const BCEngineMCMC &engineMCMC)
 
unsigned MCMCGetNChains () const
 
unsigned MCMCGetNLag () const
 
const std::vector< unsigned > & MCMCGetNIterations () const
 
unsigned MCMCGetCurrentIteration () const
 
unsigned MCMCGetCurrentChain () const
 
unsigned MCMCGetNIterationsConvergenceGlobal () const
 
bool MCMCGetFlagConvergenceGlobal () const
 
unsigned MCMCGetNIterationsMax () const
 
unsigned MCMCGetNIterationsRun () const
 
unsigned MCMCGetNIterationsPreRunMin () const
 
unsigned MCMCGetNIterationsUpdate () const
 
unsigned MCMCGetNIterationsUpdateMax () const
 
std::vector< int > MCMCGetNTrialsTrue () const
 
int MCMCGetNTrials () const
 
const std::vector< double > & MCMCGetprobMean () const
 
const std::vector< double > & MCMCGetVariance () const
 
const std::vector< double > & MCMCGetTrialFunctionScaleFactor () const
 
std::vector< double > MCMCGetTrialFunctionScaleFactor (unsigned ichain) const
 
double MCMCGetTrialFunctionScaleFactor (unsigned ichain, unsigned ipar)
 
const std::vector< double > & MCMCGetx () const
 
std::vector< double > MCMCGetx (unsigned ichain)
 
double MCMCGetx (unsigned ichain, unsigned ipar) const
 
const std::vector< double > & MCMCGetLogProbx () const
 
double MCMCGetLogProbx (unsigned ichain)
 
int MCMCGetPhase () const
 
const std::vector< double > & MCMCGetMaximumPoints () const
 
std::vector< double > MCMCGetMaximumPoint (unsigned i) const
 
const std::vector< double > & MCMCGetMaximumLogProb () const
 
int MCMCGetFlagInitialPosition () const
 
double MCMCGetRValueCriterion () const
 
double MCMCGetRValueParametersCriterion () const
 
double MCMCGetRValue () const
 
double MCMCGetRValueParameters (unsigned i)
 
bool MCMCGetRValueStrict () const
 
bool MCMCGetFlagRun () const
 
TTree * MCMCGetMarkovChainTree (unsigned i)
 
BCH1DMCMCGetH1Marginalized (unsigned i)
 
BCH2DMCMCGetH2Marginalized (unsigned i, unsigned j)
 
BCParameterGetParameter (int index) const
 
BCParameterGetParameter (const char *name) const
 
unsigned int GetNParameters () const
 
unsigned int GetNFixedParameters ()
 
unsigned int GetNFreeParameters ()
 
const std::vector< double > & GetBestFitParametersMarginalized () const
 
void MCMCSetTrialFunctionScaleFactor (std::vector< double > scale)
 
void MCMCSetNChains (unsigned n)
 
void MCMCSetNLag (unsigned n)
 
void MCMCSetNIterationsMax (unsigned n)
 
void MCMCSetNIterationsRun (unsigned n)
 
void MCMCSetNIterationsPreRunMin (unsigned n)
 
void MCMCSetNIterationsUpdate (unsigned n)
 
void MCMCSetNIterationsUpdateMax (unsigned n)
 
void MCMCSetMinimumEfficiency (double efficiency)
 
void MCMCSetMaximumEfficiency (double efficiency)
 
void MCMCSetRandomSeed (unsigned seed)
 
void MCMCSetWriteChainToFile (bool flag)
 
void MCMCSetWritePreRunToFile (bool flag)
 
void MCMCSetInitialPositions (const std::vector< double > &x0s)
 
void MCMCSetInitialPositions (std::vector< std::vector< double > > x0s)
 
void MCMCSetFlagInitialPosition (int flag)
 
void MCMCSetFlagOrderParameters (bool flag)
 
void MCMCSetFlagFillHistograms (bool flag)
 
void MCMCSetFlagPreRun (bool flag)
 
void MCMCSetRValueCriterion (double r)
 
void MCMCSetRValueParametersCriterion (double r)
 
void MCMCSetRValueStrict (bool strict=true)
 
void MCMCSetMarkovChainTrees (const std::vector< TTree * > &trees)
 
void MCMCInitializeMarkovChainTrees ()
 
int SetMarginalized (unsigned index, TH1D *h)
 
int SetMarginalized (unsigned index1, unsigned index2, TH2D *h)
 
void MCMCSetValuesDefault ()
 
void MCMCSetValuesQuick ()
 
void MCMCSetValuesDetail ()
 
void MCMCSetPrecision (BCEngineMCMC::Precision precision)
 
void SetNbins (unsigned int nbins)
 
void Copy (const BCEngineMCMC &enginemcmc)
 
virtual int AddParameter (const char *name, double min, double max, const char *latexname="")
 
virtual void MCMCTrialFunction (unsigned ichain, std::vector< double > &x)
 
virtual double MCMCTrialFunctionSingle (unsigned ichain, unsigned ipar)
 
bool MCMCGetProposalPointMetropolis (unsigned chain, std::vector< double > &x)
 
bool MCMCGetProposalPointMetropolis (unsigned chain, unsigned parameter, std::vector< double > &x)
 
bool MCMCGetNewPointMetropolis (unsigned chain=0)
 
bool MCMCGetNewPointMetropolis (unsigned chain, unsigned parameter)
 
void MCMCInChainCheckMaximum ()
 
void MCMCInChainUpdateStatistics ()
 
void MCMCInChainFillHistograms ()
 
void MCMCInChainTestConvergenceAllChains ()
 
void MCMCInChainWriteChains ()
 
int MCMCMetropolis ()
 
int MCMCMetropolisPreRun ()
 
void MCMCResetRunStatistics ()
 
void MCMCInitializeMarkovChains ()
 
int MCMCInitialize ()
 
void ClearParameters (bool hard=false)
 
virtual void MCMCIterationInterface ()
 
virtual void MCMCUserIterationInterface ()
 
virtual void MCMCCurrentPointInterface (std::vector< double > &, int, bool)
 

Protected Attributes

std::string fName
 
double fModelAPriori
 
double fModelAPosteriori
 
BCDataSetfDataSet
 
BCDataPointfDataPointLowerBoundaries
 
BCDataPointfDataPointUpperBoundaries
 
std::vector< bool > fDataFixedValues
 
double fPValue
 
double fChi2NDoF
 
double fPValueNDoF
 
bool flag_discrete
 
int fGoFNIterationsMax
 
int fGoFNIterationsRun
 
int fGoFNChains
 
std::vector< TNamed * > fPriorContainer
 
bool fPriorConstantAll
 
std::vector< bool > fPriorContainerConstant
 
std::vector< bool > fPriorContainerInterpolate
 
- Protected Attributes inherited from BCIntegrate
int fID
 
TMinuit * fMinuit
 
double fMinuitArglist [2]
 
int fMinuitErrorFlag
 
bool fFlagIgnorePrevOptimization
 
double fSAT0
 
double fSATmin
 
TTree * fTreeSA
 
bool fFlagWriteSAToFile
 
int fSANIterations
 
double fSATemperature
 
double fSALogProb
 
std::vector< double > fSAx
 
std::vector< BCH1D * > fMarginalized1D
 
std::vector< BCH2D * > fMarginalized2D
 
bool fFlagMarginalized
 
- Protected Attributes inherited from BCEngineMCMC
BCParameterSet fParameters
 
unsigned fMCMCNChains
 
unsigned fMCMCNLag
 
std::vector< unsigned > fMCMCNIterations
 
int fMCMCCurrentIteration
 
int fMCMCCurrentChain
 
unsigned fMCMCNIterationsUpdate
 
unsigned fMCMCNIterationsUpdateMax
 
int fMCMCNIterationsConvergenceGlobal
 
bool fMCMCFlagConvergenceGlobal
 
unsigned fMCMCNIterationsMax
 
unsigned fMCMCNIterationsRun
 
unsigned fMCMCNIterationsPreRunMin
 
std::vector< int > fMCMCNTrialsTrue
 
unsigned fMCMCNTrials
 
bool fMCMCFlagWriteChainToFile
 
bool fMCMCFlagWritePreRunToFile
 
std::vector< double > fMCMCTrialFunctionScaleFactor
 
std::vector< double > fMCMCTrialFunctionScaleFactorStart
 
bool fMCMCFlagPreRun
 
bool fMCMCFlagRun
 
std::vector< double > fMCMCInitialPosition
 
double fMCMCEfficiencyMin
 
double fMCMCEfficiencyMax
 
int fMCMCFlagInitialPosition
 
bool fMCMCFlagOrderParameters
 
int fMCMCPhase
 
std::vector< double > fMCMCx
 
std::vector< double > fMCMCxMax
 
std::vector< double > fMCMCxMean
 
std::vector< double > fMCMCxVar
 
std::vector< double > fMCMCprob
 
std::vector< double > fMCMCprobMax
 
std::vector< double > fMCMCprobMean
 
std::vector< double > fMCMCprobVar
 
bool fMCMCRValueUseStrict
 
double fMCMCRValueCriterion
 
double fMCMCRValueParametersCriterion
 
double fMCMCRValue
 
std::vector< double > fMCMCRValueParameters
 
TRandom3 * fRandom
 
std::vector< TH1D * > fMCMCH1Marginalized
 
std::vector< TH2D * > fMCMCH2Marginalized
 
std::vector< TTree * > fMCMCTrees
 
std::vector< double > fMCMCBestFitParameters
 
double fMCMCLogMaximum
 
std::vector< double > fMarginalModes
 

Private Member Functions

int CompareStrings (const char *string1, const char *string2)
 
BCDataPointVectorToDataPoint (const std::vector< double > &data)
 

Additional Inherited Members

- Public Types inherited from BCIntegrate
enum  BCOptimizationMethod {
  kOptEmpty, kOptSimAnn, kOptMetropolis, kOptMinuit,
  kOptDefault, NOptMethods
}
 
enum  BCIntegrationMethod {
  kIntEmpty, kIntMonteCarlo, kIntCuba, kIntGrid,
  kIntDefault, NIntMethods
}
 
enum  BCMarginalizationMethod {
  kMargEmpty, kMargMetropolis, kMargMonteCarlo, kMargGrid,
  kMargDefault, NMargMethods
}
 
enum  BCSASchedule { kSACauchy, kSABoltzmann, kSACustom, NSAMethods }
 
enum  BCCubaMethod {
  kCubaVegas, kCubaSuave, kCubaDivonne, kCubaCuhre,
  NCubaMethods
}
 
typedef void(BCIntegrate::* tRandomizer )(std::vector< double > &) const
 
typedef double(BCIntegrate::* tEvaluator )(std::vector< double > &, const std::vector< double > &, bool &)
 
typedef void(* tIntegralUpdater )(const std::vector< double > &, const int &, double &, double &)
 
- Static Public Member Functions inherited from BCIntegrate
static void IntegralUpdaterMC (const std::vector< double > &sums, const int &nIterations, double &integral, double &absprecision)
 
static int CubaIntegrand (const int *ndim, const double xx[], const int *ncomp, double ff[], void *userdata)
 
static void FCNLikelihood (int &npar, double *grad, double &fval, double *par, int flag)
 
- Protected Member Functions inherited from BCIntegrate
unsigned IntegrationOutputFrequency () const
 
void LogOutputAtStartOfIntegration (BCIntegrationMethod type, BCCubaMethod cubatype)
 
void LogOutputAtIntegrationStatusUpdate (BCIntegrationMethod type, double integral, double absprecision, int nIterations)
 
void LogOutputAtEndOfIntegration (double integral, double absprecision, double relprecision, int nIterations)
 
void Copy (const BCIntegrate &bcintegrate)
 

Detailed Description

The base class for all user-defined models.

Author
Daniel Kollar
Kevin Kröninger
Version
1.0
Date
08.2008 This class represents a model. It contains a container of prior distributions and the likelihood. The methods that implement the prior and the likelihood have to be overloaded by the user in the user defined model class derived from this class.

Definition at line 50 of file BCModel.h.

Constructor & Destructor Documentation

BCModel::BCModel ( const char *  name = "model")

A constructor.

Parameters
nameThe name of the model

Definition at line 36 of file BCModel.cxx.

36  :
37  BCIntegrate(),
38  fName((char *) name),
39  fModelAPriori(0),
41  fDataSet(0),
44  fPValue(-1),
45  fChi2NDoF(-1),
46  fPValueNDoF(-1),
47  flag_discrete(false),
48  fGoFNIterationsMax(100000),
49  fGoFNIterationsRun(2000),
50  fGoFNChains(5),
51  fPriorConstantAll(false)
52 {
53 }
BCModel::BCModel ( const BCModel bcmodel)

The copy constructor.

Definition at line 56 of file BCModel.cxx.

56  : BCIntegrate(bcmodel)
57 {
58  Copy(bcmodel);
59 }
BCModel::~BCModel ( )
virtual

The default destructor.

Definition at line 104 of file BCModel.cxx.

105 {
106  for (unsigned int i = 0; i < GetNParameters(); ++i)
107  delete fPriorContainer[i];
108  fPriorContainer.clear();
109 
112 }

Member Function Documentation

int BCModel::AddParameter ( BCParameter parameter)
virtual

Adds a parameter to the model.

Parameters
parameterA model parameter
See Also
AddParameter(const char * name, double lowerlimit, double upperlimit);

Reimplemented from BCEngineMCMC.

Definition at line 225 of file BCModel.cxx.

226 {
227  if ( !BCEngineMCMC::AddParameter(parameter))
228  return 1;
229 
230  // add empty object to prior container
231  fPriorContainer.push_back(0);
232 
233  // don't interpolate the prior histogram by default
234  fPriorContainerInterpolate.push_back(false);
235 
236  // prior assumed to be non-constant in general case
237  fPriorContainerConstant.push_back(false);
238 
239  return 0;
240 }
double BCModel::APrioriProbability ( const std::vector< double > &  parameters)

Returns the prior probability.

Parameters
parametersA set of parameter values
Returns
The prior probability p(parameters)
See Also
GetPrior(std::vector<double> parameters)

Definition at line 267 of file BCModel.cxx.

268 {
269  return exp(this->LogAPrioriProbability(parameters) );
270 }
BCH1D * BCModel::CalculatePValue ( std::vector< double >  par,
bool  flag_histogram = false 
)

Definition at line 451 of file BCModel.cxx.

452 {
453  BCH1D * hist = 0;
454 
455  // print log
456  BCLog::OutSummary("Do goodness-of-fit-test");
457 
458  // create model test
459  BCGoFTest * goftest = new BCGoFTest("modeltest");
460 
461  // set this model as the model to be tested
462  goftest->SetTestModel(this);
463 
464  // set the point in parameter space which is tested an initialize
465  // the model testing
466  if (!goftest->SetTestPoint(par))
467  return 0;
468 
469  // disable the creation of histograms to save _a lot_ of memory
470  // (histograms are not needed for p-value calculation)
471  goftest->MCMCSetFlagFillHistograms(false);
472 
473  // set parameters of the MCMC for the GoFTest
474  goftest->MCMCSetNChains(fGoFNChains);
477 
478  // get p-value
479  fPValue = goftest->GetCalculatedPValue(flag_histogram);
480 
481  // get histogram
482  if (flag_histogram) {
483  hist = new BCH1D();
484  hist->SetHistogram(goftest->GetHistogramLogProb());
485  }
486 
487  // delete model test
488  delete goftest;
489 
490  // return histogram
491  return hist;
492 }
virtual double BCModel::CDF ( const std::vector< double > &  ,
int  ,
bool   
)
inlinevirtual

1dim cumulative distribution function of the probability to get the data f(x_i|param) for a single measurement, assumed to be of identical functional form for all measurements

Parameters
parametersThe parameter values at which point to compute the cdf
indexThe data point index starting at 0,1...N-1
loweronly needed for discrete distributions! Return the CDF for the count one less than actually observed, e.g. in Poisson process, if 3 actually observed, then CDF(2) is returned

Reimplemented in BCHistogramFitter, and BCGraphFitter.

Definition at line 502 of file BCModel.h.

503  {return 0.0;}
int BCModel::CompareStrings ( const char *  string1,
const char *  string2 
)
private

Compares to strings

Definition at line 1094 of file BCModel.cxx.

1095 {
1096  int flag_same = 0;
1097 
1098  if (strlen(string1) != strlen(string2))
1099  return -1;
1100 
1101  for (int i = 0; i < int(strlen(string1)); i++)
1102  if (string1[i] != string2[i])
1103  flag_same = -1;
1104 
1105  return flag_same;
1106 }
void BCModel::Copy ( const BCModel bcmodel)

Copy from object

Parameters
bcmodelObject to copy from.

Definition at line 62 of file BCModel.cxx.

63 {
64  // called for the second time in copy constructor? do copy-and-swap instead
65  // BCIntegrate::Copy(bcmodel);
66  fName = bcmodel.fName;
67  fModelAPriori = bcmodel.fModelAPriori;
69  if (fDataSet)
70  fDataSet = bcmodel.fDataSet;
71  else
72  fDataSet = 0;
73 
74  if (bcmodel.fDataPointLowerBoundaries)
76  else
78  if (bcmodel.fDataPointUpperBoundaries)
80  else
82 
84 
85  fPValue = bcmodel.fPValue;
86  fChi2NDoF = bcmodel.fChi2NDoF;
87  fPValueNDoF = bcmodel.fPValueNDoF;
88  flag_discrete = bcmodel.flag_discrete;
91  fGoFNChains = bcmodel.fGoFNChains;
92  for (int i = 0; i < int(bcmodel.fPriorContainer.size()); ++i) {
93  if (bcmodel.fPriorContainer.at(i))
94  fPriorContainer.push_back(new TNamed(*bcmodel.fPriorContainer.at(i)));
95  else
96  fPriorContainer.push_back(0);
97  }
101 }
void BCModel::CorrelateDataPointValues ( std::vector< double > &  x)
virtual

Constrains a data point

Parameters
xA vector of double

Definition at line 495 of file BCModel.cxx.

496 {
497  // ...
498 }
double BCModel::Eval ( const std::vector< double > &  parameters)
virtual

Overloaded function to evaluate integral.

Reimplemented from BCIntegrate.

Definition at line 330 of file BCModel.cxx.

331 {
332  return exp(LogEval(parameters));
333 }
double BCModel::GetChi2NDoF ( )
inline

Definition at line 441 of file BCModel.h.

442  { return fChi2NDoF; }
std::vector< double > BCModel::GetChi2Runs ( int  dataIndex,
int  sigmaIndex 
)

For a Gaussian problem, calculate the chi2 of the longest run of consecutive values above/below the expected values

Parameters
dataIndexcomponent of datapoint with the observed value
sigmaIndexcomponent of datapoint with uncertainty

Definition at line 368 of file BCModel.cxx.

369 {
370  std::vector<double> x;
371  return x;
372 }
BCDataPoint * BCModel::GetDataPoint ( unsigned int  index) const
Parameters
indexThe index of the data point.
Returns
The data point in the current data set at index

Definition at line 132 of file BCModel.cxx.

133 {
134  if (fDataSet)
135  return fDataSet->GetDataPoint(index);
136 
137  BCLog::OutWarning("BCModel::GetDataPoint : No data set defined.");
138  return 0;
139 }
BCDataPoint* BCModel::GetDataPointLowerBoundaries ( ) const
inline
Returns
The lower boundaries of possible data values.

Definition at line 105 of file BCModel.h.

106  { return fDataPointLowerBoundaries; }
double BCModel::GetDataPointLowerBoundary ( unsigned int  index) const
Parameters
indexThe index of the variable.
Returns
The lower boundary of possible data values for a particular variable.

Definition at line 142 of file BCModel.cxx.

143 {
144  return fDataPointLowerBoundaries -> GetValue(index);
145 }
BCDataPoint* BCModel::GetDataPointUpperBoundaries ( ) const
inline
Returns
The upper boundaries of possible data values.

Definition at line 110 of file BCModel.h.

111  { return fDataPointUpperBoundaries; }
double BCModel::GetDataPointUpperBoundary ( unsigned int  index) const
Parameters
indexThe index of the variable.
Returns
The upper boundary of possible data values for a particular variable.

Definition at line 148 of file BCModel.cxx.

149 {
150  return fDataPointUpperBoundaries -> GetValue(index);
151 }
BCDataSet* BCModel::GetDataSet ( ) const
inline
Returns
The data set.

Definition at line 100 of file BCModel.h.

101  { return fDataSet; }
bool BCModel::GetFlagBoundaries ( ) const

Checks if the boundaries have been defined

Returns
true, if the boundaries have been set, false otherwise

Definition at line 154 of file BCModel.cxx.

155 {
157  return false;
158 
160  return false;
161 
163  return false;
164 
166  return false;
167 
168  return true;
169 }
double BCModel::GetModelAPosterioriProbability ( ) const
inline
Returns
The a posteriori probability.

Definition at line 95 of file BCModel.h.

96  { return fModelAPosteriori; }
double BCModel::GetModelAPrioriProbability ( ) const
inline
Returns
The a priori probability.

Definition at line 90 of file BCModel.h.

91  { return fModelAPriori; }
const std::string& BCModel::GetName ( ) const
inline
Returns
The name of the model.

Definition at line 85 of file BCModel.h.

86  { return fName; }
unsigned BCModel::GetNDataPoints ( ) const
Returns
The number of data points in the current data set.

Definition at line 123 of file BCModel.cxx.

124 {
125  if (fDataSet)
126  return fDataSet->GetNDataPoints();
127  else
128  return 0;
129  }
double BCModel::GetPValue ( )
inline
Returns
The p-value

Definition at line 435 of file BCModel.h.

436  { return fPValue; }
double BCModel::GetPvalueFromChi2 ( const std::vector< double > &  par,
int  sigma_index 
)

Calculate p-value from Chi2 distribution for Gaussian problems

Parameters
parParameter set for the calculation of the likelihood
sigma_indexIndex of the sigma/uncertainty for the data points (for data in format "x y erry" the index would be 2)

Definition at line 351 of file BCModel.cxx.

352 {
353  double ll = LogLikelihood(par);
354  int n = GetNDataPoints();
355 
356  double sum_sigma = 0;
357  for (int i = 0; i < n; i++)
358  sum_sigma += log(GetDataPoint(i)->GetValue(sigma_index));
359 
360  double chi2 = -2. * (ll + (double) n / 2. * log(2. * M_PI) + sum_sigma);
361 
362  fPValue = TMath::Prob(chi2, n);
363 
364  return fPValue;
365 }
double BCModel::GetPvalueFromChi2NDoF ( std::vector< double >  par,
int  sigma_index 
)

Definition at line 375 of file BCModel.cxx.

376 {
377  double ll = LogLikelihood(par);
378  int n = GetNDataPoints();
379  int npar = GetNParameters();
380 
381  double sum_sigma = 0;
382  for (int i = 0; i < n; i++)
383  sum_sigma += log(GetDataPoint(i)->GetValue(sigma_index));
384 
385  double chi2 = -2. * (ll + (double) n / 2. * log(2. * M_PI) + sum_sigma);
386 
387  fChi2NDoF = chi2 / double(n - npar);
388  fPValueNDoF = TMath::Prob(chi2, n - npar);
389 
390  return fPValueNDoF;
391 }
double BCModel::GetPvalueFromKolmogorov ( const std::vector< double > &  par,
int  index 
)

Calculate p-value from Kolmogorov-Smirnov test statistic for 1D - datasets.

Parameters
parParameter set for the calculation of the likelihood
indexIndex of the data point in the BCDataSet (for data in format "x y erry" the index would be 1)

Definition at line 394 of file BCModel.cxx.

395 {
396  if (flag_discrete) {
397  BCLog::OutError(Form("BCModel::GetPvalueFromKolmogorov : "
398  "test defined only for continuous distributions."));
399  return -1.;
400  }
401 
402  //calculate the ECDF from the 1D data
403  std::vector<double> yData = fDataSet->GetDataComponents(index);
404  TH1D * ECDF = BCMath::ECDF(yData);
405 
406  int N = GetNDataPoints();
407 
408  // calculated expected CDF for unique points only
409  std::set<double> uniqueObservations;
410  for (int i = 0; i < N; i++)
411  uniqueObservations.insert(CDF(par, i, false));
412 
413  int nUnique = uniqueObservations.size();
414  if (nUnique != ECDF->GetNbinsX() + 1) {
415  BCLog::OutError(Form("BCModel::GetPvalueFromKolmogorov : "
416  "Number of unique data points doesn't match (%d vs %d)", nUnique,
417  ECDF->GetNbinsX() + 1));
418  return -1.;
419  }
420 
421  // find maximum distance
422  double distMax = 0.;
423 
424  // current distance
425  double dist = 0.;
426 
427  std::set<double>::const_iterator iter = uniqueObservations.begin();
428  for (int iBin = 0; iBin < nUnique; ++iBin) {
429  // distance between current points
430  dist = TMath::Abs(*iter - ECDF->GetBinContent(iBin + 1));
431  // update maximum if necessary
432  distMax = TMath::Max(dist, distMax);
433 
434  // advance to next entry in the set
435  ++iter;
436  }
437 
438  // correct for total #points, not unique #points.
439  // would need sqrt(n1*n2/(n1+n2)) if we had two experimental datasets
440  double z = distMax * sqrt(N);
441 
442  fPValue = TMath::KolmogorovProb(z);
443 
444  // clean up
445  delete ECDF;
446 
447  return fPValue;
448 }
double BCModel::GetPValueNDoF ( )
inline

Definition at line 438 of file BCModel.h.

439  { return fPValueNDoF; }
double BCModel::HessianMatrixElement ( const BCParameter parameter1,
const BCParameter parameter2,
std::vector< double >  point 
)

Calculates the matrix element of the Hessian matrix

Parameters
parameter1The parameter for the first derivative
parameter2The parameter for the first derivative
Returns
The matrix element of the Hessian matrix

Definition at line 501 of file BCModel.cxx.

502 {
503  // check number of entries in vector
504  if (point.size() != GetNParameters()) {
505  BCLog::OutError("BCModel::HessianMatrixElement : Invalid number of entries in the vector.");
506  return -1;
507  }
508 
509  // define steps
510  double nsteps = 1e5;
511  double dx1 = par1->GetRangeWidth() / nsteps;
512  double dx2 = par2->GetRangeWidth() / nsteps;
513 
514  // define points at which to evaluate
515  std::vector<double> xpp = point;
516  std::vector<double> xpm = point;
517  std::vector<double> xmp = point;
518  std::vector<double> xmm = point;
519 
520  unsigned idx1 = fParameters.Index(par1->GetName());
521  unsigned idx2 = fParameters.Index(par2->GetName());
522 
523  xpp[idx1] += dx1;
524  xpp[idx2] += dx2;
525 
526  xpm[idx1] += dx1;
527  xpm[idx2] -= dx2;
528 
529  xmp[idx1] -= dx1;
530  xmp[idx2] += dx2;
531 
532  xmm[idx1] -= dx1;
533  xmm[idx2] -= dx2;
534 
535  // calculate probability at these points
536  double ppp = Likelihood(xpp);
537  double ppm = Likelihood(xpm);
538  double pmp = Likelihood(xmp);
539  double pmm = Likelihood(xmm);
540 
541  // return derivative
542  return (ppp + pmm - ppm - pmp) / (4. * dx1 * dx2);
543 }
double BCModel::Likelihood ( const std::vector< double > &  params)
virtual

Returns the likelihood

Parameters
paramsA set of parameter values
Returns
The likelihood

Definition at line 324 of file BCModel.cxx.

325 {
326  return exp(LogLikelihood(params));
327 }
double BCModel::LogAPrioriProbability ( const std::vector< double > &  parameters)
virtual

Returns natural logarithm of the prior probability. Method needs to be overloaded by the user.

Parameters
parametersA set of parameter values
Returns
The prior probability p(parameters)
See Also
GetPrior(std::vector<double> parameters)

Reimplemented in BCGoFTest, BCMVCDataModel, BCSummaryPriorModel, and BCRooInterface.

Definition at line 273 of file BCModel.cxx.

274 {
275  double logprob = 0;
276 
277  // loop over all parameters, assume prior factorizes
278  // into n independent parts
279  for (unsigned i = 0; i < fParameters.Size(); ++i) {
280  BCParameter * par = fParameters[i];
281 
282  // avoid fixed and zero-width parameters
283  if (par->Fixed() or not par->GetRangeWidth())
284  continue;
285 
286  if (fPriorContainerConstant[i]) {
287  logprob -= log(par->GetRangeWidth());
288  continue;
289  }
290 
291  if (fPriorContainer[i]) {
292  // check what type of object is stored
293  TF1 * f = dynamic_cast<TF1*>(fPriorContainer[i]);
294  TH1 * h = dynamic_cast<TH1*>(fPriorContainer[i]);
295 
296  if (f) // TF1
297  logprob += log(f->Eval(parameters[i]));
298  else if (h) { // TH1
300  logprob += log(h->Interpolate(parameters[i]));
301  else
302  logprob += log(h->GetBinContent(h->FindBin(parameters[i])));
303  }
304  else
305  BCLog::OutError(Form(
306  "BCModel::LogAPrioriProbability : Prior for parameter %s "
307  "is defined but not recognized.",
308  par->GetName().c_str())); // this should never happen
309  }
310  // use constant only if user has defined it
311  else {
312  BCLog::OutError(Form(
313  "BCModel::LogAPrioriProbability: Prior for parameter %s "
314  "is undefined. Using constant prior to proceed.",
315  par->GetName().c_str()));
316  logprob -= log(par->GetRangeWidth());
317  }
318  }
319 
320  return logprob;
321 }
double BCModel::LogEval ( const std::vector< double > &  parameters)
virtual

Overloaded function to evaluate integral.

Reimplemented from BCIntegrate.

Definition at line 336 of file BCModel.cxx.

337 {
338  return LogProbabilityNN(parameters);
339 }
virtual double BCModel::LogLikelihood ( const std::vector< double > &  params)
pure virtual

Calculates natural logarithm of the likelihood. Method needs to be overloaded by the user.

Parameters
paramsA set of parameter values
Returns
Natural logarithm of the likelihood

Implemented in BCMTF, BCEfficiencyFitter, BCMVCombination, BCHistogramFitter, BCGraphFitter, BCGoFTest, BCMVCDataModel, BCSummaryPriorModel, BCMVCPhysicsModel, and BCRooInterface.

double BCModel::LogProbability ( const std::vector< double > &  parameter)

Returns natural logarithm of the a posteriori probability given a set of parameter values

Parameters
parametersA set of parameter values
Returns
The a posteriori probability

Definition at line 255 of file BCModel.cxx.

256 {
257  // check if normalized
258  if (GetIntegral() <= 0.) {
259  BCLog::OutError("BCModel::LogProbability. Normalization not available or zero.");
260  return 0.;
261  }
262 
263  return LogProbabilityNN(parameters) - log(GetIntegral());
264 }
double BCModel::LogProbabilityNN ( const std::vector< double > &  parameters)
inline

Returns the natural logarithm of likelihood times prior probability given a set of parameter values

Parameters
parametersA set of parameter values
Returns
The likelihood times prior probability

Definition at line 378 of file BCModel.h.

379  { return LogLikelihood(parameters) + LogAPrioriProbability(parameters); }
BCModel & BCModel::operator= ( const BCModel bcmodel)

Defaut assignment operator

Definition at line 115 of file BCModel.cxx.

116 {
117  Copy(bcmodel);
118 
119  return *this;
120 }
void BCModel::PrintHessianMatrix ( std::vector< double >  parameters)

Prints matrix elements of the Hessian matrix

Parameters
parametersThe parameter values at which point to evaluate the matrix

Definition at line 1057 of file BCModel.cxx.

1058 {
1059  // check number of entries in vector
1060  if (parameters.size() != GetNParameters()) {
1061  BCLog::OutError("BCModel::PrintHessianMatrix : Invalid number of entries in the vector");
1062  return;
1063  }
1064 
1065  // print to screen
1066  BCLog::OutSummary("Hessian matrix elements: ");
1067  BCLog::OutSummary("Parameter values:");
1068 
1069  for (int i = 0; i < int(parameters.size()); i++)
1070  BCLog::OutSummary(Form("Parameter %d : %f", i, parameters.at(i)));
1071 
1072  BCLog::OutSummary("Hessian matrix:");
1073  // loop over all parameter pairs
1074  for (unsigned int i = 0; i < GetNParameters(); i++)
1075  for (unsigned int j = 0; j < i; j++) {
1076  // calculate Hessian matrix element
1077  double hessianmatrixelement = HessianMatrixElement(
1078  fParameters[i], fParameters[j], parameters);
1079 
1080  // print to screen
1081  BCLog::OutSummary(Form("%d %d : %f", i, j, hessianmatrixelement));
1082  }
1083 }
void BCModel::PrintResults ( const char *  file)

Prints a summary of the Markov Chain Monte Carlo to a file.

Definition at line 816 of file BCModel.cxx.

817 {
818  // print summary of Markov Chain Monte Carlo
819 
820  // open file
821  std::ofstream ofi(file);
822 
823  // check if file is open
824  if (!ofi.is_open()) {
825  std::cerr << "Couldn't open file " << file << std::endl;
826  return;
827  }
828 
829  // number of parameters and chains
830  unsigned npar = GetNParameters();
831  unsigned nchains = MCMCGetNChains();
832 
833  // check convergence
834  bool flag_conv = MCMCGetNIterationsConvergenceGlobal() > 0;
835 
836  ofi << std::endl
837  << " -----------------------------------------------------" << std::endl
838  << " Summary" << std::endl
839  << " -----------------------------------------------------" << std::endl
840  << std::endl;
841 
842  ofi << " Model summary" << std::endl << " =============" << std::endl
843  << " Model: " << fName.data() << std::endl
844  << " Number of parameters: " << npar << std::endl
845  << " List of Parameters and ranges:" << std::endl;
846  for (unsigned i = 0; i < npar; ++i) {
847  ofi << " (" << i << ") Parameter \""
848  << fParameters[i]->GetName() << "\"" << ": "
849  << "[" << fParameters[i]->GetLowerLimit() << ", "
850  << fParameters[i]->GetUpperLimit() << "]";
851  if (fParameters[i]->Fixed()) {
852  ofi << " (fixed)";
853  }
854  ofi << std::endl;
855  }
856  ofi << std::endl;
857 
858  ofi << " Results of the optimization" << std::endl
859  << " ===========================" << std::endl
860  << " Optimization algorithm used: "
861  << DumpUsedOptimizationMethod()<< std::endl;
862 
863  if ( ! GetBestFitParameters().empty()) {
864  ofi << " Log of the maximum posterior: " << GetLogMaximum() << std::endl;
865  ofi << " List of parameters and global mode:" << std::endl;
866  for (unsigned i = 0; i < npar; ++i) {
867  ofi << " (" << i << ") Parameter \""
868  << fParameters[i]->GetName() << "\": "
869  << GetBestFitParameter(i);
870  if (fParameters[i]->Fixed()) {
871  ofi << " (fixed)";
872  }
873  else if (GetBestFitParameterErrors().size() == npar) {
874  if(GetBestFitParameterError(i) >= 0.)
875  ofi << " +- " << GetBestFitParameterError(i);
876  else
877  ofi << " (no error estimate available) ";
878  }
879  else {
880  ofi << " (no error estimate available) ";
881  }
882  ofi << std::endl;
883  }
884  ofi << std::endl;
885  }
886  else {
887  ofi << " No best fit information available." << std::endl;
888  ofi << std::endl;
889  }
890 
891  if (fPValue >= 0.) {
892  ofi << " Results of the model test" << std::endl
893  << " =========================" << std::endl
894  << " p-value: " << fPValue << std::endl;
895  if (fPValueNDoF >= 0)
896  ofi << " p-value corrected for degrees of freedom: " << fPValueNDoF << std::endl;
897 
898  ofi << std::endl;
899  }
900 
901  if (GetIntegral() >= 0.) {
902  ofi << " Results of the integration" << std::endl
903  << " ============================" << std::endl
904  << " Integration method used: "
905  << DumpUsedIntegrationMethod() << std::endl;
906  ofi << " Evidence: " << GetIntegral();
907  if (GetError() >= 0)
908  ofi << " +- " << GetError() << std::endl;
909  else
910  ofi << " (no error estimate available) " << std::endl;
911  ofi << std::endl;
912  }
913 
914  // give warning if MCMC did not converge
915  if (!flag_conv && fMCMCFlagRun)
916  ofi << " WARNING: the Markov Chain did not converge!" << std::endl
917  << " Be cautious using the following results!" << std::endl
918  << std::endl;
919 
920  // print results of marginalization (if MCMC was run)
921  if (fFlagMarginalized) {
922  ofi << " Results of the marginalization" << std::endl
923  << " ==============================" << std::endl
924  << " Marginalization algorithm used: "
925  << DumpUsedMarginalizationMethod() << std::endl
926  << " List of parameters and properties of the marginalized"
927  << std::endl << " distributions:" << std::endl;
928  for (unsigned i = 0; i < npar; ++i) {
929  if ( ! fParameters[i]->FillHistograms())
930  continue;
931 
932  // get marginalized histogram
933  BCH1D * bch1d = GetMarginalized(fParameters[i]);
934 
935  ofi << " (" << i << ") Parameter \""
936  << fParameters[i]->GetName() << "\":";
937 
938  if (!bch1d) {
939  ofi << " fixed (or histogram does not exist) " << std::endl;
940  continue;
941  }
942  else
943  ofi << std::endl;
944 
945  ofi << " Mean +- sqrt(V): " << std::setprecision(4)
946  << bch1d->GetMean() << " +- " << std::setprecision(4)
947  << bch1d->GetRMS() << std::endl
948 
949  << " Median +- central 68% interval: "
950  << std::setprecision(4) << bch1d->GetMedian() << " + "
951  << std::setprecision(4) << bch1d->GetQuantile(0.84) - bch1d->GetMedian()
952  << " - " << std::setprecision(4)
953  << bch1d->GetMedian() - bch1d->GetQuantile(0.16) << std::endl
954 
955  << " (Marginalized) mode: " << bch1d->GetMode() << std::endl;
956 
957  ofi << " 5% quantile: " << std::setprecision(4)
958  << bch1d->GetQuantile(0.05) << std::endl
959  << " 10% quantile: " << std::setprecision(4)
960  << bch1d->GetQuantile(0.10) << std::endl
961  << " 16% quantile: " << std::setprecision(4)
962  << bch1d->GetQuantile(0.16) << std::endl
963  << " 84% quantile: " << std::setprecision(4)
964  << bch1d->GetQuantile(0.85) << std::endl
965  << " 90% quantile: " << std::setprecision(4)
966  << bch1d->GetQuantile(0.90) << std::endl
967  << " 95% quantile: " << std::setprecision(4)
968  << bch1d->GetQuantile(0.95) << std::endl;
969 
970  std::vector<double> v;
971  v = bch1d->GetSmallestIntervals(0.68);
972  ofi << " Smallest interval(s) containing at least 68% and local mode(s):"
973  << std::endl;
974  for (unsigned j = 0; j < v.size(); j += 5)
975  ofi << " (" << v[j] << ", " << v[j + 1]
976  << ") (local mode at " << v[j + 3] << " with rel. height "
977  << v[j + 2] << "; rel. area " << v[j + 4] << ")"
978  << std::endl;
979  ofi << std::endl;
980  }
981  }
982  if (fMCMCFlagRun) {
983  ofi << " Status of the MCMC" << std::endl << " ==================" << std::endl
984  << " Convergence reached: " << (flag_conv ? "yes" : "no")
985  << std::endl;
986 
987  if (flag_conv)
988  ofi << " Number of iterations until convergence: "
989  << MCMCGetNIterationsConvergenceGlobal() << std::endl;
990  else
991  ofi << " WARNING: the Markov Chain did not converge! Be\n"
992  << " cautious using the following results!" << std::endl
993  << std::endl;
994  ofi << " Number of chains: " << MCMCGetNChains() << std::endl
995  << " Number of iterations per chain: " << MCMCGetNIterationsRun() << std::endl
996  << " Average efficiencies:" << std::endl;
997 
998  std::vector<double> efficiencies;
999  efficiencies.assign(npar, 0.);
1000 
1001  for (unsigned ipar = 0; ipar < npar; ++ipar)
1002  for (unsigned ichain = 0; ichain < nchains; ++ichain) {
1003  unsigned index = ichain * npar + ipar;
1004  efficiencies[ipar] +=
1005  double(MCMCGetNTrialsTrue().at(index)) / double(MCMCGetNTrials()) / double(nchains) * 100.;
1006  }
1007 
1008  for (unsigned ipar = 0; ipar < npar; ++ipar)
1009  ofi << " (" << ipar << ") Parameter \""
1010  << fParameters[ipar]->GetName().data() << "\": "
1011  << efficiencies.at(ipar) << "%" << std::endl;
1012  ofi << std::endl;
1013  }
1014 
1015  ofi << " -----------------------------------------------------" << std::endl
1016  << " Notation:" << std::endl
1017  << " Mean : mean value of the marg. pdf" << std::endl
1018  << " Median : median of the marg. pdf" << std::endl
1019  << " Marg. mode : most probable value of the marg. pdf" << std::endl
1020  << " V : Variance of the marg. pdf" << std::endl
1021  << " Quantiles : most commonly used quantiles" <<std::endl
1022  << " -----------------------------------------------------" << std::endl
1023  << std::endl;
1024 
1025  // close file
1026  ofi.close();
1027 }
void BCModel::PrintShortFitSummary ( int  chi2flag = 0)

Prints a short summary of the fit results on the screen.

Definition at line 1030 of file BCModel.cxx.

1031 {
1032  BCLog::OutSummary("---------------------------------------------------");
1033  BCLog::OutSummary(Form("Fit summary for model \'%s\':", GetName().data()));
1034  BCLog::OutSummary(Form(" Number of parameters: Npar = %i", GetNParameters()));
1035  if (GetNDataPoints()) {
1036  BCLog::OutSummary(Form(" Number of data points: Ndata = %i", GetNDataPoints()));
1037  BCLog::OutSummary(" Number of degrees of freedom:");
1038  BCLog::OutSummary(Form(" NDoF = Ndata - Npar = %i", GetNDataPoints() - GetNParameters()));
1039  }
1040  if (!GetBestFitParameters().empty())
1041  BCLog::OutSummary(" Best fit parameters (global):");
1042  for (unsigned int i = 0; i < GetNParameters(); ++i)
1043  BCLog::OutSummary(Form(" %s = %.3g", GetParameter(i)->GetName().data(), GetBestFitParameter(i)));
1044 
1045  if (GetPValue() >= 0) {
1046  BCLog::OutSummary(" Goodness-of-fit test:");
1047  BCLog::OutSummary(Form(" p-value = %.3g", GetPValue()));
1048  if (chi2flag) {
1049  BCLog::OutSummary(Form(" p-value corrected for NDoF = %.3g", GetPValueNDoF()));
1050  BCLog::OutSummary(Form(" chi2 / NDoF = %.3g", GetChi2NDoF()));
1051  }
1052  }
1053  BCLog::OutSummary("---------------------------------------------------");
1054 }
void BCModel::PrintSummary ( )

Prints a summary on the screen.

Definition at line 772 of file BCModel.cxx.

773 {
774  // model summary
775  BCLog::OutSummary(Form("Model : %s", fName.data()));
776  BCLog::OutSummary(Form("Number of parameters : %u", GetNParameters()));
777  BCLog::OutSummary("Parameters:");
778 
779  // parameter summary
780  for (unsigned i = 0; i < GetNParameters(); i++)
782 
783  // best fit parameters
784  if ( !GetBestFitParameters().empty()) {
785  BCLog::OutSummary(Form("Log of the maximum posterior: %f", GetLogMaximum()));
786  BCLog::OutSummary("Best fit parameters:");
787 
788  for (unsigned i = 0; i < GetNParameters(); i++) {
789  if ( fParameters[i]->Fixed() )
790  BCLog::OutSummary(Form(" %s = %f (fixed)", fParameters[i]->GetName().data(), GetBestFitParameter(i)));
791  else
792  BCLog::OutSummary(Form(" %s = %f (global)", fParameters[i]->GetName().data(), GetBestFitParameter(i)));
793 
794  if ( fMarginalModes.size() == GetNParameters())
795  BCLog::OutSummary(Form(" %s = %f (marginalized)", fParameters[i]->GetName().data(), GetBestFitParametersMarginalized()[i]));
796 
797  }
798  }
799 
800  // model testing
801  if (fPValue >= 0) {
802  double likelihood = Likelihood(GetBestFitParameters());
803  BCLog::OutSummary(" Model testing:");
804  BCLog::OutSummary(Form(" p(data|lambda*) = %f", likelihood));
805  BCLog::OutSummary(Form(" p-value = %f", fPValue));
806  }
807 
808  // normalization
809  if (GetIntegral() > 0) {
810  BCLog::OutSummary(" Evidence:");
811  BCLog::OutSummary(Form(" - evidence : %f", GetIntegral()));
812  }
813 }
double BCModel::Probability ( const std::vector< double > &  parameter)

Returns the a posteriori probability given a set of parameter values

Parameters
parametersA set of parameter values
Returns
The a posteriori probability

Definition at line 249 of file BCModel.cxx.

250 {
251  return exp(LogProbability(parameter));
252 }
double BCModel::ProbabilityNN ( const std::vector< double > &  params)

Returns the likelihood times prior probability given a set of parameter values

Parameters
paramsA set of parameter values
Returns
The likelihood times prior probability

Definition at line 243 of file BCModel.cxx.

244 {
245  return exp(LogProbabilityNN(params) );
246 }
double BCModel::SamplingFunction ( const std::vector< double > &  parameters)
virtual

Sampling function used for importance sampling. Method needs to be overloaded by the user.

Parameters
parametersA set of parameter values
Returns
The probability density at the parameter values

Definition at line 342 of file BCModel.cxx.

343 {
344  double probability = 1;
345  for (unsigned i = 0 ; i < GetNParameters() ; ++i)
346  probability *= 1. / fParameters[i]->GetRangeWidth();
347  return probability;
348 }
void BCModel::SetDataBoundaries ( unsigned int  index,
double  lowerboundary,
double  upperboundary,
bool  fixed = false 
)

Definition at line 194 of file BCModel.cxx.

195 {
196  // check if data set exists
197  if (!fDataSet) {
198  BCLog::OutError("BCModel::SetDataBoundaries : Need to define data set first.");
199  return;
200  }
201 
202  // check if index is within range
203  if (index > fDataSet->GetDataPoint(0)->GetNValues()) {
204  BCLog::OutError("BCModel::SetDataBoundaries : Index out of range.");
205  return;
206  }
207 
208  // check if boundary data points exist
211 
214 
215  if (fDataFixedValues.size() == 0)
216  fDataFixedValues.assign(fDataSet->GetDataPoint(0)->GetNValues(), false);
217 
218  // set boundaries
219  fDataPointLowerBoundaries->SetValue(index, lowerboundary);
220  fDataPointUpperBoundaries->SetValue(index, upperboundary);
221  fDataFixedValues[index] = fixed;
222 }
void BCModel::SetDataPointLowerBoundaries ( BCDataPoint datasetlowerboundaries)
inline

Sets the data point containing the lower boundaries of possible data values

Definition at line 193 of file BCModel.h.

194  { fDataPointLowerBoundaries = datasetlowerboundaries; }
void BCModel::SetDataPointLowerBoundary ( int  index,
double  lowerboundary 
)

Sets the lower boundary of possible data values for a particular variable

Definition at line 546 of file BCModel.cxx.

547 {
548  fDataPointLowerBoundaries -> SetValue(index, lowerboundary);
549 }
void BCModel::SetDataPointUpperBoundaries ( BCDataPoint datasetupperboundaries)
inline

Sets the data point containing the upper boundaries of possible data values

Definition at line 199 of file BCModel.h.

200  { fDataPointUpperBoundaries = datasetupperboundaries; }
void BCModel::SetDataPointUpperBoundary ( int  index,
double  upperboundary 
)

Sets the upper boundary of possible data values for a particular variable

Definition at line 552 of file BCModel.cxx.

553 {
554  fDataPointUpperBoundaries -> SetValue(index, upperboundary);
555 }
void BCModel::SetDataSet ( BCDataSet dataset)
inline

Sets the data set.

Parameters
datasetA data set

Definition at line 178 of file BCModel.h.

179  { fDataSet = dataset; }
void BCModel::SetGoFNChains ( int  n)
inline

Set number of chains in the MCMC of the p-value evaluation using MCMC

Definition at line 466 of file BCModel.h.

467  { fGoFNChains=n; }
void BCModel::SetGoFNIterationsMax ( int  n)
inline

Set maximum number of iterations in the MCMC pre-run of the p-value evaluation using MCMC

Definition at line 454 of file BCModel.h.

455  { fGoFNIterationsMax=n; }
void BCModel::SetGoFNIterationsRun ( int  n)
inline

Set number of iterations in the MCMC normal run of the p-value evaluation using MCMC

Definition at line 460 of file BCModel.h.

461  { fGoFNIterationsRun=n; }
void BCModel::SetModelAPosterioriProbability ( double  probability)
inline

Sets the a posteriori probability for a model.

Parameters
modelThe model
probabilityThe a posteriori probability

Definition at line 159 of file BCModel.h.

160  { fModelAPosteriori = probability; }
void BCModel::SetModelAPrioriProbability ( double  probability)
inline

Sets the a priori probability for a model.

Parameters
modelThe model
probabilityThe a priori probability

Definition at line 152 of file BCModel.h.

153  { fModelAPriori = probability; }
void BCModel::SetName ( const char *  name)
inline

Sets the name of the model.

Parameters
nameName of the model

Definition at line 145 of file BCModel.h.

146  { fName = name; }
int BCModel::SetPrior ( int  index,
TF1 *  f 
)

Set prior for a parameter.

Parameters
indexThe parameter index
fA pointer to a function describing the prior
Returns
An error code.

Definition at line 558 of file BCModel.cxx.

559 {
560  // check index range
561  if (index < 0 && index >= int(GetNParameters())) {
562  BCLog::OutError("BCModel::SetPrior : Index out of range.");
563  return 0;
564  }
565 
566  if (fPriorContainer[index])
567  delete fPriorContainer[index];
568 
569  // copy function
570  fPriorContainer[index] = new TF1(*f);
571 
572  fPriorContainerConstant[index] = false;
573 
574  // no error
575  return 1;
576 }
int BCModel::SetPrior ( const char *  name,
TF1 *  f 
)

Set prior for a parameter.

Parameters
nameThe parameter name
fA pointer to a function describing the prior
Returns
An error code.

Definition at line 579 of file BCModel.cxx.

580 {
581  // find index
582  int index = -1;
583  for (unsigned int i = 0; i < GetNParameters(); i++)
584  if (name == GetParameter(i)->GetName())
585  index = i;
586 
587  // set prior
588  return SetPrior(index, f);
589 }
int BCModel::SetPrior ( int  index,
TH1 *  h,
bool  flag = false 
)

Set prior for a parameter.

Parameters
indexparameter index
hpointer to a histogram describing the prior
flagwhether or not to use linear interpolation
Returns
An error code.

Definition at line 682 of file BCModel.cxx.

683 {
684  // check index range
685  if (index < 0 && index >= int(GetNParameters())) {
686  BCLog::OutError("BCModel::SetPrior : Index out of range.");
687  return 0;
688  }
689 
690  // if the histogram exists
691  if(h) {
692 
693  // check if histogram is 1d
694  if (h->GetDimension() != 1) {
695  BCLog::OutError(Form("BCModel::SetPrior : Histogram given for parameter %d is not 1D.",index));
696  return 0;
697  }
698 
699  // normalize the histogram
700  h->Scale(1./h->Integral("width"));
701 
702  if(fPriorContainer[index])
703  delete fPriorContainer[index];
704 
705  // set function
706  fPriorContainer[index] = new TH1(*h);
707 
708  if (interpolate)
709  fPriorContainerInterpolate[index] = true;
710 
711  fPriorContainerConstant[index] = false;
712  }
713 
714  // no error
715  return 1;
716 }
int BCModel::SetPrior ( const char *  name,
TH1 *  h,
bool  flag = false 
)

Set prior for a parameter.

Parameters
nameparameter name
hpointer to a histogram describing the prior
flagwhether or not to use linear interpolation
Returns
An error code.

Definition at line 719 of file BCModel.cxx.

720 {
721  // find index
722  int index = -1;
723  for (unsigned int i = 0; i < GetNParameters(); i++)
724  if (name == GetParameter(i)->GetName())
725  index = i;
726 
727  // set prior
728  return SetPrior(index, h, interpolate);
729 }
int BCModel::SetPriorConstant ( int  index)

Set constant prior for this parameter

Parameters
indexthe index of the parameter
Returns
An error code

Definition at line 732 of file BCModel.cxx.

733 {
734  // check index range
735  if (index < 0 && index >= int(GetNParameters())) {
736  BCLog::OutError("BCModel::SetPriorConstant : Index out of range.");
737  return 0;
738  }
739 
740  if(fPriorContainer[index]) {
741  delete fPriorContainer[index];
742  fPriorContainer[index] = 0;
743  }
744 
745  // set prior to a constant
746  fPriorContainerConstant[index] = true;
747 
748  // no error
749  return 1;
750 }
int BCModel::SetPriorConstant ( const char *  name)
inline

Set constant prior for this parameter

Parameters
namethe name of the parameter
Returns
An error code

Definition at line 316 of file BCModel.h.

317  { return SetPriorConstant(fParameters.Index(name)); }
int BCModel::SetPriorConstantAll ( )

Enable caching the constant value of the prior, so LogAPrioriProbability is called only once. Note that the prior for ALL parameters is assumed to be constant. The value is computed from the parameter ranges, so make sure these are defined before this method is called.

Returns
An error code

Definition at line 753 of file BCModel.cxx.

754 {
755  if ( !fParameters.Size())
756  BCLog::OutWarning("BCModel::SetPriorConstantAll : No parameters defined.");
757 
758  // loop over all 1-d priors
759  for (unsigned i = 0; i < fParameters.Size(); ++i) {
760  if (fPriorContainer[i]) {
761  delete fPriorContainer[i];
762  fPriorContainer[i]=0;
763  }
764  fPriorContainerConstant[i] = true;
765  }
766 
767  // no error
768  return 1;
769 }
int BCModel::SetPriorDelta ( int  index,
double  value 
)

Set delta-function prior for a parameter. Note: this sets the parameter range to the specified value. The old parameter range is lost.

Parameters
indexThe parameter index
valueThe position of the delta function.
Returns
An error code.

Definition at line 592 of file BCModel.cxx.

593 {
594  // set range to value
595  GetParameter(index)->Fix(value);
596 
597  // set prior
598  return 1;
599 }
int BCModel::SetPriorDelta ( const char *  name,
double  value 
)

Set delta-function prior for a parameter. Note: this sets the parameter range to the specified value. The old parameter range is lost.

Parameters
nameThe parameter name
valueThe position of the delta function.
Returns
An error code.

Definition at line 602 of file BCModel.cxx.

603 {
604  fParameters.Get(name)->Fix(value);
605 
606  return 1;
607 }
int BCModel::SetPriorGauss ( int  index,
double  mean,
double  sigma 
)

Set Gaussian prior for a parameter.

Parameters
indexThe parameter index
meanThe mean of the Gaussian
sigmaThe sigma of the Gaussian
Returns
An error code.

Definition at line 610 of file BCModel.cxx.

611 {
612  // check index range
613  if (index < 0 || index >= int(GetNParameters())) {
614  BCLog::OutError("BCModel::SetPriorGauss : Index out of range.");
615  return 0;
616  }
617 
618  // create new function
619  TF1 * f = new TF1(Form("prior_%s", GetParameter(index)->GetName().c_str()),
620  "1./sqrt(2.*TMath::Pi())/[1] * exp(- (x-[0])*(x-[0])/2./[1]/[1])",
621  GetParameter(index)->GetLowerLimit(),
622  GetParameter(index)->GetUpperLimit());
623  f->SetParameter(0, mean);
624  f->SetParameter(1, sigma);
625 
626  // set prior
627  return SetPrior(index, f);
628 }
int BCModel::SetPriorGauss ( const char *  name,
double  mean,
double  sigma 
)

Set Gaussian prior for a parameter.

Parameters
nameThe parameter name
meanThe mean of the Gaussian
sigmaThe sigma of the Gaussian
Returns
An error code.

Definition at line 631 of file BCModel.cxx.

632 {
633  // find index
634  int index = -1;
635  for (unsigned int i = 0; i < GetNParameters(); i++)
636  if (name == GetParameter(i)->GetName())
637  index = i;
638 
639  // set prior
640  return SetPriorGauss(index, mean, sigma);
641 }
int BCModel::SetPriorGauss ( int  index,
double  mean,
double  sigmadown,
double  sigmaup 
)

Set Gaussian prior for a parameter with two different widths.

Parameters
indexThe parameter index
meanThe mean of the Gaussian
sigmadownThe sigma (down) of the Gaussian
sigmaupThe sigma (up)of the Gaussian
Returns
An error code.

Definition at line 644 of file BCModel.cxx.

645 {
646  // check index range
647  if (index < 0 || index >= int(GetNParameters())) {
648  BCLog::OutError("BCModel::SetPriorGauss : Index out of range.");
649  return 0;
650  }
651 
652  // create new function
653  TF1 * f = new TF1(Form("prior_%s", GetParameter(index)->GetName().c_str()),
655  GetParameter(index)->GetLowerLimit(),
656  GetParameter(index)->GetUpperLimit(),
657  3);
658  f->SetParameter(0, mean);
659  f->SetParameter(1, sigmadown);
660  f->SetParameter(2, sigmaup);
661 
662  // set prior
663  return SetPrior(index, f);
664 
665  return 0;
666 }
int BCModel::SetPriorGauss ( const char *  name,
double  mean,
double  sigmadown,
double  sigmaup 
)

Set Gaussian prior for a parameter with two different widths.

Parameters
nameThe parameter name
meanThe mean of the Gaussian
sigmadownThe sigma (down) of the Gaussian
sigmaupThe sigma (up)of the Gaussian
Returns
An error code.

Definition at line 669 of file BCModel.cxx.

670 {
671  // find index
672  int index = -1;
673  for (unsigned int i = 0; i < GetNParameters(); i++)
674  if (name == GetParameter(i)->GetName())
675  index = i;
676 
677  // set prior
678  return SetPriorGauss(index, mean, sigmadown, sigmaup);
679 }
void BCModel::SetSingleDataPoint ( BCDataPoint datapoint)

Sets a single data point as data set.

Parameters
datapointA data point

Definition at line 172 of file BCModel.cxx.

173 {
174  // create new data set consisting of a single data point
175  BCDataSet * dataset = new BCDataSet();
176 
177  // add the data point
178  dataset->AddDataPoint(datapoint);
179 
180  // set this new data set
181  SetDataSet(dataset);
182 }
void BCModel::SetSingleDataPoint ( BCDataSet dataset,
unsigned int  index 
)

Definition at line 185 of file BCModel.cxx.

186 {
187  if (index > dataset->GetNDataPoints())
188  return;
189 
190  SetSingleDataPoint(dataset->GetDataPoint(index));
191 }
BCDataPoint * BCModel::VectorToDataPoint ( const std::vector< double > &  data)
private

Converts a vector of doubles into a BCDataPoint

Definition at line 1086 of file BCModel.cxx.

1087 {
1088  BCDataPoint * datapoint = new BCDataPoint(data.size());
1089  datapoint->SetValues(data);
1090  return datapoint;
1091 }

Member Data Documentation

double BCModel::fChi2NDoF
protected

Definition at line 538 of file BCModel.h.

std::vector<bool> BCModel::fDataFixedValues
protected

Definition at line 532 of file BCModel.h.

BCDataPoint* BCModel::fDataPointLowerBoundaries
protected

data point containing the lower boundaries of possible data values

Definition at line 526 of file BCModel.h.

BCDataPoint* BCModel::fDataPointUpperBoundaries
protected

data point containing the upper boundaries of possible data values

Definition at line 530 of file BCModel.h.

BCDataSet* BCModel::fDataSet
protected

A data set

Definition at line 522 of file BCModel.h.

int BCModel::fGoFNChains
protected

Number of chains in the MCMC of the p-value evaluation using MCMC

Definition at line 558 of file BCModel.h.

int BCModel::fGoFNIterationsMax
protected

Maximum number of iterations in the MCMC pre-run of the p-value evaluation using MCMC

Definition at line 548 of file BCModel.h.

int BCModel::fGoFNIterationsRun
protected

Number of iterations in the MCMC normal run of the p-value evaluation using MCMC

Definition at line 553 of file BCModel.h.

bool BCModel::flag_discrete
protected

true for a discrete probability, false for continuous pdf

Definition at line 543 of file BCModel.h.

double BCModel::fModelAPosteriori
protected

The model a posteriori probability.

Definition at line 518 of file BCModel.h.

double BCModel::fModelAPriori
protected

The model prior probability.

Definition at line 514 of file BCModel.h.

std::string BCModel::fName
protected

Name of the model.

Definition at line 510 of file BCModel.h.

bool BCModel::fPriorConstantAll
protected

Flag to indicate that all parameters have constant prior.

Definition at line 566 of file BCModel.h.

std::vector<TNamed*> BCModel::fPriorContainer
protected

A vector of prior functions/histograms/graphs.

Definition at line 562 of file BCModel.h.

std::vector<bool> BCModel::fPriorContainerConstant
protected

List the parameters whose prior is constant

Definition at line 570 of file BCModel.h.

std::vector<bool> BCModel::fPriorContainerInterpolate
protected

List the parameters for which the histogram prior should be interpolated

Definition at line 574 of file BCModel.h.

double BCModel::fPValue
protected

The p-value

Definition at line 536 of file BCModel.h.

double BCModel::fPValueNDoF
protected

Definition at line 539 of file BCModel.h.


The documentation for this class was generated from the following files: