BCModel Class Reference

#include <BCModel.h>

Inheritance diagram for BCModel:

Inheritance graph
[legend]
Collaboration diagram for BCModel:

Collaboration graph
[legend]

List of all members.


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 parameters, their prior distributions and the conditional probabilities given those parameters. The methods which implement the prior and conditional probabilities have to be overloaded by the user in the user defined model class which will inherit from this class.

Definition at line 50 of file BCModel.h.


Public Member Functions

Member functions (miscellaneous methods)


int AddParameter (BCParameter *parameter)
int AddParameter (const char *name, double lowerlimit, double upperlimit)
double APrioriProbability (std::vector< double > parameters)
BCH1DCalculatePValue (std::vector< double > par, bool flag_histogram=false)
int CheckParameters (std::vector< double > parameters)
double ConditionalProbabilityEntry (BCDataPoint *datapoint, std::vector< double > parameters)
virtual void CorrelateDataPointValues (std::vector< double > &x)
virtual void DefineParameters ()
double Eval (std::vector< double > parameters)
double EvalSampling (std::vector< double > parameters)
void FindMode ()
void FixDataAxis (unsigned int index, bool fixed)
BCH2DGetMarginalized (const char *name1, const char *name2)
BCH2DGetMarginalized (BCParameter *parameter1, BCParameter *parameter2)
BCH1DGetMarginalized (const char *name)
BCH1DGetMarginalized (BCParameter *parameter)
double GetPValue ()
double GetPvalueFromChi2 (std::vector< double > par, int sigma_index)
double HessianMatrixElement (BCParameter *parameter1, BCParameter *parameter2, std::vector< double > point)
double Likelihood (std::vector< double > parameter)
virtual double LogAPrioriProbability (std::vector< double > parameters)
virtual double LogConditionalProbabilityEntry (BCDataPoint *datapoint, std::vector< double > parameters)
double LogEval (std::vector< double > parameters)
virtual double LogLikelihood (std::vector< double > parameter)
double LogProbability (std::vector< double > parameter)
double LogProbabilityNN (std::vector< double > parameter)
int MarginalizeAll ()
double Normalize ()
int PrintAllMarginalized (const char *file, unsigned int hdiv=1, unsigned int ndiv=1)
int PrintAllMarginalized1D (const char *filebase)
int PrintAllMarginalized2D (const char *filebase)
void PrintHessianMatrix (std::vector< double > parameters)
void PrintResults (const char *file)
void PrintShortFitSummary ()
void PrintSummary ()
double Probability (std::vector< double > parameter)
double ProbabilityNN (std::vector< double > parameter)
int ReadErrorBandFromFile (const char *file)
int ReadMarginalizedFromFile (const char *file)
int ReadMode (const char *file)
virtual double SamplingFunction (std::vector< double > parameters)
void SetGoFNChains (int n)
void SetGoFNIterationsMax (int n)
void SetGoFNIterationsRun (int n)
void WriteMode (const char *file)
Constructors and destructors


 BCModel (const char *name)
 BCModel ()
virtual ~BCModel ()
Member functions (get)


double GetBestFitParameter (unsigned int index)
double GetBestFitParameterMarginalized (unsigned int index)
std::vector< double > GetBestFitParameters ()
std::vector< double > GetBestFitParametersMarginalized ()
BCDataPointGetDataPoint (unsigned int index)
BCDataPointGetDataPointLowerBoundaries ()
double GetDataPointLowerBoundary (unsigned int index)
BCDataPointGetDataPointUpperBoundaries ()
double GetDataPointUpperBoundary (unsigned int index)
BCDataSetGetDataSet ()
std::vector< double > GetErrorBand (double level)
TGraph * GetErrorBandGraph (double level1, double level2)
TH2D * GetErrorBandXY ()
TH2D * GetErrorBandXY_yellow (double level=.68, int nsmooth=0)
TGraph * GetFitFunctionGraph (std::vector< double > parameters, double xmin, double xmax, int n=1000)
TGraph * GetFitFunctionGraph ()
TGraph * GetFitFunctionGraph (std::vector< double > parameters)
bool GetFixedDataAxis (unsigned int index)
bool GetFlagBoundaries ()
int GetIndex ()
double GetModelAPosterioriProbability ()
double GetModelAPrioriProbability ()
std::string GetName ()
int GetNDataPoints ()
unsigned int GetNDataPointsMaximum ()
unsigned int GetNDataPointsMinimum ()
double GetNormalization ()
unsigned int GetNParameters ()
BCParameterGetParameter (const char *name)
BCParameterGetParameter (int index)
Member functions (set)


void SetDataBoundaries (unsigned int index, double lowerboundary, double upperboundary, bool fixed=false)
void SetDataSet (BCDataSet *dataset)
void SetErrorBandContinuous (bool flag)
void SetIndex (int index)
void SetModelAPosterioriProbability (double probability)
void SetModelAPrioriProbability (double probability)
void SetName (const char *name)
void SetNDataPointsMaximum (unsigned int maximum)
void SetNDataPointsMinimum (unsigned int minimum)
void SetNormalization (double norm)
void SetSingleDataPoint (BCDataSet *dataset, unsigned int index)
void SetSingleDataPoint (BCDataPoint *datapoint)

Protected Attributes

BCDataSetfDataSet
int fGoFNChains
int fGoFNIterationsMax
int fGoFNIterationsRun
int fIndex
bool flag_ConditionalProbabilityEntry
double fModelAPosteriori
double fModelAPriori
std::string fName
unsigned int fNDataPointsMaximum
unsigned int fNDataPointsMinimum
BCParameterSetfParameterSet
double fPValue

Private Member Functions

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

Private Attributes

double fNormalization

Constructor & Destructor Documentation

BCModel::BCModel (  ) 

The default constructor.

Definition at line 61 of file BCModel.cxx.

00061                  : BCIntegrate()
00062 {
00063    fNormalization = -1.0;
00064    fDataSet = 0;
00065    fParameterSet = new BCParameterSet();
00066 
00067    fIndex = -1;
00068    fPValue = -1;
00069 
00070    fName = "model";
00071    fDataPointUpperBoundaries = 0;
00072    fDataPointLowerBoundaries = 0;
00073 
00074    flag_ConditionalProbabilityEntry = true;
00075 
00076    fGoFNChains = 5;
00077    fGoFNIterationsMax = 100000;
00078    fGoFNIterationsRun = 2000;
00079 }

BCModel::BCModel ( const char *  name  ) 

A constructor.

Parameters:
name The name of the model

Definition at line 37 of file BCModel.cxx.

00037                                   : BCIntegrate()
00038 {
00039    fNormalization = -1.0;
00040    fDataSet = 0;
00041    fParameterSet = new BCParameterSet;
00042 
00043    fIndex = -1;
00044    fPValue = -1;
00045 
00046    fName = (char *) name;
00047    flag_ConditionalProbabilityEntry = true;
00048 
00049    fDataPointUpperBoundaries = 0;
00050    fDataPointLowerBoundaries = 0;
00051 
00052    fErrorBandXY = 0;
00053 
00054    fGoFNChains = 5;
00055    fGoFNIterationsMax = 100000;
00056    fGoFNIterationsRun = 2000;
00057 }

BCModel::~BCModel (  )  [virtual]

The default destructor.

Definition at line 83 of file BCModel.cxx.

00084 {
00085    delete fParameterSet;
00086 
00087    if (fDataPointLowerBoundaries)
00088       delete fDataPointLowerBoundaries;
00089 
00090    if (fDataPointUpperBoundaries)
00091       delete fDataPointUpperBoundaries;
00092 }


Member Function Documentation

int BCModel::AddParameter ( BCParameter parameter  ) 

Adds a parameter to the model.

Parameters:
parameter A model parameter
See also:
AddParameter(const char * name, double lowerlimit, double upperlimit);

Definition at line 420 of file BCModel.cxx.

00421 {
00422    // check if parameter set exists
00423    if (!fParameterSet)
00424    {
00425       BCLog::Out(BCLog::error, BCLog::error,
00426             "BCModel::AddParameter : Parameter set does not exist");
00427       return ERROR_PARAMETERSETDOESNOTEXIST;
00428    }
00429 
00430    // check if parameter with same name exists
00431    int flag_exists = 0;
00432    for (unsigned int i = 0; i < this -> GetNParameters(); i++)
00433       if (this -> CompareStrings(parameter -> GetName().data(), this -> GetParameter(i) -> GetName().data()) == 0)
00434          flag_exists = -1;
00435 
00436    if (flag_exists < 0)
00437    {
00438       BCLog::Out(BCLog::error, BCLog::error,
00439             Form("BCModel::AddParameter : Parameter with name %s exists already. ", parameter -> GetName().data()));
00440       return ERROR_PARAMETEREXISTSALREADY;
00441    }
00442 
00443    // define index of new parameter
00444    unsigned int index = fParameterSet -> size();
00445    parameter -> SetIndex(index);
00446 
00447    // add parameter to parameter container
00448    fParameterSet -> push_back(parameter);
00449 
00450    // add parameters to integation methods
00451    this -> SetParameters(fParameterSet);
00452 
00453    // add parameter to MCMC
00454    // this -> MCMCAddParameter(parameter -> GetLowerLimit(), parameter -> GetUpperLimit());
00455 
00456    // re-initialize
00457 // this -> MCMCInitialize();
00458 
00459    return 0;
00460 }

int BCModel::AddParameter ( const char *  name,
double  lowerlimit,
double  upperlimit 
)

Adds a parameter to the parameter set

Parameters:
name The name of the parameter
lowerlimit The lower limit of the parameter values
upperlimit The upper limit of the parameter values
See also:
AddParameter(BCParameter* parameter);

Definition at line 406 of file BCModel.cxx.

00407 {
00408    // create new parameter
00409    BCParameter * parameter = new BCParameter(name, lowerlimit, upperlimit);
00410 
00411    int flag_ok = this -> AddParameter(parameter);
00412    if (flag_ok)
00413       delete parameter;
00414 
00415    return flag_ok;
00416 }

double BCModel::APrioriProbability ( std::vector< double >  parameters  )  [inline]

Returns the prior probability.

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

Definition at line 318 of file BCModel.h.

00319          { return exp( this->LogAPrioriProbability(parameters) ); };

BCH1D * BCModel::CalculatePValue ( std::vector< double >  par,
bool  flag_histogram = false 
)

Definition at line 1166 of file BCModel.cxx.

01167 {
01168    BCH1D * hist = 0;
01169 
01170    // print log
01171    BCLog::Out(BCLog::summary, BCLog::summary, "Do goodness-of-fit-test");
01172 
01173    // create model test
01174    BCGoFTest * goftest = new BCGoFTest("modeltest");
01175 
01176    // set this model as the model to be tested
01177    goftest -> SetTestModel(this);
01178 
01179    // set the point in parameter space which is tested an initialize
01180    // the model testing
01181    if (!goftest -> SetTestPoint(par))
01182       return 0;
01183 
01184    // set parameters of the MCMC for the GoFTest
01185    goftest -> MCMCSetNChains(fGoFNChains);
01186    goftest -> MCMCSetNIterationsMax(fGoFNIterationsMax);
01187    goftest -> MCMCSetNIterationsRun(fGoFNIterationsRun);
01188 
01189    // get p-value
01190    fPValue = goftest -> GetCalculatedPValue(flag_histogram);
01191 
01192    // get histogram
01193    if (flag_histogram)
01194    {
01195       hist = new BCH1D();
01196       hist -> SetHistogram(goftest -> GetHistogramLogProb());
01197    }
01198 
01199    // delete model test
01200    delete goftest;
01201 
01202    // return histogram
01203    return hist;
01204 }

int BCModel::CheckParameters ( std::vector< double >  parameters  ) 

Checks if a set of parameters values is within the given range.

Parameters:
parameters A set of parameter values
Returns:
Error code (0: OK, -1 length of parameters not correct, -2 values not within range)

Definition at line 556 of file BCModel.cxx.

00557 {
00558    // check if vectors are of equal size
00559    if (!parameters.size() == fParameterSet -> size())
00560       return  ERROR_INVALIDNUMBEROFPARAMETERS;
00561 
00562    // check if parameters are within limits
00563    for (unsigned int i = 0; i < fParameterSet -> size(); i++)
00564    {
00565       BCParameter * modelparameter = fParameterSet -> at(i);
00566 
00567       if (modelparameter -> GetLowerLimit() > parameters.at(i) ||
00568             modelparameter -> GetUpperLimit() < parameters.at(i))
00569       {
00570          BCLog::Out(BCLog::error, BCLog::error,
00571                 Form("BCModel::CheckParameters : Parameter %s not within limits.", fParameterSet -> at(i) -> GetName().data()));
00572          return ERROR_PARAMETERNOTWITHINRANGE;
00573       }
00574    }
00575 
00576    return 0;
00577 }

int BCModel::CompareStrings ( const char *  string1,
const char *  string2 
) [private]

Compares to strings

Definition at line 1571 of file BCModel.cxx.

01572 {
01573    int flag_same = 0;
01574 
01575    if (strlen(string1) != strlen(string2))
01576       return -1;
01577 
01578    for (int i = 0; i < int(strlen(string1)); i++)
01579       if (string1[i] != string2[i])
01580          flag_same = -1;
01581 
01582    return flag_same;
01583 }

double BCModel::ConditionalProbabilityEntry ( BCDataPoint datapoint,
std::vector< double >  parameters 
) [inline]

Returns a conditional probability. Method needs to be overloaded by the user.

Parameters:
datapoint A data point
parameters A set of parameter values
Returns:
The conditional probability p(datapoint|parameters)
See also:
GetConditionalEntry(BCDataPoint* datapoint, std::vector <double> parameters)

Definition at line 378 of file BCModel.h.

00379          { return exp( this->LogConditionalProbabilityEntry(datapoint, parameters) ); };

void BCModel::CorrelateDataPointValues ( std::vector< double > &  x  )  [virtual]

Constrains a data point

Parameters:
x A vector of double

Definition at line 1208 of file BCModel.cxx.

01209 {
01210    // ...
01211 }

virtual void BCModel::DefineParameters (  )  [inline, virtual]

Defines the parameters of the model Method needs to be overloaded by the user.

Definition at line 310 of file BCModel.h.

00311          { ;};

double BCModel::Eval ( std::vector< double >  parameters  )  [inline, virtual]

Overloaded function to evaluate integral.

Reimplemented from BCIntegrate.

Definition at line 400 of file BCModel.h.

00401          { return exp( this->LogEval(parameters) ); };

double BCModel::EvalSampling ( std::vector< double >  parameters  )  [virtual]

Overloaded function to evaluate integral.

Reimplemented from BCIntegrate.

Definition at line 515 of file BCModel.cxx.

00516 {
00517    return this -> SamplingFunction(parameters);
00518 }

void BCModel::FindMode (  ) 

Does the mode finding

Definition at line 581 of file BCModel.cxx.

00582 {
00583 // this implementation is CLEARLY not good we have top work on this.
00584 
00585    BCLog::Out(BCLog::summary, BCLog::summary,
00586       Form("Model \'%s\': Finding mode", this -> GetName().data()));
00587 
00588    // synchronize parameters in BCIntegrate
00589    this -> SetParameters(fParameterSet);
00590 
00591    switch(this -> GetOptimizationMethod())
00592    {
00593       case BCIntegrate::kOptSimulatedAnnealing:
00594 
00595          BCLog::Out(BCLog::warning, BCLog::warning, "BCModel::FindMode. Simulated annaeling not yet implemented.");
00596          return;
00597       case BCIntegrate::kOptMinuit:
00598          this -> FindModeMinuit();
00599          return;
00600       case BCIntegrate::kOptMetropolis:
00601          this -> MarginalizeAll();
00602          return;
00603       }
00604 
00605    BCLog::Out(BCLog::warning, BCLog::warning, Form("BCModel::FindMode. Invalid mode finding method: %d. Return.",
00606          this->GetOptimizationMethod()));
00607 
00608    return;
00609 }

void BCModel::FixDataAxis ( unsigned int  index,
bool  fixed 
)

Definition at line 1261 of file BCModel.cxx.

01262 {
01263    // check if index is within range
01264    if (index < 0 || index > fDataSet -> GetDataPoint(0) -> GetNValues())
01265    {
01266       BCLog::Out(BCLog::warning, BCLog::warning, "BCModel::FixDataAxis. Index out of range.");
01267       return;
01268    }
01269 
01270    if (fDataFixedValues.size() == 0)
01271       fDataFixedValues.assign(fDataSet -> GetDataPoint(0) -> GetNValues(), false);
01272 
01273    fDataFixedValues[index] = fixed;
01274 }

double BCModel::GetBestFitParameter ( unsigned int  index  )  [inline]

Returns the value of a particular parameter (defined by index) at the global mode of the posterior pdf.

Parameters:
index The index of the parameter.
Returns:
The best fit parameter.

Definition at line 172 of file BCModel.h.

00173          { return fBestFitParameters[index]; };

double BCModel::GetBestFitParameterMarginalized ( unsigned int  index  )  [inline]

Returns the value of a particular parameter (defined by index) at the modes of the marginalized posterior pdfs.

Parameters:
index The index of the parameter.
Returns:
The best fit parameter

Definition at line 187 of file BCModel.h.

00188          { return fBestFitParametersMarginalized[index]; };

std::vector<double> BCModel::GetBestFitParameters (  )  [inline]

Returns the set of values of the parameters at the global mode of the posterior pdf.

Returns:
The best fit parameters

Definition at line 179 of file BCModel.h.

00180          { return fBestFitParameters; };

std::vector<double> BCModel::GetBestFitParametersMarginalized (  )  [inline]

Returns the set of values of the parameters at the modes of the marginalized posterior pdfs.

Returns:
The best fit parameters.

Definition at line 194 of file BCModel.h.

00195          { return fBestFitParametersMarginalized; };

BCDataPoint * BCModel::GetDataPoint ( unsigned int  index  ) 

Parameters:
index The index of the data point.
Returns:
The data point in the current data set at index

Definition at line 112 of file BCModel.cxx.

00113 {
00114    if (fDataSet)
00115       return fDataSet -> GetDataPoint(index);
00116 
00117    BCLog::Out(BCLog::warning, BCLog::warning,"BCModel::GetDataPoint. No data set defined.");
00118    return 0;
00119 }

BCDataPoint* BCModel::GetDataPointLowerBoundaries (  )  [inline]

Returns:
The lower boundaries of possible data values.

Definition at line 108 of file BCModel.h.

00109          { return fDataPointLowerBoundaries; };

double BCModel::GetDataPointLowerBoundary ( unsigned int  index  )  [inline]

Parameters:
index The index of the variable.
Returns:
The lower boundary of possible data values for a particular variable.

Definition at line 119 of file BCModel.h.

00120          { return fDataPointLowerBoundaries -> GetValue(index); };

BCDataPoint* BCModel::GetDataPointUpperBoundaries (  )  [inline]

Returns:
The upper boundaries of possible data values.

Definition at line 113 of file BCModel.h.

00114          { return fDataPointUpperBoundaries; };

double BCModel::GetDataPointUpperBoundary ( unsigned int  index  )  [inline]

Parameters:
index The index of the variable.
Returns:
The upper boundary of possible data values for a particular variable.

Definition at line 125 of file BCModel.h.

00126          { return fDataPointUpperBoundaries -> GetValue(index); };

BCDataSet* BCModel::GetDataSet (  )  [inline]

Returns:
The data set.

Definition at line 103 of file BCModel.h.

00104          { return fDataSet; };

std::vector< double > BCModel::GetErrorBand ( double  level  ) 

Returns a vector of y-values at a certain probability level.

Parameters:
level The level of probability
Returns:
The vector of y-values

Definition at line 162 of file BCModel.cxx.

00163 {
00164    std::vector <double> errorband;
00165 
00166    if (!fErrorBandXY)
00167       return errorband;
00168 
00169    int nx = fErrorBandXY -> GetNbinsX();
00170    errorband.assign(nx, 0.0);
00171 
00172    // loop over x and y bins
00173    for (int ix = 1; ix <= nx; ix++)
00174    {
00175       TH1D * temphist = fErrorBandXY -> ProjectionY("temphist", ix, ix);
00176 
00177       int nprobSum = 1;
00178       double q[1];
00179       double probSum[1];
00180       probSum[0] = level;
00181 
00182       temphist -> GetQuantiles(nprobSum, q, probSum);
00183 
00184       errorband[ix-1] = q[0];
00185    }
00186 
00187    return errorband;
00188 }

TGraph * BCModel::GetErrorBandGraph ( double  level1,
double  level2 
)

Definition at line 192 of file BCModel.cxx.

00193 {
00194    if (!fErrorBandXY)
00195       return 0;
00196 
00197    // define new graph
00198    int nx = fErrorBandXY -> GetNbinsX();
00199 
00200    TGraph * graph = new TGraph(2 * nx);
00201    graph -> SetFillStyle(1001);
00202    graph -> SetFillColor(kYellow);
00203 
00204    // get error bands
00205    std::vector <double> ymin = this -> GetErrorBand(level1);
00206    std::vector <double> ymax = this -> GetErrorBand(level2);
00207 
00208    for (int i = 0; i < nx; i++)
00209    {
00210       graph -> SetPoint(i,      fErrorBandXY -> GetXaxis() -> GetBinCenter(i + 1), ymin.at(i));
00211       graph -> SetPoint(nx + i, fErrorBandXY -> GetXaxis() -> GetBinCenter(nx - i), ymax.at(nx - i - 1));
00212    }
00213 
00214    return graph;
00215 }

TH2D* BCModel::GetErrorBandXY (  )  [inline]

Returns:
The 2-d histogram of the error band.

Definition at line 199 of file BCModel.h.

00200          { return fErrorBandXY; };

TH2D * BCModel::GetErrorBandXY_yellow ( double  level = .68,
int  nsmooth = 0 
)

Definition at line 219 of file BCModel.cxx.

00220 {
00221    if (!fErrorBandXY)
00222       return 0;
00223 
00224    int nx = fErrorBandXY -> GetNbinsX();
00225    int ny = fErrorBandXY -> GetNbinsY();
00226 
00227    // copy existing histogram
00228    TH2D * hist_tempxy = (TH2D*) fErrorBandXY -> Clone(TString::Format("%s_sub_%f.2",fErrorBandXY->GetName(),level));
00229    hist_tempxy -> Reset();
00230    hist_tempxy -> SetFillColor(kYellow);
00231 
00232    // loop over x bins
00233    for (int ix = 1; ix < nx; ix++)
00234    {
00235       BCH1D * hist_temp = new BCH1D();
00236 
00237       TH1D * hproj = fErrorBandXY -> ProjectionY("temphist", ix, ix);
00238       if(nsmooth>0)
00239          hproj->Smooth(nsmooth);
00240 
00241       hist_temp -> SetHistogram(hproj);
00242 
00243       TH1D * hist_temp_yellow = hist_temp -> GetSmallestIntervalHistogram(level);
00244 
00245       for (int iy = 1; iy <= ny; ++iy)
00246          hist_tempxy -> SetBinContent(ix, iy, hist_temp_yellow -> GetBinContent(iy));
00247 
00248       delete hist_temp_yellow;
00249       delete hist_temp;
00250    }
00251 
00252    return hist_tempxy;
00253 }

TGraph * BCModel::GetFitFunctionGraph ( std::vector< double >  parameters,
double  xmin,
double  xmax,
int  n = 1000 
)

Definition at line 284 of file BCModel.cxx.

00285 {
00286    // define new graph
00287    TGraph * graph = new TGraph(n+1);
00288 
00289    double dx = (xmax-xmin)/(double)n;
00290 
00291    // loop over x values
00292    for (int i = 0; i <= n; i++)
00293    {
00294       double x = (double)i*dx+xmin;
00295       std::vector <double> xvec;
00296       xvec.push_back(x);
00297       double y = this -> FitFunction(xvec, parameters);
00298 
00299       xvec.clear();
00300 
00301       graph -> SetPoint(i, x, y);
00302    }
00303 
00304    return graph;
00305 }

TGraph* BCModel::GetFitFunctionGraph (  )  [inline]

Definition at line 214 of file BCModel.h.

00215          { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); };

TGraph * BCModel::GetFitFunctionGraph ( std::vector< double >  parameters  ) 

Definition at line 257 of file BCModel.cxx.

00258 {
00259    if (!fErrorBandXY)
00260       return 0;
00261 
00262    // define new graph
00263    int nx = fErrorBandXY -> GetNbinsX();
00264    TGraph * graph = new TGraph(nx);
00265 
00266    // loop over x values
00267    for (int i = 0; i < nx; i++)
00268    {
00269       double x = fErrorBandXY -> GetXaxis() -> GetBinCenter(i + 1);
00270 
00271       std::vector <double> xvec;
00272       xvec.push_back(x);
00273       double y = this -> FitFunction(xvec, parameters);
00274       xvec.clear();
00275 
00276       graph -> SetPoint(i, x, y);
00277    }
00278 
00279    return graph;
00280 }

bool BCModel::GetFixedDataAxis ( unsigned int  index  ) 

Definition at line 1278 of file BCModel.cxx.

01279 {
01280    // check if index is within range
01281    if (index < 0 || index > fDataSet -> GetDataPoint(0) -> GetNValues())
01282    {
01283       BCLog::Out(BCLog::warning, BCLog::warning, "BCModel::GetFixedDataAxis. Index out of range.");
01284       return false;
01285    }
01286 
01287    return fDataFixedValues.at(index);
01288 }

bool BCModel::GetFlagBoundaries (  ) 

Definition at line 309 of file BCModel.cxx.

00310 {
00311    if (!fDataPointLowerBoundaries)
00312       return false;
00313 
00314    if (!fDataPointUpperBoundaries)
00315       return false;
00316 
00317    if (fDataPointLowerBoundaries -> GetNValues() != fDataSet -> GetDataPoint(0) -> GetNValues())
00318       return false;
00319 
00320    if (fDataPointUpperBoundaries -> GetNValues() != fDataSet -> GetDataPoint(0) -> GetNValues())
00321       return false;
00322 
00323    return true;
00324 }

int BCModel::GetIndex (  )  [inline]

Returns:
The index of the model.

Definition at line 83 of file BCModel.h.

00084          { return fIndex; };

BCH2D* BCModel::GetMarginalized ( const char *  name1,
const char *  name2 
) [inline]

Definition at line 467 of file BCModel.h.

00468          { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); };

BCH2D * BCModel::GetMarginalized ( BCParameter parameter1,
BCParameter parameter2 
)

If MarginalizeAll method was used, the individual marginalized distributions with respect to otwo parameters can be retrieved using this method.

Parameters:
parameter1 First parameter
parameter2 Second parameter
Returns:
2D marginalized probability

Definition at line 1104 of file BCModel.cxx.

01105 {
01106 // if(fMCMCH2Marginalized.size()==0)
01107 // {
01108 //    BCLog::Out(BCLog::warning, BCLog::warning,
01109 //           "BCModel::GetMarginalized. MarginalizeAll() has to be run prior to this.");
01110 //    return 0;
01111 // }
01112 
01113    int index1 = parameter1 -> GetIndex();
01114    int index2 = parameter2 -> GetIndex();
01115 
01116    if (index1 > index2)
01117    {
01118       BCLog::Out(BCLog::warning, BCLog::warning,
01119              "BCModel::GetMarginalized. Index 1 has to be smaller than index 2.");
01120       return 0;
01121    }
01122 
01123    // get histogram
01124    TH2D * hist = this -> MCMCGetH2Marginalized(index1, index2);
01125 
01126    if(hist==0)
01127       return 0;
01128 
01129    BCH2D * hprob = new BCH2D();
01130 
01131    // set axis labels
01132    hist -> SetName(Form("hist_%s_%s_%s", this -> GetName().data(), parameter1 -> GetName().data(), parameter2 -> GetName().data()));
01133    hist -> SetXTitle(Form("%s", parameter1 -> GetName().data()));
01134    hist -> SetYTitle(Form("%s", parameter2 -> GetName().data()));
01135    hist -> SetStats(kFALSE);
01136 
01137    double gmode[] = { fBestFitParameters.at(index1), fBestFitParameters.at(index2) };
01138    hprob->SetGlobalMode(gmode);
01139 
01140    // set histogram
01141    hprob -> SetHistogram(hist);
01142 
01143    return hprob;
01144 }

BCH1D* BCModel::GetMarginalized ( const char *  name  )  [inline]

Definition at line 456 of file BCModel.h.

00457          { return this -> GetMarginalized(this -> GetParameter(name)); };

BCH1D * BCModel::GetMarginalized ( BCParameter parameter  ) 

If MarginalizeAll method was used, the individual marginalized distributions with respect to one parameter can be retrieved using this method.

Parameters:
parameter Model parameter
Returns:
1D marginalized probability

Definition at line 743 of file BCModel.cxx.

00744 {
00745 // if(fMCMCH1Marginalized.size()==0)
00746 // {
00747 //    BCLog::Out(BCLog::warning, BCLog::warning,
00748 //          "BCModel::GetMarginalized. MarginalizeAll() has to be run prior to this.");
00749 //    return 0;
00750 // }
00751 
00752    int index = parameter -> GetIndex();
00753 
00754    // get histogram
00755    TH1D * hist = this -> MCMCGetH1Marginalized(index);
00756    if(!hist)
00757       return 0;
00758 
00759    BCH1D * hprob = new BCH1D();
00760 
00761    // set axis labels
00762    hist -> SetName(Form("hist_%s_%s", this -> GetName().data(), parameter -> GetName().data()));
00763    hist -> SetXTitle(parameter -> GetName().data());
00764    hist -> SetYTitle(Form("p(%s|data)", parameter -> GetName().data()));
00765    hist -> SetStats(kFALSE);
00766 
00767    // set histogram
00768    hprob -> SetHistogram(hist);
00769 
00770    // set best fit parameter
00771    double bestfit = hprob -> GetMode();
00772 
00773    if (fBestFitParametersMarginalized.size() == 0)
00774       for (unsigned int i = 0; i < this -> GetNParameters(); i++)
00775          fBestFitParametersMarginalized.push_back(0.0);
00776 
00777    fBestFitParametersMarginalized[index] = bestfit;
00778 
00779    hprob->SetGlobalMode(fBestFitParameters.at(index));
00780 
00781    return hprob;
00782 }

double BCModel::GetModelAPosterioriProbability (  )  [inline]

Returns:
The a posteriori probability.

Definition at line 93 of file BCModel.h.

00094          { return fModelAPosteriori; };

double BCModel::GetModelAPrioriProbability (  )  [inline]

Returns:
The a priori probability.

Definition at line 88 of file BCModel.h.

00089          { return fModelAPriori; };

std::string BCModel::GetName (  )  [inline]

Returns:
The name of the model.

Definition at line 78 of file BCModel.h.

00079          { return fName; };

int BCModel::GetNDataPoints (  ) 

Returns:
The number of data points in the current data set.

Definition at line 96 of file BCModel.cxx.

00097 {
00098    int npoints = 0;
00099    if (fDataSet)
00100       npoints = fDataSet -> GetNDataPoints();
00101    else
00102    {
00103       BCLog::Out(BCLog::warning, BCLog::warning,"BCModel::GetNDataPoints(). No data set defined.");
00104       return ERROR_NOEVENTS;
00105    }
00106 
00107    return npoints;
00108 }

unsigned int BCModel::GetNDataPointsMaximum (  )  [inline]

Returns:
The maximum number of data points.

Definition at line 149 of file BCModel.h.

00150          { return fNDataPointsMaximum; };

unsigned int BCModel::GetNDataPointsMinimum (  )  [inline]

Returns:
The minimum number of data points.

Definition at line 144 of file BCModel.h.

00145          { return fNDataPointsMinimum; };

double BCModel::GetNormalization (  )  [inline]

Returns:
The normalization factor of the probability

Definition at line 98 of file BCModel.h.

00099          { return fNormalization; };

unsigned int BCModel::GetNParameters (  )  [inline]

Returns:
The number of parameters of the model.

Definition at line 154 of file BCModel.h.

00155          { return fParameterSet ? fParameterSet -> size() : 0; };

BCParameter * BCModel::GetParameter ( const char *  name  ) 

Parameters:
name The name of the parameter in the parameter set.
Returns:
The parameter.

Definition at line 140 of file BCModel.cxx.

00141 {
00142    if (!fParameterSet)
00143       return 0;
00144 
00145    int index = -1;
00146    for (unsigned int i = 0; i < this->GetNParameters(); i++)
00147       if (name == this -> GetParameter(i) -> GetName())
00148          index = i;
00149 
00150    if (index<0)
00151    {
00152       BCLog::Out(BCLog::warning, BCLog::warning,
00153             Form("BCModel::GetParameter. Model %s has no parameter named %s.", (this -> GetName()).data(), name));
00154       return 0;
00155    }
00156 
00157    return this->GetParameter(index);
00158 }

BCParameter * BCModel::GetParameter ( int  index  ) 

Parameters:
index The index of the parameter in the parameter set.
Returns:
The parameter.

Definition at line 123 of file BCModel.cxx.

00124 {
00125    if (!fParameterSet)
00126       return 0;
00127 
00128    if (index < 0 || index >= (int)this -> GetNParameters())
00129    {
00130       BCLog::Out(BCLog::warning, BCLog::warning,
00131             Form("BCModel::GetParameter. Parameter index %d not within range.", index));
00132       return 0;
00133    }
00134 
00135    return fParameterSet -> at(index);
00136 }

double BCModel::GetPValue (  )  [inline]

Definition at line 492 of file BCModel.h.

00493          { return fPValue; };

double BCModel::GetPvalueFromChi2 ( std::vector< double >  par,
int  sigma_index 
)

Calculate p-value from Chi2 distribution for Gaussian problems

Parameters:
par Parameter set for the calculation of the likelihood
sigma_index Index of the sigma/uncertainty for the data points (for data in format "x y erry" the index would be 2)

Definition at line 1148 of file BCModel.cxx.

01149 {
01150    double ll = this -> LogLikelihood(par);
01151    int n = this -> GetNDataPoints();
01152 
01153    double sum_sigma=0;
01154    for (int i=0;i<n;i++)
01155       sum_sigma += log(this -> GetDataPoint(i) -> GetValue(sigma_index));
01156 
01157    double chi2 = -2.*(ll + (double)n/2. * log(2.*M_PI) + sum_sigma);
01158 
01159    fPValue = TMath::Prob(chi2,n);
01160 
01161    return fPValue;
01162 }

double BCModel::HessianMatrixElement ( BCParameter parameter1,
BCParameter parameter2,
std::vector< double >  point 
)

Calculates the matrix element of the Hessian matrix

Parameters:
parameter1 The parameter for the first derivative
parameter2 The parameter for the first derivative
Returns:
The matrix element of the Hessian matrix

Definition at line 1215 of file BCModel.cxx.

01216 {
01217    // check number of entries in vector
01218    if (point.size() != this -> GetNParameters())
01219    {
01220       BCLog::Out(BCLog::warning, BCLog::warning, Form("BCModel::HessianMatrixElement. Invalid number of entries in the vector."));
01221       return -1;
01222    }
01223 
01224    // define steps
01225    double nsteps = 1e5;
01226    double dx1 = (parameter1 -> GetUpperLimit() - parameter1 -> GetLowerLimit()) / nsteps;
01227    double dx2 = (parameter2 -> GetUpperLimit() - parameter2 -> GetLowerLimit()) / nsteps ;
01228 
01229    // define points at which to evaluate
01230    std::vector<double> xpp = point;
01231    std::vector<double> xpm = point;
01232    std::vector<double> xmp = point;
01233    std::vector<double> xmm = point;
01234 
01235    xpp.at(parameter1 -> GetIndex()) = xpp.at(parameter1 -> GetIndex()) + dx1;
01236    xpp.at(parameter2 -> GetIndex()) = xpp.at(parameter2 -> GetIndex()) + dx2;
01237 
01238    xpm.at(parameter1 -> GetIndex()) = xpm.at(parameter1 -> GetIndex()) + dx1;
01239    xpm.at(parameter2 -> GetIndex()) = xpm.at(parameter2 -> GetIndex()) - dx2;
01240 
01241    xmp.at(parameter1 -> GetIndex()) = xmp.at(parameter1 -> GetIndex()) - dx1;
01242    xmp.at(parameter2 -> GetIndex()) = xmp.at(parameter2 -> GetIndex()) + dx2;
01243 
01244    xmm.at(parameter1 -> GetIndex()) = xmm.at(parameter1 -> GetIndex()) - dx1;
01245    xmm.at(parameter2 -> GetIndex()) = xmm.at(parameter2 -> GetIndex()) - dx2;
01246 
01247    // calculate probability at these points
01248    double ppp = this -> Likelihood(xpp);
01249    double ppm = this -> Likelihood(xpm);
01250    double pmp = this -> Likelihood(xmp);
01251    double pmm = this -> Likelihood(xmm);
01252 
01253    // calculate derivative
01254    double derivative = (ppp + pmm - ppm - pmp) / (4.0 * dx1 * dx2);
01255 
01256    return derivative;
01257 }

double BCModel::Likelihood ( std::vector< double >  parameter  )  [inline]

Returns the likelihood

Parameters:
parameters A set of parameter values
Returns:
The likelihood

Definition at line 334 of file BCModel.h.

00335          { return exp( this->LogLikelihood(parameter) ); };

virtual double BCModel::LogAPrioriProbability ( std::vector< double >  parameters  )  [inline, virtual]

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

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

Reimplemented in BCEfficiencyFitter, BCGoFTest, BCGraphFitter, and BCHistogramFitter.

Definition at line 327 of file BCModel.h.

00328          { return 1.; };

virtual double BCModel::LogConditionalProbabilityEntry ( BCDataPoint datapoint,
std::vector< double >  parameters 
) [inline, virtual]

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

Parameters:
datapoint A data point
parameters A set of parameter values
Returns:
The conditional probability p(datapoint|parameters)
See also:
GetConditionalEntry(BCDataPoint* datapoint, std::vector <double> parameters)

Definition at line 388 of file BCModel.h.

00389          { flag_ConditionalProbabilityEntry = false; return 0.; };

double BCModel::LogEval ( std::vector< double >  parameters  )  [virtual]

Overloaded function to evaluate integral.

Reimplemented from BCIntegrate.

Definition at line 508 of file BCModel.cxx.

00509 {
00510    return this -> LogProbabilityNN(parameters);
00511 }

double BCModel::LogLikelihood ( std::vector< double >  parameter  )  [virtual]

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

Parameters:
parameters A set of parameter values
Returns:
Natural logarithm of the likelihood

Reimplemented in BCEfficiencyFitter, BCGoFTest, BCGraphFitter, and BCHistogramFitter.

Definition at line 492 of file BCModel.cxx.

00493 {
00494    double logprob = 0.;
00495 
00496    // add log of conditional probabilities event-by-event
00497    for (unsigned int i=0;i<fDataSet -> GetNDataPoints();i++)
00498    {
00499       BCDataPoint * datapoint = this -> GetDataPoint(i);
00500       logprob += this -> LogConditionalProbabilityEntry(datapoint, parameters);
00501    }
00502 
00503    return logprob;
00504 }

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

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

Parameters:
parameters A set of parameter values
Returns:
The a posteriori probability

Definition at line 477 of file BCModel.cxx.

00478 {
00479    // check if normalized
00480    if (fNormalization<0. || fNormalization==0.)
00481    {
00482       BCLog::Out(BCLog::warning, BCLog::warning,
00483              "BCModel::LogProbability. Normalization not available or zero.");
00484       return 0.;
00485    }
00486 
00487    return this -> LogProbabilityNN(parameters) - log(fNormalization);
00488 }

double BCModel::LogProbabilityNN ( std::vector< double >  parameter  ) 

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

Parameters:
parameters A set of parameter values
Returns:
The likelihood times prior probability

Definition at line 464 of file BCModel.cxx.

00465 {
00466    // add log of conditional probability
00467    double logprob = this -> LogLikelihood(parameters);
00468 
00469    // add log of prior probability
00470    logprob += this -> LogAPrioriProbability(parameters);
00471 
00472    return logprob;
00473 }

int BCModel::MarginalizeAll (  ) 

Marginalize all probabilities wrt. single parameters and all combinations of two parameters. The individual distributions can be retrieved using the GetMarginalized method.

Returns:
Total number of marginalized distributions

Definition at line 700 of file BCModel.cxx.

00701 {
00702    BCLog::Out(BCLog::summary,BCLog::summary,
00703       Form("Running MCMC for model \'%s\'",this->GetName().data()));
00704 
00705    // prepare function fitting
00706    double dx = 0.0;
00707    double dy = 0.0;
00708 
00709    if (fFitFunctionIndexX >= 0)
00710    {
00711       dx = (fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexX) - fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexX))
00712             / (double)fErrorBandNbinsX;
00713 
00714       dy = (fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexY) - fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexY))
00715             / (double)fErrorBandNbinsY;
00716 
00717       fErrorBandXY = new TH2D(
00718             TString::Format("errorbandxy_%d",BCLog::GetHIndex()), "",
00719             fErrorBandNbinsX,
00720             fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexX) - .5 * dx,
00721             fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexX) + .5 * dx,
00722             fErrorBandNbinsY,
00723             fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexY) - .5 * dy,
00724             fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexY) + .5 * dy);
00725       fErrorBandXY -> SetStats(kFALSE);
00726 
00727       for (int ix = 1; ix <= fErrorBandNbinsX; ++ix)
00728          for (int iy = 1; iy <= fErrorBandNbinsX; ++iy)
00729             fErrorBandXY -> SetBinContent(ix, iy, 0.0);
00730    }
00731 
00732    this -> MCMCMetropolis();
00733    this -> FindModeMCMC();
00734 
00735    // this -> PrintResults(Form("%s.txt", this -> GetName().data()));
00736 
00737    return 1;
00738 }

double BCModel::Normalize (  ) 

Integrates over the un-normalized probability and updates fNormalization.

Definition at line 532 of file BCModel.cxx.

00533 {
00534    BCLog::Out(BCLog::summary, BCLog::summary, Form("Model \'%s\': Normalizing probability",this->GetName().data()));
00535 
00536    unsigned int n = this -> GetNvar();
00537 
00538    // initialize BCIntegrate if not done already
00539    if (n == 0)
00540    {
00541       this->SetParameters(fParameterSet);
00542       n = this->GetNvar();
00543    }
00544 
00545    // integrate and get best fit parameters
00546    // maybe we have to remove the mode finding from here in the future
00547    fNormalization = this -> Integrate();
00548 
00549    BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Normalization factor : %.6g", fNormalization));
00550 
00551    return fNormalization;
00552 }

int BCModel::PrintAllMarginalized ( const char *  file,
unsigned int  hdiv = 1,
unsigned int  ndiv = 1 
)

Definition at line 940 of file BCModel.cxx.

00941 {
00942    if(fMCMCH1Marginalized.size()==0 || (fMCMCH2Marginalized.size()==0 && this -> GetNParameters() > 1))
00943    {
00944       BCLog::Out(BCLog::error, BCLog::error,
00945             "BCModel::PrintAllMarginalized : Marginalized distributions not available.");
00946       return 0;
00947    }
00948 
00949    // if there's only one parameter, we just want to call Print()
00950    if (fMCMCH1Marginalized.size()==1 && fMCMCH2Marginalized.size()==0)
00951    {
00952       BCParameter * a = this->GetParameter(0);
00953       this -> GetMarginalized(a) -> Print(file);
00954       return 1;
00955    }
00956 
00957    int c_width=600; // default canvas width
00958    int c_height=600; // default canvas height
00959 
00960    int type = 112; // landscape
00961 
00962    if (hdiv > vdiv)
00963    {
00964       if(hdiv>3)
00965       {
00966          c_width=1000;
00967          c_height=700;
00968       }
00969       else
00970       {
00971          c_width=800;
00972          c_height=600;
00973       }
00974    }
00975    else if(hdiv < vdiv)
00976    {
00977       if(hdiv>3)
00978       {
00979          c_height=1000;
00980          c_width=700;
00981       }
00982       else
00983       {
00984          c_height=800;
00985          c_width=600;
00986       }
00987       type=111;
00988    }
00989 
00990    // get number of parameters of the model and calculate number of plots
00991    int npar = this -> GetNParameters();
00992    int nplots2d = npar * (npar-1)/2;
00993    int nplots = npar + nplots2d;
00994 
00995    // give out warning if too many plots
00996    BCLog::Out(BCLog::summary,BCLog::summary,
00997          Form("Printing all marginalized distributions (%d x 1D + %d x 2D = %d) into file %s",
00998                npar,nplots2d,nplots,file));
00999    if(nplots>100)
01000       BCLog::Out(BCLog::detail,BCLog::detail,"This can take a while...");
01001 
01002    // setup the canvas and postscript file
01003    TCanvas * c = new TCanvas( "c","canvas",c_width,c_height);
01004 
01005    TPostScript * ps = new TPostScript(file,type);
01006 
01007    if(type==112)
01008       ps->Range(24,16);
01009    else
01010       ps->Range(16,24);
01011 
01012    // draw all 1D distributions
01013    ps->NewPage();
01014    c->cd();
01015    c->Clear();
01016    c->Divide(hdiv,vdiv);
01017 
01018    int n=0;
01019    for(int i=0;i<npar;i++)
01020    {
01021       // if current page is full, swith to new page
01022       if(i!=0 && i%(hdiv*vdiv)==0)
01023       {
01024          c->Update();
01025          ps->NewPage();
01026          c->cd();
01027          c->Clear();
01028          c->Divide(hdiv,vdiv);
01029       }
01030 
01031       // go to next pad
01032       c->cd(i%(hdiv*vdiv)+1);
01033 
01034       BCParameter * a = this->GetParameter(i);
01035       this -> GetMarginalized(a) -> Draw();
01036       n++;
01037 
01038       if(n%100==0)
01039          BCLog::Out(BCLog::detail,BCLog::detail,Form(" --> %d plots done",n));
01040    }
01041 
01042    c->Update();
01043 
01044    // draw all the 2D distributions
01045    ps->NewPage();
01046    c->cd();
01047    c->Clear();
01048    c->Divide(hdiv,vdiv);
01049 
01050    int k=0;
01051    for(int i=0;i<npar-1;i++)
01052    {
01053       for(int j=i+1;j<npar;j++)
01054       {
01055          // if current page is full, switch to new page
01056          if(k!=0 && k%(hdiv*vdiv)==0)
01057          {
01058             c->Update();
01059             ps->NewPage();
01060             c->cd();
01061             c->Clear();
01062             c->Divide(hdiv,vdiv);
01063          }
01064 
01065          // go to next pad
01066          c->cd(k%(hdiv*vdiv)+1);
01067 
01068          BCParameter * a = this->GetParameter(i);
01069          BCParameter * b = this->GetParameter(j);
01070 
01071          double meana = (a -> GetLowerLimit() + a -> GetUpperLimit()) / 2.0;
01072          double deltaa = (a -> GetUpperLimit() - a -> GetLowerLimit());
01073          if (deltaa <= 1e-7 * meana)
01074             continue;
01075 
01076          double meanb = (b -> GetLowerLimit() + b -> GetUpperLimit()) / 2.0;
01077          double deltab = (b -> GetUpperLimit() - b -> GetLowerLimit());
01078          if (deltab <= 1e-7 * meanb)
01079             continue;
01080 
01081          this -> GetMarginalized(a,b) -> Draw(52);
01082          k++;
01083 
01084          if((n+k)%100==0)
01085             BCLog::Out(BCLog::detail,BCLog::detail,Form(" --> %d plots done",n+k));
01086       }
01087    }
01088 
01089    if( (n+k)>100 && (n+k)%100 != 0 )
01090       BCLog::Out(BCLog::detail,BCLog::detail,Form(" --> %d plots done",n+k));
01091 
01092    c->Update();
01093    ps->Close();
01094 
01095    delete c;
01096    delete ps;
01097 
01098    // return total number of drawn histograms
01099    return n+k;
01100 }

int BCModel::PrintAllMarginalized1D ( const char *  filebase  ) 

Definition at line 881 of file BCModel.cxx.

00882 {
00883    if(fMCMCH1Marginalized.size()==0)
00884    {
00885       BCLog::Out(BCLog::warning, BCLog::warning,
00886             "BCModel::PrintAllMarginalized1D : MarginalizeAll() has to be run prior to this to fill the distributions.");
00887       return 0;
00888    }
00889 
00890    int n=this->GetNParameters();
00891    for(int i=0;i<n;i++)
00892    {
00893       BCParameter * a = this->GetParameter(i);
00894       this -> GetMarginalized(a) -> Print(Form("%s_1D_%s.ps",filebase,a->GetName().data()));
00895    }
00896 
00897    return n;
00898 }

int BCModel::PrintAllMarginalized2D ( const char *  filebase  ) 

Definition at line 902 of file BCModel.cxx.

00903 {
00904    if(fMCMCH2Marginalized.size()==0)
00905    {
00906       BCLog::Out(BCLog::warning, BCLog::warning,
00907             "BCModel::PrintAllMarginalized2D : MarginalizeAll() has to be run prior to this to fill the distributions.");
00908       return 0;
00909    }
00910 
00911    int k=0;
00912    int n=this->GetNParameters();
00913    for(int i=0;i<n-1;i++)
00914    {
00915       for(int j=i+1;j<n;j++)
00916       {
00917          BCParameter * a = this->GetParameter(i);
00918          BCParameter * b = this->GetParameter(j);
00919 
00920          double meana = (a -> GetLowerLimit() + a -> GetUpperLimit()) / 2.0;
00921          double deltaa = (a -> GetUpperLimit() - a -> GetLowerLimit());
00922          if (deltaa <= 1e-7 * meana)
00923             continue;
00924 
00925          double meanb = (b -> GetLowerLimit() + b -> GetUpperLimit()) / 2.0;
00926          double deltab = (b -> GetUpperLimit() - b -> GetLowerLimit());
00927          if (deltab <= 1e-7 * meanb)
00928             continue;
00929 
00930          this -> GetMarginalized(a,b) -> Print(Form("%s_2D_%s_%s.ps",filebase,a->GetName().data(),b->GetName().data()));
00931          k++;
00932       }
00933    }
00934 
00935    return k;
00936 }

void BCModel::PrintHessianMatrix ( std::vector< double >  parameters  ) 

Prints matrix elements of the Hessian matrix

Parameters:
parameters The parameter values at which point to evaluate the matrix

Definition at line 1526 of file BCModel.cxx.

01527 {
01528    // check number of entries in vector
01529    if (parameters.size() != this -> GetNParameters())
01530    {
01531       BCLog::Out(BCLog::warning, BCLog::warning,
01532             Form("BCModel::PrintHessianMatrix. Invalid number of entries in the vector."));
01533       return;
01534    }
01535 
01536    // print to screen
01537    std::cout
01538       << std::endl
01539       << " Hessian matrix elements: " << std::endl
01540       << " Point: ";
01541 
01542    for (int i = 0; i < int(parameters.size()); i++)
01543       std::cout << parameters.at(i) << " ";
01544    std::cout << std::endl;
01545 
01546    // loop over all parameter pairs
01547    for (unsigned int i = 0; i < this -> GetNParameters(); i++)
01548       for (unsigned int j = 0; j < i; j++)
01549       {
01550          // calculate Hessian matrix element
01551          double hessianmatrixelement = this -> HessianMatrixElement(fParameterSet -> at(i),
01552                fParameterSet -> at(j), parameters);
01553 
01554          // print to screen
01555          std::cout << " " << i << " " << j << " : " << hessianmatrixelement << std::endl;
01556       }
01557 }

void BCModel::PrintResults ( const char *  file  ) 

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

Definition at line 1355 of file BCModel.cxx.

01356 {
01357    // print summary of Markov Chain Monte Carlo
01358 
01359    // open file
01360    ofstream ofi(file);
01361 
01362    // check if file is open
01363    if(!ofi.is_open())
01364    {
01365       std::cerr << "Couldn't open file " << file <<std::endl;
01366       return;
01367    }
01368 
01369    // number of parameters
01370    int npar = fParameterSet -> size();
01371 
01372    // check convergence
01373    bool flag_conv = ((this -> MCMCGetNIterationsConvergenceGlobal() > 0)?1:0);
01374 
01375    ofi
01376       << std::endl
01377       << " -----------------------------------------------------" << std::endl
01378       << " Summary of the Markov Chain Monte Carlo run" << std::endl
01379       << " -----------------------------------------------------" << std::endl
01380       << std::endl;
01381 
01382    if (!flag_conv)
01383    {
01384       ofi
01385          << " WARNING: the Markov Chain did not converge! Be" << std::endl
01386          << " cautious using the following results!" << std::endl
01387          << std::endl;
01388    }
01389 
01390    ofi
01391       << " Model summary" << std::endl
01392       << " =============" << std::endl
01393       << " Model: " << fName.data() << std::endl
01394       << " Number of parameters: " << npar << std::endl
01395       << " List of Parameters and ranges:" << std::endl;
01396    for (int i = 0; i < npar; ++i)
01397    {
01398       ofi
01399          << "  (" << i << ") Parameter \""
01400          << fParameterSet -> at(i) -> GetName().data() << "\""
01401          << ": " << fParameterSet -> at(i) -> GetLowerLimit()
01402          << " - "
01403          << fParameterSet -> at(i) -> GetUpperLimit() << std::endl;
01404    }
01405    ofi << std::endl;
01406 
01407    if (flag_conv)
01408    {
01409       ofi
01410          << " Results of the marginalization" << std::endl
01411          << " ==============================" << std::endl
01412          << " List of parameters and properties of the marginalized" << std::endl
01413          << " distributions:" << std::endl;
01414       for (int i = 0; i < npar; ++i)
01415       {
01416          BCH1D * bch1d = this -> GetMarginalized(fParameterSet -> at(i));
01417 
01418          ofi
01419             << "  (" << i << ") Parameter \""
01420                << fParameterSet -> at(i) -> GetName().data() << "\"" << std::endl
01421             << "      Mean +- RMS:         "
01422                << std::setprecision(4) << bch1d -> GetMean()
01423                << " +- "
01424                << std::setprecision(4) << bch1d -> GetRMS() << std::endl
01425             << "      Median +- sigma:     "
01426                << std::setprecision(4) << bch1d -> GetMedian()
01427                << " +  " << std::setprecision(4) << bch1d -> GetQuantile(0.84) - bch1d -> GetMedian()
01428                << " - " << std::setprecision(4) << bch1d -> GetMedian() - bch1d -> GetQuantile(0.16) << std::endl
01429             << "      (Marginalized) mode: " << bch1d -> GetMode() << std::endl
01430             << "      Smallest interval(s) containing 68% and local modes:" << std::endl;
01431 
01432          std::vector <double> v;
01433          v = bch1d -> GetSmallestIntervals(0.68);
01434          int ninter = int(v.size());
01435 
01436          for (int j = 0; j < ninter; j+=5)
01437             ofi << "       " << v.at(j) << " - " << v.at(j+1) << " (local mode at " << v.at(j+3) << " with rel. height " << v.at(j+2) << "; rel. area " << v.at(j+4) << ")" << std::endl;
01438       }
01439       ofi << std::endl;
01440    }
01441 
01442    ofi
01443       << " Results of the optimization" << std::endl
01444       << " ===========================" << std::endl
01445       << " Optimization algorithm used: ";
01446    switch(this -> GetOptimizationMethod())
01447    {
01448       case BCIntegrate::kOptSimulatedAnnealing:
01449          ofi << " Simulated Annealing" << std::endl;
01450          break;
01451       case BCIntegrate::kOptMinuit:
01452          ofi << " Minuit" << std::endl;
01453          break;
01454       case BCIntegrate::kOptMetropolis:
01455          ofi << " MCMC " << std::endl;
01456          break;
01457    }
01458 
01459    ofi << " List of parameters and global mode:" << std::endl;
01460    for (int i = 0; i < npar; ++i)
01461       ofi
01462          << "  (" << i << ") Parameter \""
01463          << fParameterSet -> at(i) -> GetName().data() << "\": "
01464          << fBestFitParameters.at(i) << std::endl;
01465    ofi << std::endl;
01466 
01467    if (fPValue >= 0.)
01468    {
01469       ofi
01470          << " Results of the model test" << std::endl
01471          << " =========================" << std::endl
01472          << " p-value at global mode: " << fPValue << std::endl
01473          << std::endl;
01474    }
01475 
01476    ofi
01477       << " Status of the MCMC" << std::endl
01478       << " ==================" << std::endl
01479       << " Convergence reached: " << ((flag_conv)?"yes":"no") << std::endl;
01480 
01481    if (flag_conv)
01482       ofi << " Number of iterations until convergence: " << this -> MCMCGetNIterationsConvergenceGlobal() << std::endl;
01483    else
01484       ofi
01485          << " WARNING: the Markov Chain did not converge! Be\n"
01486          << " cautious using the following results!" << std::endl
01487          << std::endl;
01488    ofi
01489       << " Number of chains:                       " << this -> MCMCGetNChains() << std::endl
01490       << " Number of iterations of each chain:     " << this -> MCMCGetNIterationsMax() << std::endl
01491       << std::endl;
01492 
01493    ofi
01494       << " -----------------------------------------------------" << std::endl
01495       << std::endl
01496       << " Notes" << std::endl
01497       << " =====" << std::endl
01498       << " (i) Median +- sigma denotes the median, m, of the" << std::endl
01499       << "     marginalized distribution and the intervals from" << std::endl
01500       << "     m to the 16% and 84% quantiles." << std::endl
01501       << " -----------------------------------------------------" << std::endl;
01502 
01503    // close file
01504 // ofi.close;
01505 }

void BCModel::PrintShortFitSummary (  ) 

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

Definition at line 1509 of file BCModel.cxx.

01510 {
01511    BCLog::Out(BCLog::summary, BCLog::summary, "---------------------------------------------------");
01512    BCLog::Out(BCLog::summary, BCLog::summary, Form("Fit summary for model \'%s\':",this -> GetName().data()));
01513    BCLog::Out(BCLog::summary, BCLog::summary, Form("   Number of parameters = %i", this -> GetNParameters()));
01514 
01515    BCLog::Out(BCLog::summary, BCLog::summary, "   Best fit parameters (global):");
01516    for (unsigned int i = 0; i < this -> GetNParameters(); ++i)
01517       BCLog::Out(BCLog::summary, BCLog::summary, Form("      %s = %.2lf", this -> GetParameter(i) -> GetName().data(), this -> GetBestFitParameter(i)));
01518 
01519    BCLog::Out(BCLog::summary, BCLog::summary, "   Goodness-of-fit test:");
01520    BCLog::Out(BCLog::summary, BCLog::summary, Form("      p-value = %.2lf", this -> GetPValue()));
01521    BCLog::Out(BCLog::summary, BCLog::summary, "---------------------------------------------------");
01522 }

void BCModel::PrintSummary (  ) 

Prints a summary on the screen.

Definition at line 1292 of file BCModel.cxx.

01293 {
01294    int nparameters = this -> GetNParameters();
01295 
01296    // model summary
01297    std::cout
01298       << std::endl
01299       << "   ---------------------------------" << std::endl
01300       << "    Model : " << fName.data() << std::endl
01301       << "   ---------------------------------"<< std::endl
01302       << "     Index                : " << fIndex << std::endl
01303       << "     Number of parameters : " << nparameters << std::endl
01304       << std::endl
01305       << "     - Parameters : " << std::endl
01306       << std::endl;
01307 
01308    // parameter summary
01309    for (int i=0; i<nparameters; i++)
01310       fParameterSet -> at(i) -> PrintSummary();
01311 
01312    // best fit parameters
01313    if (this -> GetBestFitParameters().size() > 0)
01314    {
01315       std::cout
01316          << std::endl
01317          << "     - Best fit parameters :" << std::endl
01318          << std::endl;
01319 
01320       for (int i=0; i<nparameters; i++)
01321       {
01322          std::cout
01323             << "       " << fParameterSet -> at(i) -> GetName().data()
01324             << " = " << this -> GetBestFitParameter(i)
01325             << " (overall)" << std::endl;
01326          if ((int)fBestFitParametersMarginalized.size() == nparameters)
01327             std::cout
01328                << "       " << fParameterSet -> at(i) -> GetName().data()
01329                << " = " << this -> GetBestFitParameterMarginalized(i)
01330                << " (marginalized)" << std::endl;
01331       }
01332    }
01333 
01334    std::cout << std::endl;
01335 
01336    // model testing
01337    if (fPValue >= 0)
01338    {
01339       double likelihood = this -> Likelihood(this -> GetBestFitParameters());
01340       std::cout
01341          << "   - Model testing:" << std::endl
01342          << std::endl
01343          << "       p(data|lambda*) = " << likelihood << std::endl
01344          << "       p-value         = " << fPValue << std::endl
01345          << std::endl;
01346    }
01347 
01348    // normalization
01349    if (fNormalization > 0)
01350       std::cout << "     Normalization        : " << fNormalization << std::endl;
01351 }

double BCModel::Probability ( std::vector< double >  parameter  )  [inline]

Returns the a posteriori probability given a set of parameter values

Parameters:
parameters A set of parameter values
Returns:
The a posteriori probability

Definition at line 362 of file BCModel.h.

00363          { return exp( this->LogProbability(parameter) ); };

double BCModel::ProbabilityNN ( std::vector< double >  parameter  )  [inline]

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

Parameters:
parameters A set of parameter values
Returns:
The likelihood times prior probability

Definition at line 348 of file BCModel.h.

00349          { return exp( this->LogProbabilityNN(parameter) ); };

int BCModel::ReadErrorBandFromFile ( const char *  file  ) 

Read

Definition at line 851 of file BCModel.cxx.

00852 {
00853    TFile * froot = new TFile(file);
00854    if(!froot->IsOpen())
00855    {
00856       BCLog::Out(BCLog::warning, BCLog::warning, Form("BCModel::ReadErrorBandFromFile. Couldn't open file %s.",file));
00857       return 0;
00858    }
00859 
00860    int r=0;
00861 
00862    TH2D * h2 = (TH2D*)froot->Get("errorbandxy");
00863    if(h2)
00864    {
00865       h2->SetDirectory(0);
00866       h2->SetName(TString::Format("errorbandxy_%d",BCLog::GetHIndex()));
00867       this->SetErrorBandHisto(h2);
00868       r=1;
00869    }
00870    else
00871       BCLog::Out(BCLog::warning, BCLog::warning,
00872          Form("BCModel::ReadErrorBandFromFile : Couldn't read histogram \"errorbandxy\" from file %s.", file));
00873 
00874    froot->Close();
00875 
00876    return r;
00877 }

int BCModel::ReadMarginalizedFromFile ( const char *  file  ) 

Read

Definition at line 786 of file BCModel.cxx.

00787 {
00788    TFile * froot = new TFile(file);
00789    if(!froot->IsOpen())
00790    {
00791       BCLog::Out(BCLog::error, BCLog::error,
00792             Form("BCModel::ReadMarginalizedFromFile : Couldn't open file %s.",file));
00793       return 0;
00794    }
00795 
00796    // We reset the MCMCEngine here for the moment.
00797    // In the future maybe we only want to do this if the engine
00798    // wans't initialized at all or when there were some changes
00799    // in the model.
00800    // But maybe we want reset everything since we're overwriting
00801    // the marginalized distributions anyway.
00802    this -> MCMCInitialize();
00803 
00804    int k=0;
00805    int n=this->GetNParameters();
00806    for(int i=0;i<n;i++)
00807    {
00808       BCParameter * a = this -> GetParameter(i);
00809       TKey * key = froot -> GetKey(TString::Format("hist_%s_%s", this -> GetName().data(), a -> GetName().data()));
00810       if(key)
00811       {
00812          TH1D * h1 = (TH1D*) key -> ReadObjectAny(TH1D::Class());
00813          h1->SetDirectory(0);
00814          if(this->SetMarginalized(i,h1))
00815             k++;
00816       }
00817       else
00818          BCLog::Out(BCLog::warning, BCLog::warning,
00819             Form("BCModel::ReadMarginalizedFromFile. Couldn't read histogram \"hist_%s_%s\" from file %s.",
00820                this -> GetName().data(), a -> GetName().data(), file));
00821    }
00822 
00823    for(int i=0;i<n-1;i++)
00824    {
00825       for(int j=i+1;j<n;j++)
00826       {
00827          BCParameter * a = this -> GetParameter(i);
00828          BCParameter * b = this -> GetParameter(j);
00829          TKey * key = froot -> GetKey(TString::Format("hist_%s_%s_%s", this -> GetName().data(), a -> GetName().data(), b -> GetName().data()));
00830          if(key)
00831          {
00832             TH2D * h2 = (TH2D*) key -> ReadObjectAny(TH2D::Class());
00833             h2->SetDirectory(0);
00834             if(this->SetMarginalized(i,j,h2))
00835                k++;
00836          }
00837          else
00838             BCLog::Out(BCLog::warning, BCLog::warning,
00839                Form("BCModel::ReadMarginalizedFromFile. Couldn't read histogram \"hist_%s_%s_%s\" from file %s.",
00840                   this -> GetName().data(), a -> GetName().data(), b -> GetName().data(), file));
00841       }
00842    }
00843 
00844    froot->Close();
00845 
00846    return k;
00847 }

int BCModel::ReadMode ( const char *  file  ) 

Read mode from file created by WriteMode() call

Definition at line 654 of file BCModel.cxx.

00655 {
00656    ifstream ifi(file);
00657    if(!ifi.is_open())
00658    {
00659       BCLog::Out(BCLog::error,BCLog::error,
00660             Form("BCModel::ReadMode : Couldn't open file %s.",file));
00661       return 0;
00662    }
00663 
00664    int npar = fParameterSet -> size();
00665    std::vector <double> mode;
00666 
00667    int i=0;
00668    while (i<npar && !ifi.eof())
00669    {
00670       double a;
00671       ifi>>a;
00672       mode.push_back(a);
00673       i++;
00674    }
00675 
00676    if(i<npar)
00677    {
00678       BCLog::Out(BCLog::error,BCLog::error,
00679             Form("BCModel::ReadMode : Couldn't read mode from file %s.",file));
00680       BCLog::Out(BCLog::error,BCLog::error,
00681             Form("BCModel::ReadMode : Expected %d parameters, found %d.",npar,i));
00682       return 0;
00683    }
00684 
00685    BCLog::Out(BCLog::summary,BCLog::summary,
00686          Form("#  Read in best fit parameters (mode) for model \'%s\' from file %s:",fName.data(),file));
00687    this->SetMode(mode);
00688    for(int j=0 ; j<npar; j++)
00689       BCLog::Out(BCLog::summary,BCLog::summary,
00690             Form("#    -> Parameter %d : %s = %e", j, fParameterSet->at(j)->GetName().data(), fBestFitParameters[j]));
00691 
00692    BCLog::Out(BCLog::warning,BCLog::warning,
00693          "#  ! Best fit values obtained before this call will be overwritten !");
00694 
00695    return npar;
00696 }

double BCModel::SamplingFunction ( std::vector< double >  parameters  )  [virtual]

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

Parameters:
parameters A set of parameter values
Returns:
The probability density at the parameter values

Definition at line 522 of file BCModel.cxx.

00523 {
00524    double probability = 1.0;
00525    for (std::vector<BCParameter*>::const_iterator it = fParameterSet -> begin(); it != fParameterSet -> end(); ++it)
00526       probability *= 1.0 / ((*it) -> GetUpperLimit() - (*it) -> GetLowerLimit());
00527    return probability;
00528 }

void BCModel::SetDataBoundaries ( unsigned int  index,
double  lowerboundary,
double  upperboundary,
bool  fixed = false 
)

Definition at line 353 of file BCModel.cxx.

00354 {
00355    // check if data set exists
00356    if (!fDataSet)
00357    {
00358       BCLog::Out(BCLog::error, BCLog::error,
00359              "BCModel::SetDataBoundaries : Need to define data set first.");
00360       return;
00361    }
00362 
00363    // check if index is within range
00364    if (index < 0 || index > fDataSet -> GetDataPoint(0) -> GetNValues())
00365    {
00366       BCLog::Out(BCLog::error, BCLog::error,
00367             "BCModel::SetDataBoundaries : Index out of range.");
00368       return;
00369    }
00370 
00371    // check if boundary data points exist
00372    if (!fDataPointLowerBoundaries)
00373       fDataPointLowerBoundaries = new BCDataPoint(fDataSet -> GetDataPoint(0) -> GetNValues());
00374 
00375    if (!fDataPointUpperBoundaries)
00376       fDataPointUpperBoundaries = new BCDataPoint(fDataSet -> GetDataPoint(0) -> GetNValues());
00377 
00378    if (fDataFixedValues.size() == 0)
00379       fDataFixedValues.assign(fDataSet -> GetDataPoint(0) -> GetNValues(), false);
00380 
00381    // set boundaries
00382    fDataPointLowerBoundaries -> SetValue(index, lowerboundary);
00383    fDataPointUpperBoundaries -> SetValue(index, upperboundary);
00384    fDataFixedValues[index] = fixed;
00385 }

void BCModel::SetDataSet ( BCDataSet dataset  )  [inline]

Sets the data set.

Parameters:
dataset A data set

Definition at line 262 of file BCModel.h.

00263          { fDataSet = dataset; fNormalization = -1.0; };

void BCModel::SetErrorBandContinuous ( bool  flag  ) 

Sets the error band flag to continuous function

Definition at line 389 of file BCModel.cxx.

00390 {
00391    fErrorBandContinuous = flag;
00392 
00393    if (flag)
00394       return;
00395 
00396    // clear x-values
00397    fErrorBandX.clear();
00398 
00399    // copy data x-values
00400    for (unsigned int i = 0; i < fDataSet -> GetNDataPoints(); ++i)
00401       fErrorBandX.push_back(fDataSet -> GetDataPoint(i) -> GetValue(fFitFunctionIndexX));
00402 }

void BCModel::SetGoFNChains ( int  n  )  [inline]

Definition at line 510 of file BCModel.h.

00511          { fGoFNChains=n; };

void BCModel::SetGoFNIterationsMax ( int  n  )  [inline]

Definition at line 498 of file BCModel.h.

00499          { fGoFNIterationsMax=n; };

void BCModel::SetGoFNIterationsRun ( int  n  )  [inline]

Definition at line 504 of file BCModel.h.

00505          { fGoFNIterationsRun=n; };

void BCModel::SetIndex ( int  index  )  [inline]

Sets the index of the model within the BCModelManager.

Parameters:
index The index of the model

Definition at line 235 of file BCModel.h.

00236          { fIndex = index; };

void BCModel::SetModelAPosterioriProbability ( double  probability  )  [inline]

Sets the a posteriori probability for a model.

Parameters:
model The model
probability The a posteriori probability

Definition at line 249 of file BCModel.h.

00250          { fModelAPosteriori = probability; };

void BCModel::SetModelAPrioriProbability ( double  probability  )  [inline]

Sets the a priori probability for a model.

Parameters:
model The model
probability The a priori probability

Definition at line 242 of file BCModel.h.

00243          { fModelAPriori = probability; };

void BCModel::SetName ( const char *  name  )  [inline]

Sets the name of the model.

Parameters:
name Name of the model

Definition at line 229 of file BCModel.h.

00230          { fName = name; };

void BCModel::SetNDataPointsMaximum ( unsigned int  maximum  )  [inline]

Sets the maximum number of data points.

Definition at line 279 of file BCModel.h.

00280          { fNDataPointsMaximum = maximum; };

void BCModel::SetNDataPointsMinimum ( unsigned int  minimum  )  [inline]

Sets the minimum number of data points.

Definition at line 274 of file BCModel.h.

00275          { fNDataPointsMinimum = minimum; };

void BCModel::SetNormalization ( double  norm  )  [inline]

Sets the normalization of the likelihood. The normalization is the integral of likelihood over all parameters.

Parameters:
norm The normalization of the likelihood

Definition at line 256 of file BCModel.h.

00257          { fNormalization = norm; };

void BCModel::SetSingleDataPoint ( BCDataSet dataset,
unsigned int  index 
)

Definition at line 343 of file BCModel.cxx.

00344 {
00345    if (index < 0 || index > dataset -> GetNDataPoints())
00346       return;
00347 
00348    this -> SetSingleDataPoint(dataset -> GetDataPoint(index));
00349 }

void BCModel::SetSingleDataPoint ( BCDataPoint datapoint  ) 

Sets a single data point as data set.

Parameters:
datapoint A data point

Definition at line 328 of file BCModel.cxx.

00329 {
00330    // create new data set consisting of a single data point
00331    BCDataSet * dataset = new BCDataSet();
00332 
00333    // add the data point
00334    dataset -> AddDataPoint(datapoint);
00335 
00336    // set this new data set
00337    this -> SetDataSet(dataset);
00338 
00339 }

BCDataPoint * BCModel::VectorToDataPoint ( std::vector< double >  data  )  [private]

Converts a vector of doubles into a BCDataPoint

Definition at line 1561 of file BCModel.cxx.

01562 {
01563    int sizeofvector = int(data.size());
01564    BCDataPoint * datapoint = new BCDataPoint(sizeofvector);
01565    datapoint -> SetValues(data);
01566    return datapoint;
01567 }

void BCModel::WriteMode ( const char *  file  ) 

Write mode into file

Definition at line 613 of file BCModel.cxx.

00614 {
00615    ofstream ofi(file);
00616    if(!ofi.is_open())
00617    {
00618       std::cerr<<"Couldn't open file "<<file<<std::endl;
00619       return;
00620    }
00621 
00622    int npar = fParameterSet -> size();
00623    for (int i=0; i<npar; i++)
00624       ofi<<fBestFitParameters.at(i)<<std::endl;
00625 
00626    ofi<<std::endl;
00627    ofi<<"#######################################################################"<<std::endl;
00628    ofi<<"#"<<std::endl;
00629    ofi<<"#  This file was created automatically by BCModel::WriteMode() call."<<std::endl;
00630    ofi<<"#  It can be read in by call to BCModel::ReadMode()."<<std::endl;
00631    ofi<<"#  Do not modify it unless you know what you're doing."<<std::endl;
00632    ofi<<"#"<<std::endl;
00633    ofi<<"#######################################################################"<<std::endl;
00634    ofi<<"#"<<std::endl;
00635    ofi<<"#  Best fit parameters (mode) for model:"<<std::endl;
00636    ofi<<"#  \'"<<fName.data()<<"\'"<<std::endl;
00637    ofi<<"#"<<std::endl;
00638    ofi<<"#  Number of parameters: "<<npar<<std::endl;
00639    ofi<<"#  Parameters ordered as above:"<<std::endl;
00640 
00641    for (int i=0; i<npar; i++)
00642    {
00643       ofi<<"#     "<<i<<": ";
00644       ofi<<fParameterSet->at(i)->GetName().data()<<" = ";
00645       ofi<<fBestFitParameters.at(i)<<std::endl;
00646    }
00647 
00648    ofi<<"#"<<std::endl;
00649    ofi<<"########################################################################"<<std::endl;
00650 }


Member Data Documentation

A data set

Definition at line 565 of file BCModel.h.

int BCModel::fGoFNChains [protected]

Definition at line 596 of file BCModel.h.

int BCModel::fGoFNIterationsMax [protected]

Definition at line 586 of file BCModel.h.

int BCModel::fGoFNIterationsRun [protected]

Definition at line 591 of file BCModel.h.

int BCModel::fIndex [protected]

Index of the model.

Definition at line 545 of file BCModel.h.

A flag for overloading ConditionalProbabilityEntry

Definition at line 577 of file BCModel.h.

double BCModel::fModelAPosteriori [protected]

The model a posteriori probability.

Definition at line 557 of file BCModel.h.

double BCModel::fModelAPriori [protected]

The model prior probability.

Definition at line 553 of file BCModel.h.

std::string BCModel::fName [protected]

Name of the model.

Definition at line 549 of file BCModel.h.

unsigned int BCModel::fNDataPointsMaximum [protected]

Maximum number of data points

Definition at line 573 of file BCModel.h.

unsigned int BCModel::fNDataPointsMinimum [protected]

Minimum number of data points

Definition at line 569 of file BCModel.h.

double BCModel::fNormalization [private]

The Likelihood normalization.

Definition at line 610 of file BCModel.h.

A model parameter container.

Definition at line 561 of file BCModel.h.

double BCModel::fPValue [protected]

The p-value

Definition at line 581 of file BCModel.h.


Generated on Fri Jan 16 10:24:10 2009 for BAT - Bayesian Analysis Toolkit by  doxygen 1.5.6