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

BCModelManager.h

Go to the documentation of this file.
00001 #ifndef __BCMODELMANAGER__H
00002 #define __BCMODELMANAGER__H
00003 
00004 /*!
00005  * \class BCModelManager
00006  * \brief A class representing a set of BCModels.
00007  * \author Daniel Kollar
00008  * \author Kevin Kröninger
00009  * \version 1.0
00010  * \date 08.2008
00011  * \detail This class represents a manager for BCModels. It handles
00012  * common data sets and performs operations on BCModels
00013  * simultaneously. Model comparsion in terms of a posteriori
00014  * probabilities is only possible with this class.
00015  */
00016 
00017 /*
00018  * Copyright (C) 2008-2010, Daniel Kollar and Kevin Kroeninger.
00019  * All rights reserved.
00020  *
00021  * For the licensing terms see doc/COPYING.
00022  */
00023 
00024 // ---------------------------------------------------------
00025 
00026 #include "BAT/BCModel.h"
00027 #include "BAT/BCDataSet.h"
00028 
00029 // BAT classes
00030 class BCDataPoint;
00031 
00032 // ---------------------------------------------------------
00033 
00034 class BCModelManager
00035 {
00036    public:
00037 
00038       /** \name Constructors and destructors */
00039       /* @{ */
00040 
00041       /**
00042        * The default constructor. */
00043       BCModelManager();
00044 
00045       /**
00046        * The default copy constructor. */
00047       BCModelManager(const BCModelManager & modelmanager);
00048 
00049       /**
00050        * The default destructor. */
00051       virtual ~BCModelManager();
00052 
00053       /* @} */
00054 
00055       /** \name Assignment operators */
00056       /* @{ */
00057 
00058       /**
00059        * The defaut assignment operator */
00060       BCModelManager & operator = (const BCModelManager & modelmanager);
00061 
00062       /* @} */
00063 
00064       /** \name Member functions (get) */
00065       /* @{ */
00066 
00067       /**
00068        * @return The number of models. */
00069       unsigned int GetNModels()
00070          { return fModelContainer -> size(); };
00071 
00072       /**
00073        * Returns the BCModel at a certain index of this BCModelManager.
00074        * @param index The index of the model in the BCModelManager.
00075        * @return The BCModel at the index. */
00076       BCModel * GetModel(int index)
00077          { return fModelContainer -> at(index); };
00078 
00079       /**
00080        * Returns the number of entries in the common data set.
00081        * @return The number of entries. */
00082       int GetNDataPoints()
00083          { return (fDataSet) ? fDataSet -> GetNDataPoints() : 0; };
00084 
00085       /**
00086        * Returns a data point of the common data set at an index.
00087        * @param index The index of the data point in the data set.
00088        * @return The data point. */
00089       BCDataPoint * GetDataPoint(int index)
00090          { return fDataSet -> GetDataPoint(index); };
00091 
00092       /**
00093        * Returns the common data set.
00094        * @return The data set. */
00095       BCDataSet * GetDataSet()
00096          { return fDataSet; };
00097 
00098       /* @} */
00099 
00100       /** \name Member functions (set) */
00101       /* @{ */
00102 
00103       /**
00104        * Sets the data set common to all BCModels in this
00105        * BCModelManager.
00106        * @param dataset A data set */
00107       void SetDataSet(BCDataSet * dataset);
00108 
00109       /**
00110        * Sets a single data point as a common data set.
00111        * @param datapoint A data point
00112        * @see SetSingleDataPoint(BCDataSet * dataset, int index)
00113        * @see SetDataSet(BCDataSet * dataset) */
00114       void SetSingleDataPoint(BCDataPoint * datapoint);
00115 
00116       /**
00117        * Sets a single data point as a common data set.
00118        * @param dataset A data set.
00119        * @param index The index of the data point in the data set specified.
00120        * @see SetSingleDataPoint(BCDataPoint * datapoint)
00121        * @see SetDataSet(BCDataSet * dataset) */
00122       void SetSingleDataPoint(BCDataSet * dataset, unsigned int index);
00123 
00124       // DEBUG DELETE?
00125       /**
00126        * Sets the maximum number of iterations for the Monte Carlo
00127        * integration for all BCModels in this BCModelManager.
00128        * @param niterations */
00129       // void SetNIterationsMax(int niterations);
00130 
00131       /**
00132        * @param method The marginalization method */
00133       void SetMarginalizationMethod(BCIntegrate::BCMarginalizationMethod method);
00134 
00135       /**
00136        * @param method The integration method */
00137       void SetIntegrationMethod(BCIntegrate::BCIntegrationMethod method);
00138 
00139       /**
00140        * @param method The mode finding method */
00141       void SetOptimizationMethod(BCIntegrate::BCOptimizationMethod method);
00142 
00143       /**
00144        * @param niterations Number of iterations per dimension for Monte
00145        * Carlo integration. */
00146       void SetNiterationsPerDimension(unsigned int niterations);
00147 
00148       /**
00149        * @param n Number of samples per 2D bin per variable in the
00150        * Metropolis marginalization.  Default is 100. */
00151       void SetNSamplesPer2DBin(unsigned int n);
00152 
00153       /**
00154        * @param relprecision The relative precision envisioned for Monte
00155        * Carlo integration */
00156       void SetRelativePrecision(double relprecision);
00157 
00158       /**
00159        * @param n Number of bins per dimension for the marginalized
00160        * distributions.  Default is 100. Minimum number allowed is 2. */
00161       void SetNbins(unsigned int n);
00162 
00163       /**
00164        * Turn on or off the filling of the error band during the MCMC run
00165        * for all models added to the model manager before calling this method.
00166        * @param flag set to true for turning on the filling */
00167       void SetFillErrorBand(bool flag = true);
00168 
00169       /**
00170        * Turn off the filling of the error band during the MCMC run
00171        * for all models added to the model manager before calling this method. */
00172       void UnetFillErrorBand()
00173          { SetFillErrorBand(false); };
00174 
00175       /**
00176        * Sets index of the x values in function fits.
00177        * @param index Index of the x values */
00178       void SetFitFunctionIndexX(int index);
00179 
00180       /**
00181        * Sets index of the y values in function fits.
00182        * @param index Index of the y values */
00183       void SetFitFunctionIndexY(int index);
00184 
00185       void SetFitFunctionIndices(int indexx, int indexy);
00186 
00187       /**
00188        * Sets the data point containing the lower boundaries of possible
00189        * data values */
00190       void SetDataPointLowerBoundaries(BCDataPoint * datasetlowerboundaries);
00191 
00192       /**
00193        * Sets the data point containing the upper boundaries of possible
00194        * data values */
00195       void SetDataPointUpperBoundaries(BCDataPoint* datasetupperboundaries);
00196 
00197       /**
00198        * Sets the lower boundary of possible data values for a particular
00199        * variable */
00200       void SetDataPointLowerBoundary(int index, double lowerboundary);
00201 
00202       /**
00203        * Sets the upper boundary of possible data values for a particular
00204        * variable */
00205       void SetDataPointUpperBoundary(int index, double upperboundary);
00206 
00207       /**
00208        * Set the lower and upper boundaries for possible data values for a
00209        * particular variable */
00210       void SetDataBoundaries(int index, double lowerboundary, double upperboundary);
00211 
00212       /*
00213        * Fixes an axis */
00214       void FixDataAxis(int index, bool fixed);
00215 
00216       /*
00217        * Sets the number of Markov chains */
00218       void SetNChains(unsigned int n);
00219 
00220       /* @} */
00221 
00222       /** \name Member functions (miscellaneous methods) */
00223       /* @{ */
00224 
00225       /**
00226        * Adds a model to the container
00227        * @param model The model
00228        * @param probability The a priori probability
00229        * @see AddModel(BCModel * model)
00230        * @see SetModelPrior(BCModel * model, double probability) */
00231       void AddModel(BCModel * model, double probability=0.);
00232 
00233       /**
00234        * Adds a data point to the data container.
00235        * @param datapoint The data point */
00236       void AddDataPoint(BCDataPoint * datapoint)
00237          { fDataSet -> AddDataPoint(datapoint); };
00238 
00239       /**
00240        * Reads data from a file. For a description see the following
00241        * member functions. */
00242       int ReadDataFromFile(const char * filename, const char * treename, const char * branchnames)
00243       { return this ->  ReadDataFromFileTree(filename, treename, branchnames); };
00244       
00245       int ReadDataFromFile(const char * filename, int nvariables)
00246       { return this -> ReadDataFromFileTxt(filename, nvariables); };
00247       
00248       /**
00249        * Reads tree data from a ROOT file.
00250        * Opens a ROOT file and gets a ROOT tree. It creates data set
00251        * containing the values read from the file.
00252        * @param filename The filename of the ROOT file
00253        * @param treename The name of the ROOT tree
00254        * @param branchnames A vector of the names of the branches
00255        * @see ReadDataFromFileHist(char * filename, char * histname, const char*  branchnames);
00256        * @see ReadDataFromFileTxt(char * filename, int nbranches); */
00257       int ReadDataFromFileTree(const char * filename, const char * treename, const char * branchnames);
00258 
00259       /**
00260        * Reads data from a txt file.
00261        * Opens a txt file and creates data set
00262        * containing the values read from the file.
00263        * @param filename The filename of the ROOT file
00264        * @param nbranches The number of variables
00265        * @see ReadDataFromFileTree(char * filename, char * treename, std::vector<char*> branchnames)
00266        * @see ReadDataFromFileHist(char * filename, char * histname, const char * branchnames); */
00267       int ReadDataFromFileTxt(const char * filename, int nbranches);
00268 
00269       /**
00270        * Calculates the normalization of the likelihood for each model in
00271        * the container. */
00272       void Normalize();
00273 
00274       /**
00275        * Calculate Bayes factor for two models.
00276        * @param imodel1 index of model 1 (numerator)
00277        * @param imodel2 index of model 2 (denominator)
00278        * @return Bayes factor or -1. on error */
00279       double BayesFactor(const unsigned int imodel1, const unsigned int imodel2);
00280 
00281       /**
00282        * Does the mode finding */
00283       void FindMode();
00284 
00285       /**
00286        * Marginalize all probabilities wrt. single parameters and all
00287        * combinations of two parameters for all models. */
00288       void MarginalizeAll();
00289 
00290       /*
00291        * Flag for writing Markov chain to file */
00292       void WriteMarkovChain(bool flag);
00293 
00294       /**
00295        * Resets the data set */
00296       void ResetDataSet()
00297          { fDataSet -> Reset(); };
00298 
00299       /**
00300        * Prints a summary of model comparison into a file.
00301        * If filename is omitted the summary will be printed onto the screen
00302        * @param filename name of the file to write into. */
00303       void PrintModelComparisonSummary(const char * filename=0);
00304 
00305       /**
00306        * Prints a summary into a file. If filename is omitted the summary
00307        * will be printed onto the screen.
00308        * This method is obsolete. Use PrintResults() instead.
00309        * @param filename name of the file to write into. */
00310       void PrintSummary(const char * filename=0);
00311 
00312       /*
00313        * Prints summaries of all files */
00314       void PrintResults();
00315 
00316       /*
00317        * Calculates the p-value for all models. */
00318       void CalculatePValue(bool flag_histogram=false);
00319 
00320       /* @} */
00321 
00322    private:
00323 
00324       /*
00325        * Copies this BCModelManager into another one */
00326       void Copy(BCModelManager & modelmanager) const;
00327 
00328       /**
00329        * The BCModelContainer containing all BCModels. */
00330       BCModelContainer * fModelContainer;
00331 
00332       /**
00333        * The data set common to all models. */
00334       BCDataSet * fDataSet;
00335 
00336 };
00337 
00338 // ---------------------------------------------------------
00339 
00340 #endif

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