• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

BCModel.h

Go to the documentation of this file.
00001 #ifndef __BCMODEL__H
00002 #define __BCMODEL__H
00003 
00004 /*!
00005  * \class BCModel
00006  * \brief The base class for all user-defined models.
00007  * \author Daniel Kollar
00008  * \author Kevin Kröninger
00009  * \version 1.0
00010  * \date 08.2008
00011  * \detail This class represents a model. It contains a container of
00012  * parameters, their prior distributions and the conditional
00013  * probabilities given those parameters.  The methods which implement
00014  * the prior and conditional probabilities have to be overloaded by
00015  * the user in the user defined model class which will inherit from
00016  * this class.
00017  */
00018 
00019 /*
00020  * Copyright (C) 2008-2010, Daniel Kollar and Kevin Kroeninger.
00021  * All rights reserved.
00022  *
00023  * For the licensing terms see doc/COPYING.
00024  */
00025 
00026 // ---------------------------------------------------------
00027 
00028 #include <vector>
00029 #include <string>
00030 
00031 #include "BAT/BCIntegrate.h"
00032 
00033 // ROOT classes
00034 class TH2D;
00035 class TGraph;
00036 class TCanvas;
00037 class TPostscript;
00038 class TF1;
00039 
00040 //BAT classes
00041 class BCDataPoint;
00042 class BCDataSet;
00043 class BCParameter;
00044 class BCH1D;
00045 class BCH2D;
00046 
00047 const int MAXNDATAPOINTVALUES = 20;
00048 
00049 // ---------------------------------------------------------
00050 
00051 class BCModel : public BCIntegrate
00052 {
00053 
00054    public:
00055 
00056       /** \name Constructors and destructors */
00057       /* @{ */
00058 
00059       /**
00060        * The default constructor. */
00061       BCModel();
00062 
00063       /**
00064        * A constructor.
00065        * @param name The name of the model */
00066       BCModel(const char * name);
00067 
00068       /**
00069        * The default destructor. */
00070       virtual ~BCModel();
00071 
00072       /* @} */
00073 
00074       /** \name Member functions (get) */
00075       /* @{ */
00076 
00077       /**
00078        * @return The name of the model. */
00079       std::string GetName()
00080          { return fName; };
00081 
00082       /**
00083        * @return The index of the model. */
00084       int GetIndex()
00085          { return fIndex; };
00086 
00087       /**
00088        * @return The a priori probability. */
00089       double GetModelAPrioriProbability()
00090          { return fModelAPriori; };
00091 
00092       /**
00093        * @return The a posteriori probability. */
00094       double GetModelAPosterioriProbability()
00095          { return fModelAPosteriori; };
00096 
00097       /**
00098        * @return The normalization factor of the probability */
00099       double GetNormalization()
00100          { return fNormalization; };
00101 
00102       /**
00103        * @return The data set. */
00104       BCDataSet* GetDataSet()
00105          { return fDataSet; };
00106 
00107       /**
00108        * @return The lower boundaries of possible data values. */
00109       BCDataPoint* GetDataPointLowerBoundaries()
00110          { return fDataPointLowerBoundaries; };
00111 
00112       /**
00113        * @return The upper boundaries of possible data values. */
00114       BCDataPoint* GetDataPointUpperBoundaries()
00115          { return fDataPointUpperBoundaries; };
00116 
00117       /**
00118        * @param index The index of the variable.
00119        * @return The lower boundary of possible data values for a particular variable. */
00120       double GetDataPointLowerBoundary(unsigned int index)
00121          { return fDataPointLowerBoundaries -> GetValue(index); };
00122 
00123       /**
00124        * @param index The index of the variable.
00125        * @return The upper boundary of possible data values for a particular variable. */
00126       double GetDataPointUpperBoundary(unsigned int index)
00127          { return fDataPointUpperBoundaries -> GetValue(index); };
00128 
00129       /*
00130        * Checks if the boundaries have been defined
00131        * @return true, if the boundaries have been set, false otherwise */
00132       bool GetFlagBoundaries();
00133 
00134       /**
00135        * @return The number of data points in the current data set. */
00136       int GetNDataPoints();
00137 
00138       /**
00139        * @param index The index of the data point.
00140        * @return The data point in the current data set at index */
00141       BCDataPoint * GetDataPoint(unsigned int index);
00142 
00143       /**
00144        * @return The minimum number of data points. */
00145       unsigned int GetNDataPointsMinimum()
00146          { return fNDataPointsMinimum; };
00147 
00148       /**
00149        * @return The maximum number of data points. */
00150       unsigned int GetNDataPointsMaximum()
00151          { return fNDataPointsMaximum; };
00152 
00153       /**
00154        * @return The number of parameters of the model. */
00155       unsigned int GetNParameters()
00156          { return fParameterSet ? fParameterSet -> size() : 0; };
00157 
00158       /**
00159        * @param index The index of the parameter in the parameter set.
00160        * @return The parameter. */
00161       BCParameter * GetParameter(int index);
00162 
00163       /**
00164        * @param name The name of the parameter in the parameter set.
00165        * @return The parameter. */
00166       BCParameter * GetParameter(const char * name);
00167 
00168       /**
00169        * @return parameter set */
00170       BCParameterSet * GetParameterSet()
00171          { return fParameterSet; };
00172 
00173       /**
00174        * Returns the value of a parameter (defined by index) at
00175        * the global mode of the posterior pdf.
00176        * @param index index of the parameter.
00177        * @return best fit value of the parameter or -1e+111 on error or center of the range if mode finding not yer run */
00178       double GetBestFitParameter(unsigned int index);
00179 
00180       /**
00181        * Returns the error on the value of a parameter (defined by index) at
00182        * the global mode of the posterior pdf.
00183        * @param index index of the parameter.
00184        * @return error on the best fit value of the parameter or -1 if undefined */
00185       double GetBestFitParameterError(unsigned int index);
00186 
00187       /**
00188        * Returns the set of values of the parameters at the global mode of
00189        * the posterior pdf.
00190        * @return The best fit parameters */
00191       std::vector <double> GetBestFitParameters()
00192          { return fBestFitParameters; };
00193       
00194       std::vector <double> GetBestFitParameterErrors() 
00195          { return fBestFitParameterErrors; }; 
00196 
00197       /**
00198        * Returns the value of a particular parameter (defined by index) at
00199        * the modes of the marginalized posterior pdfs.
00200        * @param index index of the parameter.
00201        * @return best fit parameter or -1e+111 on error or center of the range if marginalization not yet run */
00202       double GetBestFitParameterMarginalized(unsigned int index);
00203 
00204       /**
00205        * Returns the set of values of the parameters at the modes of the
00206        * marginalized posterior pdfs.
00207        * @return best fit parameters */
00208       std::vector <double> GetBestFitParametersMarginalized()
00209          { return fBestFitParametersMarginalized; };                                                          
00210 
00211       /**
00212        * @return The 2-d histogram of the error band. */
00213       TH2D * GetErrorBandXY()
00214          { return fErrorBandXY; };
00215 
00216       TH2D * GetErrorBandXY_yellow(double level=.68, int nsmooth=0);
00217 
00218       /**
00219        * Returns a vector of y-values at a certain probability level.
00220        * @param level The level of probability
00221        * @return vector of y-values */
00222       std::vector <double> GetErrorBand(double level);
00223 
00224       TGraph * GetErrorBandGraph(double level1, double level2);
00225 
00226       TGraph * GetFitFunctionGraph(std::vector <double> parameters);
00227 
00228       TGraph * GetFitFunctionGraph()
00229          { return this -> GetFitFunctionGraph(this -> GetBestFitParameters()); };
00230 
00231       TGraph * GetFitFunctionGraph(std::vector <double> parameters, double xmin, double xmax, int n=1000);
00232 
00233       bool GetFixedDataAxis(unsigned int index);
00234 
00235       /* @} */
00236 
00237       /** \name Member functions (set) */
00238       /* @{ */
00239 
00240       /**
00241        * Sets the name of the model.
00242        * @param name Name of the model */
00243       void SetName(const char * name)
00244          { fName = name; };
00245 
00246       /**
00247        * Sets the index of the model within the BCModelManager.
00248        * @param index The index of the model */
00249       void SetIndex(int index)
00250          { fIndex = index; };
00251 
00252       /**
00253        * Set all parameters of the model using a BCParameterSet container.
00254        * @par pointer to parameter set */
00255       void SetParameterSet( BCParameterSet * parset )
00256          { fParameterSet = parset; };
00257 
00258       /** 
00259        * Set the range of a parameter
00260        * @param index The parameter index
00261        * @param parmin The parameter minimum
00262        * @param parmax The parameter maximum
00263        * @return An error code. */
00264       int SetParameterRange(int index, double parmin, double parmax);
00265 
00266       /**
00267        * Sets the a priori probability for a model.
00268        * @param model The model
00269        * @param probability The a priori probability */
00270       void SetModelAPrioriProbability(double probability)
00271          { fModelAPriori = probability; };
00272 
00273       /**
00274        * Sets the a posteriori probability for a model.
00275        * @param model The model
00276        * @param probability The a posteriori probability */
00277       void SetModelAPosterioriProbability(double probability)
00278          { fModelAPosteriori = probability; };
00279 
00280       /**
00281        * Sets the normalization of the likelihood.
00282        * The normalization is the integral of likelihood over all parameters.
00283        * @param norm The normalization of the likelihood */
00284       void SetNormalization(double norm)
00285          { fNormalization = norm; };
00286 
00287       /**
00288        * Sets the data set.
00289        * @param dataset A data set */
00290       void SetDataSet(BCDataSet* dataset)
00291          { fDataSet = dataset; fNormalization = -1.0; };
00292 
00293       /**
00294        * Sets a single data point as data set.
00295        * @param datapoint A data point */
00296       void SetSingleDataPoint(BCDataPoint * datapoint);
00297 
00298       void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00299 
00300       /**
00301        * Sets the minimum number of data points. */
00302       void SetNDataPointsMinimum(unsigned int minimum)
00303          { fNDataPointsMinimum = minimum; };
00304 
00305       /**
00306        * Sets the maximum number of data points. */
00307       void SetNDataPointsMaximum(unsigned int maximum)
00308          { fNDataPointsMaximum = maximum; };
00309 
00310       void SetDataBoundaries(unsigned int index, double lowerboundary, double upperboundary, bool fixed=false);
00311 
00312       /**
00313        * Sets the error band flag to continuous function */
00314       void SetErrorBandContinuous(bool flag);
00315 
00316       /**
00317        * Set the number of bins for the marginalized distribution of a parameter.
00318        * @param parname The name of the parameter in the parameter set
00319        * @param nbins   Number of bins (default = 100) */
00320       void SetNbins(const char * parname, int nbins);
00321 
00322       /**
00323        * Set prior for a parameter. 
00324        * @param index The parameter index
00325        * @param f A pointer to a function describing the prior
00326        * @return An error code.
00327        */ 
00328       int SetPrior(int index, TF1* f); 
00329 
00330       /**
00331        * Set prior for a parameter. 
00332        * @param name The parameter name
00333        * @param f A pointer to a function describing the prior
00334        * @return An error code.
00335        */ 
00336       int SetPrior(const char* name, TF1* f); 
00337 
00338       /**
00339        * Set Gaussian prior for a parameter. 
00340        * @param index The parameter index
00341        * @param mean The mean of the Gaussian
00342        * @param sigma The sigma of the Gaussian
00343        * @return An error code.
00344        */ 
00345       int SetPriorGauss(int index, double mean, double sigma); 
00346 
00347       /**
00348        * Set Gaussian prior for a parameter. 
00349        * @param name The parameter name
00350        * @param mean The mean of the Gaussian
00351        * @param sigma The sigma of the Gaussian
00352        * @return An error code.
00353        */ 
00354       int SetPriorGauss(const char* name, double mean, double sigma); 
00355 
00356       /**
00357        * Set Gaussian prior for a parameter with two different widths.
00358        * @param index The parameter index
00359        * @param mean The mean of the Gaussian
00360        * @param sigmadown The sigma (down) of the Gaussian
00361        * @param sigmaup The sigma (up)of the Gaussian
00362        * @return An error code.
00363        */ 
00364       int SetPriorGauss(int index, double mean, double sigmadown, double sigmaup);
00365 
00366       /**
00367        * Set Gaussian prior for a parameter with two different widths.
00368        * @param name The parameter name
00369        * @param mean The mean of the Gaussian
00370        * @param sigmadown The sigma (down) of the Gaussian
00371        * @param sigmaup The sigma (up)of the Gaussian
00372        * @return An error code.
00373        */ 
00374       int SetPriorGauss(const char* name, double mean, double sigmadown, double sigmaup);
00375 
00376       /**
00377        * Set constant prior for this parameter
00378        * @param index the index of the parameter
00379        * @return An error code
00380        */
00381       int SetPriorConstant(int index);
00382 
00383       /**
00384        * Set constant prior for this parameter
00385        * @param name the name of the parameter
00386        * @return An error code
00387        */
00388       int SetPriorConstant(const char* name);
00389 
00390       /**
00391        * Enable caching the constant value of the prior, so LogAPrioriProbability
00392        * is called only once. Note that the prior for ALL parameters is
00393        * assumed to be constant. The value is computed from
00394        * the parameter ranges, so make sure these are defined before this method is
00395        * called.
00396        * @return An error code
00397        */
00398       int SetPriorConstantAll();
00399 
00400       /* @} */
00401 
00402       /** \name Member functions (miscellaneous methods) */
00403       /* @{ */
00404 
00405       /**
00406        * Adds a parameter to the parameter set
00407        * @param name The name of the parameter
00408        * @param lowerlimit The lower limit of the parameter values
00409        * @param upperlimit The upper limit of the parameter values
00410        * @see AddParameter(BCParameter* parameter); */
00411       int AddParameter(const char * name, double lowerlimit, double upperlimit);
00412 
00413       /**
00414        * Adds a parameter to the model.
00415        * @param parameter A model parameter
00416        * @see AddParameter(const char * name, double lowerlimit, double upperlimit); */
00417       int AddParameter(BCParameter* parameter);
00418 
00419       /**
00420        * Returns the prior probability.
00421        * @param parameters A set of parameter values
00422        * @return The prior probability p(parameters)
00423        * @see GetPrior(std::vector <double> parameters) */
00424       double APrioriProbability(std::vector <double> parameters)
00425          { return exp( this->LogAPrioriProbability(parameters) ); };
00426 
00427       /**
00428        * Returns natural logarithm of the prior probability.
00429        * Method needs to be overloaded by the user.
00430        * @param parameters A set of parameter values
00431        * @return The prior probability p(parameters)
00432        * @see GetPrior(std::vector <double> parameters) */
00433       virtual double LogAPrioriProbability(std::vector <double> parameters); 
00434 
00435       /**
00436        * Returns the likelihood
00437        * @param parameters A set of parameter values
00438        * @return The likelihood */
00439       double Likelihood(std::vector <double> parameter)
00440          { return exp( this->LogLikelihood(parameter) ); };
00441 
00442       /**
00443        * Calculates natural logarithm of the likelihood.
00444        * Method needs to be overloaded by the user.
00445        * @param parameters A set of parameter values
00446        * @return Natural logarithm of the likelihood */
00447       virtual double LogLikelihood(std::vector <double> parameter);
00448 
00449       /**
00450        * Returns the likelihood times prior probability given a set of parameter values
00451        * @param parameters A set of parameter values
00452        * @return The likelihood times prior probability */
00453       double ProbabilityNN(std::vector <double> parameter)
00454          { return exp( this->LogProbabilityNN(parameter) ); };
00455 
00456       /**
00457        * Returns the natural logarithm of likelihood times prior probability given
00458        * a set of parameter values
00459        * @param parameters A set of parameter values
00460        * @return The likelihood times prior probability */
00461       double LogProbabilityNN(std::vector <double> parameter);
00462 
00463       /**
00464        * Returns the a posteriori probability given a set of parameter values
00465        * @param parameters A set of parameter values
00466        * @return The a posteriori probability */
00467       double Probability(std::vector <double> parameter)
00468          { return exp( this->LogProbability(parameter) ); };
00469 
00470       /**
00471        * Returns natural logarithm of the  a posteriori probability given a set of parameter values
00472        * @param parameters A set of parameter values
00473        * @return The a posteriori probability */
00474       double LogProbability(std::vector <double> parameter);
00475 
00476       /**
00477        * Returns a conditional probability.
00478        * Method needs to be overloaded by the user.
00479        * @param datapoint A data point
00480        * @param parameters A set of parameter values
00481        * @return The conditional probability p(datapoint|parameters)
00482        * @see GetConditionalEntry(BCDataPoint* datapoint, std::vector <double> parameters) */
00483       double ConditionalProbabilityEntry(BCDataPoint * datapoint, std::vector <double> parameters)
00484          { return exp( this->LogConditionalProbabilityEntry(datapoint, parameters) ); };
00485 
00486       /**
00487        * Returns a natural logarithm of conditional probability.
00488        * Method needs to be overloaded by the user.
00489        * @param datapoint A data point
00490        * @param parameters A set of parameter values
00491        * @return The conditional probability p(datapoint|parameters)
00492        * @see GetConditionalEntry(BCDataPoint* datapoint, std::vector <double> parameters) */
00493       virtual double LogConditionalProbabilityEntry(BCDataPoint * /*datapoint*/, std::vector <double> /*parameters*/)
00494          { flag_ConditionalProbabilityEntry = false; return 0.; };
00495 
00496       /**
00497        * Sampling function used for importance sampling.
00498        * Method needs to be overloaded by the user.
00499        * @param parameters A set of parameter values
00500        * @return The probability density at the parameter values */
00501       virtual double SamplingFunction(std::vector <double> parameters);
00502 
00503       /**
00504        * Overloaded function to evaluate integral. */
00505       double Eval(std::vector <double> parameters)
00506          { return exp( this->LogEval(parameters) ); };
00507 
00508       /**
00509        * Overloaded function to evaluate integral. */
00510       double LogEval(std::vector <double> parameters);
00511 
00512       /**
00513        * Overloaded function to evaluate integral. */
00514       double EvalSampling(std::vector <double> parameters);
00515 
00516       /**
00517        * Integrates over the un-normalized probability and updates fNormalization. */
00518       double Normalize();
00519 
00520       /**
00521        * Checks if a set of parameters values is within the given range.
00522        * @param parameters A set of parameter values
00523        * @return Error code (0: OK, -1 length of parameters not correct, -2 values not within range)
00524        */
00525       int CheckParameters(std::vector <double> parameters);
00526 
00527       /**
00528        * Do the mode finding using a method set via SetOptimizationMethod.
00529        * Default is Minuit. The mode can be extracted using the GetBestFitParameters() method.
00530        *
00531        * A starting point for the mode finding can be specified for Minuit. If not
00532        * specified, Minuit default will be used (center of the parameter space).
00533        *
00534        * If running mode finding after the MCMC it is a good idea to specify the
00535        * mode obtained from MCMC as a starting point for the Minuit minimization.
00536        * MCMC will find the location of the global mode and Minuit will
00537        * converge to the mode precisely. The commands are:
00538          <pre>
00539          model -> MarginalizeAll();
00540          model -> FindMode( model -> GetBestFitParameters() );
00541          </pre>
00542        * @start startinf point of Minuit minimization
00543        * */
00544       void FindMode(std::vector<double> start = std::vector<double>(0));
00545 
00546       /**
00547        * Does the mode finding using Minuit. If starting point is not specified,
00548        * finding will start from the center of the parameter space.
00549        * @param start point in parameter space from which the mode finding is started.
00550        * @param printlevel The print level. */
00551       void FindModeMinuit(std::vector<double> start = std::vector<double>(0), int printlevel = 1);
00552 
00553       /**
00554        * Write mode into file */
00555       void WriteMode(const char * file);
00556 
00557       /**
00558        * Read mode from file created by WriteMode() call */
00559       int ReadMode(const char * file);
00560 
00561       /**
00562        * Read */
00563       int ReadMarginalizedFromFile(const char * file);
00564 
00565       /**
00566        * Read */
00567       int ReadErrorBandFromFile(const char * file);
00568 
00569       /**
00570        * Marginalize all probabilities wrt. single parameters and all combinations
00571        * of two parameters. The individual distributions can be retrieved using
00572        * the GetMarginalized method.
00573        * @return Total number of marginalized distributions */
00574       int MarginalizeAll();
00575 
00576       /**
00577        * If MarginalizeAll method was used, the individual marginalized distributions
00578        * with respect to one parameter can be retrieved using this method.
00579        * @param parameter Model parameter
00580        * @return 1D marginalized probability */
00581       BCH1D * GetMarginalized(BCParameter * parameter);
00582 
00583       BCH1D * GetMarginalized(const char * name)
00584          { return this -> GetMarginalized(this -> GetParameter(name)); };
00585 
00586       /**
00587        * If MarginalizeAll method was used, the individual marginalized distributions
00588        * with respect to otwo parameters can be retrieved using this method.
00589        * @param parameter1 First parameter
00590        * @param parameter2 Second parameter
00591        * @return 2D marginalized probability */
00592       BCH2D * GetMarginalized(BCParameter * parameter1, BCParameter * parameter2);
00593 
00594       BCH2D * GetMarginalized(const char * name1, const char * name2)
00595          { return this -> GetMarginalized(this -> GetParameter(name1), this -> GetParameter(name2)); };
00596 
00597       /**
00598        *   */
00599       int PrintAllMarginalized1D(const char * filebase);
00600       int PrintAllMarginalized2D(const char * filebase);
00601       int PrintAllMarginalized(const char * file, unsigned int hdiv=1, unsigned int ndiv=1);
00602 
00603       /**
00604        * Constrains a data point
00605        * @param x A vector of double */
00606       virtual void CorrelateDataPointValues(std::vector<double> &x);
00607 
00608       /**
00609        * Calculate p-value from Chi2 distribution for Gaussian problems
00610        * @param par Parameter set for the calculation of the likelihood
00611        * @param sigma_index Index of the sigma/uncertainty for the data points
00612        *        (for data in format "x y erry" the index would be 2) */
00613       double GetPvalueFromChi2(std::vector<double> par, int sigma_index);
00614 
00615       /**
00616        * Calculate p-value from asymptotic Chi2 distribution for arbitrary problems
00617        * using the definition (3) from
00618        * Johnson, V.E. A Bayesian chi2 Test for Goodness-of-Fit. The Annals of Statistics 32, 2361-2384(2004).
00619        *
00620        * @param par Parameter set for the calculation of the likelihood */
00621       double GetPvalueFromChi2Johnson(std::vector<double> par);
00622 
00623       /**
00624        * Calculate p-value from Kolmogorov-Smirnov test statistic
00625        * for 1D - datasets.
00626        *
00627        * @param par Parameter set for the calculation of the likelihood
00628        * @param index Index of the data point in the BCDataSet
00629        *        (for data in format "x y erry" the index would be 1) */
00630       double GetPvalueFromKolmogorov(const std::vector<double>& par, int index);
00631 
00632 
00633       /**
00634        * Calculate  Chi2  (also called R^{B}) for arbitrary problems with binned data
00635        * using the definition (3) from
00636        * Johnson, V.E. A Bayesian chi2 Test for Goodness-of-Fit. The Annals of Statistics 32, 2361-2384(2004).
00637        *
00638        * @param par Parameter set for the calculation of the likelihood
00639        * @param nBins how many bins to use for the data, for negative an adapted rule \
00640        * of thumb by  Wald(1942) is used, with at least three bins*/
00641       double GetChi2Johnson(std::vector<double> par, const int nBins=-1);
00642 
00643       /**
00644        * Calculate the A-value, a summary statistic. It computes the frequency
00645        * that a Chi2 value determined from the data by Johnson's binning prescription is
00646        * larger than a value sampled from the reference chi2 distribution. They out
00647        * from one chain is used. A=1/2 provides
00648        * no evidence against the null hypothesis. Compare
00649        * Johnson, V.E. A Bayesian chi2 Test for Goodness-of-Fit. The Annals of Statistics 32, 2361-2384(2004).
00650        *
00651        * @param par tree contains the samples of posterior of the parameters
00652        * @param par histogram filled by function with distribution of p values*/
00653       double GetAvalueFromChi2Johnson(TTree* tree, TH1D* distribution=0);
00654 
00655       double GetPvalueFromChi2NDoF(std::vector<double> par, int sigma_index);
00656 
00657       BCH1D * CalculatePValue(std::vector<double> par, bool flag_histogram=false);
00658 
00659       /*
00660        * @return The p-value */
00661       double GetPValue()
00662          { return fPValue; };
00663 
00664       double GetPValueNDoF()
00665          { return fPValueNDoF; };
00666 
00667       double GetChi2NDoF()
00668          { return fChi2NDoF; };
00669 
00670       /**
00671        * For a Gaussian problem, calculate the chi2 of the longest run of consecutive
00672        * values above/below the expected values
00673        * @param dataIndex component of datapoint with the observed value
00674        * @param sigmaIndex component of datapoint with uncertainty */
00675       std::vector<double> GetChi2Runs(int dataIndex, int sigmaIndex);
00676 
00677       /*
00678        * Set maximum number of iterations in the MCMC pre-run of the p-value
00679        * evaluation using MCMC */
00680       void SetGoFNIterationsMax(int n)
00681          { fGoFNIterationsMax=n; };
00682 
00683       /*
00684        * Set number of iterations in the MCMC normal run of the p-value
00685        * evaluation using MCMC */
00686       void SetGoFNIterationsRun(int n)
00687          { fGoFNIterationsRun=n; };
00688 
00689       /*
00690        * Set number of chains in the MCMC of the p-value
00691        * evaluation using MCMC */
00692       void SetGoFNChains(int n)
00693          { fGoFNChains=n; };
00694 
00695       /**
00696        * Calculates the matrix element of the Hessian matrix
00697        * @param parameter1 The parameter for the first derivative
00698        * @param parameter2 The parameter for the first derivative
00699        * @return The matrix element of the Hessian matrix */
00700       double HessianMatrixElement(BCParameter * parameter1, BCParameter * parameter2, std::vector<double> point);
00701 
00702       /**
00703        * Prints a summary on the screen. */
00704       void PrintSummary();
00705 
00706       /**
00707        * Prints a summary of the Markov Chain Monte Carlo to a file. */
00708       void PrintResults(const char * file);
00709 
00710       /**
00711        * Prints a short summary of the fit results on the screen. */
00712       void PrintShortFitSummary(int chi2flag=0);
00713 
00714       /**
00715        * Prints matrix elements of the Hessian matrix
00716        * @param parameters The parameter values at which point to evaluate the matrix */
00717       void PrintHessianMatrix(std::vector<double> parameters);
00718 
00719       void FixDataAxis(unsigned int index, bool fixed);
00720 
00721 
00722       /**
00723        * 1dim cumulative distribution function of the probability
00724        * to get the data f(x_i|param) for a single measurement, assumed to
00725        * be of identical functional form for all measurements
00726        * @param parameters The parameter values at which point to compute the cdf
00727        * @param index The data point index starting at 0,1...N-1
00728        * @param lower only needed for discrete distributions!
00729        * Return the CDF for the count one less than actually observed, e.g.
00730        * in Poisson process, if 3 actually observed, then CDF(2) is returned */
00731       virtual double CDF(const std::vector<double>& /*parameters*/,  int /*index*/, bool /*lower=false*/)
00732       {return 0.0;}
00733 
00734 
00735       /** 
00736        * Reset all results. 
00737        * @return An error code. */ 
00738       int ResetResults();
00739 
00740    /* @} */
00741 
00742    protected:
00743 
00744       /**
00745        * Index of the model. */
00746       int fIndex;
00747 
00748       /**
00749        * Name of the model. */
00750       std::string fName;
00751 
00752       /**
00753        * The model prior probability. */
00754       double fModelAPriori;
00755 
00756       /**
00757        * The model a posteriori probability. */
00758       double fModelAPosteriori;
00759 
00760       /**
00761        * A model parameter container. */
00762       BCParameterSet * fParameterSet;
00763 
00764       /**
00765        * A data set */
00766       BCDataSet * fDataSet;
00767 
00768       /**
00769        * Minimum number of data points */
00770       unsigned int fNDataPointsMinimum;
00771 
00772       /**
00773        * Maximum number of data points */
00774       unsigned int fNDataPointsMaximum;
00775 
00776       /**
00777        * A flag for overloading ConditionalProbabilityEntry */
00778       bool flag_ConditionalProbabilityEntry;
00779 
00780       /**
00781        * The p-value */
00782       double fPValue;
00783 
00784       double fChi2NDoF;
00785       double fPValueNDoF;
00786 
00787       /**
00788       * true for a discrete probability, false for continuous pdf  */
00789       bool flag_discrete;
00790 
00791       /*
00792        * Maximum number of iterations in the MCMC pre-run of the p-value
00793        * evaluation using MCMC */
00794       int fGoFNIterationsMax;
00795 
00796       /*
00797        * Number of iterations in the MCMC normal run of the p-value
00798        * evaluation using MCMC */
00799       int fGoFNIterationsRun;
00800 
00801       /*
00802        * Number of chains in the MCMC of the p-value
00803        * evaluation using MCMC */
00804       int fGoFNChains;
00805 
00806       /*
00807        * A vector of prior functions. */ 
00808       std::vector<TF1*> fPriorContainer;
00809 
00810       /**
00811        * Flag to indicate that all parameters have constant prior.
00812        */
00813       bool fPriorConstantAll;
00814 
00815       /**
00816        * The value of the product of constant priors of
00817        * individual parameters.
00818        */
00819       double fPriorConstantValue;
00820 
00821       /**
00822        * List the parameters whose prior is constant
00823        */
00824       std::vector<bool> fPriorContainerConstant;
00825 
00826    private:
00827 
00828       /**
00829        * Converts a vector of doubles into a BCDataPoint */
00830       BCDataPoint * VectorToDataPoint(std::vector<double> data);
00831 
00832       /**
00833        * Compares to strings */
00834       int CompareStrings(const char * string1, const char * string2);
00835 
00836       /**
00837        * The Likelihood normalization. */
00838       double fNormalization;
00839 
00840       /**
00841        * rule of thumb for good number of bins (Wald1942, Johnson2004) to group observations
00842        * updated so minimum is three bins (for 1-5 observations)!
00843        * @param */
00844 
00845       int NumberBins()
00846          { return (int)(exp(0.4 * log(this -> GetNDataPoints())) + 2); }
00847 
00848 };
00849 
00850 // ---------------------------------------------------------
00851 
00852 typedef std::vector<BCModel*> BCModelContainer;
00853 
00854 // ---------------------------------------------------------
00855 
00856 #endif

Generated on Mon Aug 30 2010 22:14:54 for Bayesian Analysis Toolkit by  doxygen 1.7.1