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

BCIntegrate.h

Go to the documentation of this file.
00001 #ifndef __BCINTEGRATE__H
00002 #define __BCINTEGRATE__H
00003 
00023 // ---------------------------------------------------------
00024 
00025 #include <vector>
00026 
00027 #include <math.h>
00028 
00029 #include "BCEngineMCMC.h"
00030 #include "BCParameter.h"
00031 #include "BCDataPoint.h"
00032 
00033 // ROOT classes
00034 class TH1D;
00035 class TH2D;
00036 class TRandom3;
00037 class TMinuit;
00038 class TTree;
00039 
00040 
00041 #define BC_DEBUG 0
00042 
00043 // ---------------------------------------------------------
00044 
00045 class BCIntegrate : public BCEngineMCMC
00046 {
00047 
00048  public:
00049 
00055       enum BCIntegrationMethod { kIntMonteCarlo, kIntImportance, kIntMetropolis, kIntCuba, NIntMethods };
00056 
00059       enum BCMarginalizationMethod { kMargMonteCarlo, kMargMetropolis, NMargMethods };
00060 
00063       enum BCOptimizationMethod { kOptSA, kOptMetropolis, kOptMinuit, NOptMethods };
00064 
00067       enum BCSASchedule { kSACauchy, kSABoltzmann, kSACustom, NSAMethods };
00068 
00071       enum BCCubaMethod { kCubaVegas, kCubaSuave, kCubaDivonne, kCubaCuhre };
00072 
00080       BCIntegrate();
00081 
00084       BCIntegrate(BCParameterSet * par);
00085 
00088       BCIntegrate(const BCIntegrate & bcintegrate);
00089 
00092       virtual ~BCIntegrate();
00093 
00100          BCIntegrate & operator = (const BCIntegrate & bcintegrate);
00101 
00108       BCIntegrate::BCIntegrationMethod GetIntegrationMethod()
00109          { return fIntegrationMethod; }
00110 
00113       BCIntegrate::BCMarginalizationMethod GetMarginalizationMethod()
00114          { return fMarginalizationMethod; }
00115 
00118       BCIntegrate::BCOptimizationMethod GetOptimizationMethod()
00119          { return fOptimizationMethod; }
00120 
00123       BCIntegrate::BCOptimizationMethod GetOptimizationMethodMode()
00124          { return fOptimizationMethodMode; }
00125 
00128       BCIntegrate::BCSASchedule GetSASchedule()
00129          { return fSASchedule; }
00130 
00134       void GetRandomVector(std::vector <double> &x);
00135 
00136       virtual void GetRandomVectorMetro(std::vector <double> &x);
00137 
00143       double GetRandomPoint(std::vector <double> &x);
00144 
00150       double GetRandomPointImportance(std::vector <double> &x);
00151 
00156       void GetRandomPointMetro(std::vector <double> &x);
00157 
00162       void GetRandomPointSamplingMetro(std::vector <double> &x);
00163 
00166       int GetNiterationsPerDimension()
00167          { return fNiterPerDimension; }
00168 
00171       int GetNSamplesPer2DBin()
00172          { return fNSamplesPer2DBin; }
00173 
00176       int GetNvar()
00177          { return fNvar; }
00178 
00181       int GetNIterationsMax()
00182          { return fNIterationsMax; }
00183 
00186       int GetNIterations()
00187          { return fNIterations; }
00188 
00191       double GetRelativePrecision()
00192          { return fRelativePrecision; }
00193 
00196       double GetAbsolutePrecision()
00197          { return fAbsolutePrecision; }
00198 
00201       BCCubaMethod GetCubaIntegrationMethod()
00202          { return fCubaIntegrationMethod; }
00203 
00206       int GetCubaMinEval()
00207          { return fCubaMinEval; }
00208 
00211       int GetCubaMaxEval()
00212          { return fCubaMaxEval; }
00213 
00216       int GetCubaVerbositylevel()
00217          { return fCubaVerbosity; }
00218 
00221       int GetCubaVegasNStart()
00222          { return fCubaVegasNStart; }
00223 
00226       int GetCubaVegasNIncrease()
00227          { return fCubaVegasNIncrease; }
00228 
00231       int GetCubaSuaveNNew()
00232          { return fCubaSuaveNNew; }
00233 
00236       double GetCubaSuaveFlatness()
00237          { return fCubaSuaveFlatness; }
00238 
00241       double GetError()
00242          { return fError; }
00243 
00246       int GetNbins()
00247          { return fNbins; }
00248 
00251       TMinuit * GetMinuit();
00252 
00253       int GetMinuitErrorFlag()
00254          { return fMinuitErrorFlag; }
00255 
00258       TTree * GetMarkovChainTree()
00259          { return fMarkovChainTree; }
00260 
00263       std::vector<double> * GetMarkovChainPoint()
00264          { return &fXmetro1; }
00265 
00268       int * GetMCMCIteration()
00269          { return &fMCMCIteration; }
00270 
00273       double * GetMarkovChainValue()
00274          { return &fMarkovChainValue; }
00275 
00278       double GetSAT0()
00279          { return fSAT0; }
00280 
00283       double GetSATmin()
00284          { return fSATmin; }
00285 
00291       void SetMinuitArlist(double * arglist)
00292          { fMinuitArglist[0] = arglist[0];
00293            fMinuitArglist[1] = arglist[1]; }
00294 
00295       void SetFlagIgnorePrevOptimization(bool flag)
00296          { fFlagIgnorePrevOptimization = flag; }
00297 
00301       void SetParameters(BCParameterSet * par);
00302 
00305       void SetVarList(int * varlist);
00306 
00309       void SetVar(int index)
00310          {fVarlist[index]=1;}
00311 
00314       void SetIntegrationMethod(BCIntegrate::BCIntegrationMethod method);
00315 
00318       void SetMarginalizationMethod(BCIntegrate::BCMarginalizationMethod method)
00319          { fMarginalizationMethod = method; }
00320 
00323       void SetOptimizationMethod(BCIntegrate::BCOptimizationMethod method)
00324          { fOptimizationMethod = method; }
00325 
00329       void SetOptimizationMethodMode(BCIntegrate::BCOptimizationMethod method)
00330          { fOptimizationMethodMode = method; }
00331 
00332 
00335       void SetSASchedule(BCIntegrate::BCSASchedule schedule)
00336          { fSASchedule = schedule; }
00337 
00340       void SetNiterationsPerDimension(int niterations)
00341          { fNiterPerDimension = niterations; }
00342 
00346       void SetNSamplesPer2DBin(int n)
00347          { fNSamplesPer2DBin = n; }
00348 
00351       void SetNIterationsMax(int niterations)
00352          { fNIterationsMax = niterations; }
00353 
00357       void SetRelativePrecision(double relprecision)
00358          { fRelativePrecision = relprecision; }
00359 
00362       void SetAbsolutePrecision(double absprecision)
00363          { fAbsolutePrecision = absprecision; }
00364 
00367       void SetCubaIntegrationMethod(BCCubaMethod type);
00368 
00371       void SetCubaMinEval(int n)
00372          { fCubaMinEval = n; }
00373 
00376       void SetCubaMaxEval(int n)
00377          { fCubaMaxEval = n; }
00378 
00381       void SetCubaVerbosityLevel(int n)
00382          { fCubaVerbosity = n; }
00383 
00386       void SetCubaVegasNStart(int n)
00387          { fCubaVegasNStart = n; }
00388 
00391       void SetCubaVegasNIncrease(int n)
00392          { fCubaVegasNIncrease = n; }
00393 
00396       void SetCubaSuaveNNew(int n)
00397          { fCubaSuaveNNew = n; }
00398 
00401       void SetCubaSuaveFlatness(double p)
00402          { fCubaSuaveFlatness = p; }
00403 
00413       void SetNbins(int nbins, int index = -1);
00414 
00418       void SetFillErrorBand(bool flag = true)
00419          { fFillErrorBand=flag; }
00420 
00424       void UnsetFillErrorBand()
00425          { fFillErrorBand=false; }
00426 
00430       void SetFitFunctionIndexX(int index)
00431          { fFitFunctionIndexX = index; }
00432 
00436       void SetFitFunctionIndexY(int index)
00437          { fFitFunctionIndexY = index; }
00438 
00439       void SetFitFunctionIndices(int indexx, int indexy)
00440          { this -> SetFitFunctionIndexX(indexx);
00441             this -> SetFitFunctionIndexY(indexy); }
00442 
00446       void SetDataPointLowerBoundaries(BCDataPoint * datasetlowerboundaries)
00447          { fDataPointLowerBoundaries = datasetlowerboundaries; }
00448 
00452       void SetDataPointUpperBoundaries(BCDataPoint * datasetupperboundaries)
00453          { fDataPointUpperBoundaries = datasetupperboundaries; }
00454 
00458       void SetDataPointLowerBoundary(int index, double lowerboundary)
00459          { fDataPointLowerBoundaries -> SetValue(index, lowerboundary); }
00460 
00464       void SetDataPointUpperBoundary(int index, double upperboundary)
00465          { fDataPointUpperBoundaries -> SetValue(index, upperboundary); }
00466 
00470       void WriteMarkovChain(bool flag)
00471          { fFlagWriteMarkovChain = flag;
00472            fMCMCFlagWriteChainToFile = flag;
00473            fMCMCFlagWritePreRunToFile = flag; }
00474 
00477       void SetMarkovChainTree(TTree * tree)
00478          { fMarkovChainTree = tree; }
00479 
00482       void SetMarkovChainInitialPosition(std::vector<double> position);
00483 
00486       void SetMarkovChainStepSize(double stepsize)
00487          { fMarkovChainStepSize = stepsize; }
00488 
00491       void SetMarkovChainNIterations(int niterations)
00492          { fMarkovChainNIterations = niterations;
00493            fMarkovChainAutoN = false; }
00494 
00497       void SetMarkovChainAutoN(bool flag)
00498          { fMarkovChainAutoN = flag; }
00499 
00502       void SetMode(std::vector <double> mode);
00503 
00506       void SetErrorBandHisto(TH2D * h)
00507          { fErrorBandXY = h; }
00508 
00511       void SetSAT0(double T0)
00512          { fSAT0 = T0; }
00513 
00516       void SetSATmin(double Tmin)
00517          { fSATmin = Tmin; }
00518 
00519       void SetFlagWriteSAToFile(bool flag)
00520          { fFlagWriteSAToFile = flag; }
00521 
00524       void SetSATree(TTree * tree)
00525          { fTreeSA = tree; }
00526 
00529       TTree * GetSATree()
00530          { return fTreeSA; }
00531 
00534       void InitializeSATree();
00535 
00543       void DeleteVarList();
00544 
00548       void ResetVarlist(int v);
00549 
00553       void UnsetVar(int index)
00554          { fVarlist[index] = 0; }
00555 
00561       virtual double Eval(std::vector <double> x);
00562 
00568       virtual double LogEval(std::vector <double> x);
00569 
00575       virtual double EvalSampling(std::vector <double> x);
00576 
00582       double LogEvalSampling(std::vector <double> x);
00583 
00590       double EvalPrint(std::vector <double> x);
00591 
00597       virtual double FitFunction(std::vector <double> /*x*/, std::vector <double> /*parameters*/)
00598          { return 0.; }
00599 
00603       double Integrate();
00604 
00610       double IntegralMC(std::vector <double> x, int * varlist);
00611 
00612       double IntegralMC(std::vector <double> x);
00613 
00618       double IntegralMetro(std::vector <double> x);
00619 
00624       double IntegralImportance(std::vector <double> x);
00625 
00632       double CubaIntegrate(BCIntegrate::BCCubaMethod method, std::vector<double> parameters_double, std::vector<double> parameters_int);
00633 
00634       double CubaIntegrate();
00635 
00643       //      static void CubaIntegrand(const int * ndim, const double xx[], const int * ncomp, double ff[]);
00644       static int CubaIntegrand(const int * ndim, const double xx[], const int * ncomp, double ff[], void *userdata);
00645 
00650       TH1D * Marginalize(BCParameter * parameter);
00651 
00657       TH2D * Marginalize(BCParameter * parameter1, BCParameter * parameter2);
00658 
00664       TH1D * MarginalizeByIntegrate(BCParameter * parameter);
00665 
00672       TH2D * MarginalizeByIntegrate(BCParameter * parameter1, BCParameter * parameter2);
00673 
00679       TH1D * MarginalizeByMetro(BCParameter * parameter);
00680 
00686       TH2D * MarginalizeByMetro(BCParameter * parameter1, BCParameter * parameter2);
00687 
00693       int MarginalizeAllByMetro(const char * name);
00694 
00699       TH1D * GetH1D(int parIndex);
00700 
00706       int GetH2DIndex(int parIndex1, int parIndex2);
00707 
00713       TH2D * GetH2D(int parIndex1, int parIndex2);
00714 
00717       void InitMetro();
00718 
00719       void SAInitialize();
00720 
00723 //      void FindMode();
00724 
00730       virtual void FindModeMinuit(std::vector<double> start = std::vector<double>(0), int printlevel = 1);
00731 
00734       void FindModeMCMC();
00735 //      void FindModeMCMC(int flag_run = 0);
00736 
00742       void FindModeSA(std::vector<double> start = std::vector<double>(0));
00743 
00749       double SATemperature(double t);
00750 
00755       double SATemperatureBoltzmann(double t);
00756 
00761       double SATemperatureCauchy(double t);
00762 
00768       virtual double SATemperatureCustom(double t);
00769 
00777       std::vector<double> GetProposalPointSA(std::vector<double> x, int t);
00778 
00785       std::vector<double> GetProposalPointSABoltzmann(std::vector<double> x, int t);
00786 
00793       std::vector<double> GetProposalPointSACauchy(std::vector<double> x, int t);
00794 
00802       virtual std::vector<double> GetProposalPointSACustom(std::vector<double> x, int t);
00803 
00808       std::vector<double> SAHelperGetRandomPointOnHypersphere();
00809 
00813       double SAHelperGetRadialCauchy();
00814 
00818       double SAHelperSinusToNIntegral(int dim, double theta);
00819 
00820 
00821       static void FCNLikelihood(int &npar, double * grad, double &fval, double * par, int flag);
00822 
00826       virtual void MCMCUserIterationInterface()
00827          {}
00828 
00832       int IntegrateResetResults();
00833 
00834       std::string DumpIntegrationMethod(BCIntegrationMethod type);
00835       std::string DumpIntegrationMethod()
00836          { return DumpIntegrationMethod(fIntegrationMethod); }
00837 
00838       std::string DumpMarginalizationMethod(BCMarginalizationMethod type);
00839       std::string DumpMarginalizationMethod()
00840          { return DumpMarginalizationMethod(fMarginalizationMethod); }
00841 
00842       std::string DumpOptimizationMethod(BCOptimizationMethod type);
00843       std::string DumpOptimizationMethod()
00844          { return DumpOptimizationMethod(fOptimizationMethod); }
00845       std::string DumpUsedOptimizationMethod()
00846          { return DumpOptimizationMethod(fOptimizationMethodMode); }
00847 
00848       std::string DumpCubaIntegrationMethod(BCCubaMethod type);
00849       std::string DumpCubaIntegrationMethod()
00850          { return DumpCubaIntegrationMethod(fCubaIntegrationMethod); }
00851 
00852 
00855    protected:
00856 
00859       int fNvar;
00860 
00863       int fNbins;
00864 
00868       int fNSamplesPer2DBin;
00869 
00872       double fMarkovChainStepSize;
00873 
00874       int fMarkovChainNIterations;
00875 
00876       bool fMarkovChainAutoN;
00877 
00880       BCDataPoint * fDataPointLowerBoundaries;
00881 
00884       BCDataPoint * fDataPointUpperBoundaries;
00885 
00886       std::vector <bool> fDataFixedValues;
00887 
00891       std::vector <double> fBestFitParameters;
00892       std::vector <double> fBestFitParameterErrors;
00893 
00896       std::vector <double> fBestFitParametersMarginalized;
00897 
00900       std::vector <TH1D *> fHProb1D;
00901 
00904       std::vector <TH2D *> fHProb2D;
00905 
00908       bool fFillErrorBand;
00909 
00912       int fFitFunctionIndexX;
00913       int fFitFunctionIndexY;
00914 
00917       bool fErrorBandContinuous;
00918       std::vector <double> fErrorBandX;
00919 
00922       TH2D * fErrorBandXY;
00923 
00926       int fErrorBandNbinsX;
00927 
00930       int fErrorBandNbinsY;
00931 
00934       TMinuit * fMinuit;
00935 
00936       double fMinuitArglist[2];
00937       int fMinuitErrorFlag;
00938 
00941       double fFlagIgnorePrevOptimization;
00942 
00945       bool fFlagWriteMarkovChain;
00946 
00949       TTree * fMarkovChainTree;
00950 
00953       int fMCMCIteration;
00954 
00957       double fSAT0;
00958 
00961       double fSATmin;
00962 
00965       TTree * fTreeSA;
00966 
00969       bool fFlagWriteSAToFile;
00970 
00971       int fSANIterations;
00972       double fSATemperature;
00973       double fSALogProb;
00974       std::vector<double> fSAx;
00975 
00976    private:
00977 
00980       BCParameterSet * fx;
00981 
00984       double * fMin;
00985 
00988       double * fMax;
00989 
00992       int * fVarlist;
00993 
00996       int fNiterPerDimension;
00997 
01000       BCIntegrate::BCIntegrationMethod fIntegrationMethod;
01001 
01004       BCIntegrate::BCMarginalizationMethod fMarginalizationMethod;
01005 
01008       BCIntegrate::BCOptimizationMethod fOptimizationMethod;
01009 
01013       BCIntegrate::BCOptimizationMethod fOptimizationMethodMode;
01014 
01017       BCIntegrate::BCSASchedule fSASchedule;
01018 
01021       int fNIterationsMax;
01022 
01025       int fNIterations;
01026 
01028       double fRelativePrecision;
01029 
01031       double fAbsolutePrecision;
01032 
01034       BCCubaMethod fCubaIntegrationMethod;
01035 
01037       int fCubaMinEval;
01038 
01040       int fCubaMaxEval;
01041 
01043       int fCubaVerbosity;
01044 
01046       int fCubaVegasNStart;
01047 
01049       int fCubaVegasNIncrease;
01050 
01052       int fCubaSuaveNNew;
01053 
01055       double fCubaSuaveFlatness;
01056 
01059       double fError;
01060 
01063       int fNmetro;
01064       int fNacceptedMCMC;
01065 
01068       std::vector <double> fXmetro0;
01069 
01072       std::vector <double> fXmetro1;
01073 
01076       double fMarkovChainValue;
01077 
01080       void MCMCIterationInterface();
01081 
01084       void MCMCFillErrorBand();
01085 };
01086 
01087 // ---------------------------------------------------------
01088 
01089 #endif

Generated by  doxygen 1.7.1