00001 #ifndef __BCENGINEMCMC__H
00002 #define __BCENGINEMCMC__H
00003
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <vector>
00026
00027
00028 class TH1D;
00029 class TH2D;
00030 class TTree;
00031 class TRandom3;
00032
00033
00034
00035 class BCEngineMCMC
00036 {
00037
00038 public:
00039
00041
00042
00045 BCEngineMCMC();
00046
00050 BCEngineMCMC(int n);
00051
00054 BCEngineMCMC(const BCEngineMCMC & enginemcmc);
00055
00058 virtual ~BCEngineMCMC();
00059
00060
00062
00063
00066 BCEngineMCMC & operator = (const BCEngineMCMC & engineMCMC);
00067
00068
00070
00071
00072
00073
00074 int MCMCGetNParameters()
00075 { return fMCMCNParameters; };
00076
00077
00078
00079 int MCMCGetNChains()
00080 { return fMCMCNChains; };
00081
00082
00083
00084 int MCMCGetNLag()
00085 { return fMCMCNLag; };
00086
00087
00088
00089 std::vector <int> MCMCGetNIterations()
00090 { return fMCMCNIterations; };
00091
00092
00093
00094 std::vector <int> * MCMCGetP2NIterations()
00095 { return &fMCMCNIterations; };
00096
00097
00098
00099
00100 int MCMCGetNIterationsConvergenceGlobal()
00101 { return fMCMCNIterationsConvergenceGlobal; };
00102
00103
00104
00105 bool MCMCGetFlagConvergenceGlobal()
00106 { return fMCMCFlagConvergenceGlobal; };
00107
00108
00109
00110 int MCMCGetNIterationsMax()
00111 { return fMCMCNIterationsMax; };
00112
00113
00114
00115 int MCMCGetNIterationsRun()
00116 { return fMCMCNIterationsRun; };
00117
00118
00119
00120
00121 int MCMCGetNIterationsBurnIn()
00122 { return fMCMCNIterationsBurnIn; };
00123
00124
00125
00126 std::vector <int> MCMCGetNTrialsTrue()
00127 { return fMCMCNTrialsTrue; };
00128
00129
00130
00131 std::vector <int> MCMCGetNTrialsFalse()
00132 { return fMCMCNTrialsFalse; };
00133
00134
00135
00136
00137 std::vector <double> MCMCGetMean()
00138 { return fMCMCMean; };
00139
00140
00141
00142
00143 std::vector <double> MCMCGetVariance()
00144 { return fMCMCVariance; };
00145
00146
00147
00148 std::vector <double> MCMCGetTrialFunctionScaleFactor()
00149 { return fMCMCTrialFunctionScaleFactor; };
00150
00151
00152
00153
00154 std::vector <double> MCMCGetTrialFunctionScaleFactor(int ichain);
00155
00156
00157
00158
00159
00160 double MCMCGetTrialFunctionScaleFactor(int ichain, int ipar);
00161
00162
00163
00164 std::vector <double> MCMCGetx()
00165 { return fMCMCx; };
00166
00167
00168
00169 std::vector <double> * MCMCGetP2x()
00170 { return &fMCMCx; };
00171
00172
00173
00174
00175 std::vector <double> MCMCGetx(int ichain);
00176
00177
00178
00179
00180
00181 double MCMCGetx(int ichain, int ipar);
00182
00183
00184
00185 std::vector <double> MCMCGetLogProbx()
00186 { return fMCMCLogProbx; };
00187
00188
00189
00190
00191 double MCMCGetLogProbx(int ichain);
00192
00193
00194
00195 std::vector <double> * MCMCGetP2LogProbx()
00196 { return &fMCMCLogProbx; };
00197
00198
00199
00200 std::vector <double> MCMCGetMaximumPoints()
00201 { return fMCMCMaximumPoints; };
00202
00203
00204
00205
00206 std::vector <double> MCMCGetMaximumPoint(int i);
00207
00208
00209
00210 std::vector <double> MCMCGetMaximumLogProb()
00211 { return fMCMCMaximumLogProb; };
00212
00213
00214
00215 int MCMCGetFlagInitialPosition()
00216 { return fMCMCFlagInitialPosition; };
00217
00218
00219
00220 double MCMCGetRValueCriterion()
00221 { return fMCMCRValueCriterion; };
00222
00223
00224
00225 double MCMCGetRValueParametersCriterion()
00226 { return fMCMCRValueParametersCriterion; };
00227
00228
00229
00230 double MCMCGetRValue()
00231 { return fMCMCRValue; };
00232
00233
00234
00235
00236 double MCMCGetRValueParameters(int i)
00237 { return fMCMCRValueParameters.at(i); };
00238
00239
00240
00241 bool MCMCGetFlagRun()
00242 { return fMCMCFlagRun; };
00243
00244
00245
00246
00247
00248 TTree * MCMCGetMarkovChainTree(int i)
00249 { return fMCMCTrees.at(i); };
00250
00251
00252
00253
00254
00255 TH1D * MCMCGetH1Marginalized(int i);
00256
00257
00258
00259
00260
00261
00262 TH2D * MCMCGetH2Marginalized(int i, int j);
00263
00264
00265
00266 TRandom3 * MCMCGetTRandom3()
00267 { return fMCMCRandom; };
00268
00269
00271
00272
00273
00274
00275
00276 void MCMCSetTrialFunctionScaleFactor(std::vector <double> scale)
00277 { fMCMCTrialFunctionScaleFactorStart = scale; };
00278
00279
00280
00281 void MCMCSetNChains(int n);
00282
00283
00284
00285 void MCMCSetNLag(int n)
00286 { fMCMCNLag = n; };
00287
00288
00289
00290 void MCMCSetNIterationsMax(int n)
00291 { fMCMCNIterationsMax = n; };
00292
00293
00294
00295 void MCMCSetNIterationsRun(int n)
00296 { fMCMCNIterationsRun = n; };
00297
00298
00299
00300 void MCMCSetNIterationsBurnIn(int n)
00301 { fMCMCNIterationsBurnIn = n; };
00302
00303
00304
00305 void MCMCSetNIterationsPreRunMin(int n)
00306 { fMCMCNIterationsPreRunMin = n; };
00307
00308
00309
00310
00311
00312 void MCMCSetNIterationsUpdate(int n)
00313 { fMCMCNIterationsUpdate = n; };
00314
00315
00316
00317
00318
00319
00320 void MCMCSetNIterationsUpdateMax(int n)
00321 { fMCMCNIterationsUpdateMax = n; };
00322
00323
00324
00325 void MCMCSetMinimumEfficiency(double efficiency)
00326 { fMCMCEfficiencyMin = efficiency; };
00327
00328
00329
00330 void MCMCSetMaximumEfficiency(double efficiency)
00331 { fMCMCEfficiencyMax = efficiency; };
00332
00333
00334
00335 void MCMCSetWriteChainToFile(bool flag)
00336 { fMCMCFlagWriteChainToFile = flag; };
00337
00338
00339
00340
00341 void MCMCSetInitialPositions(std::vector<double> x0s);
00342
00343
00344
00345
00346 void MCMCSetInitialPositions(std::vector< std::vector<double> > x0s);
00347
00348
00349
00350 void MCMCSetFlagInitialPosition(int flag)
00351 { fMCMCFlagInitialPosition = flag; };
00352
00353
00354
00355
00356 void MCMCSetFlagOrderParameters(bool flag)
00357 { fMCMCFlagOrderParameters = flag; };
00358
00359
00360 void MCMCSetFlagFillHistograms(bool flag);
00361
00362
00363 void MCMCSetFlagFillHistograms(int index, bool flag);
00364
00365
00366
00367 void MCMCSetRValueCriterion(double r)
00368 { fMCMCRValueCriterion = r; };
00369
00370
00371
00372 void MCMCSetRValueParametersCriterion(double r)
00373 { fMCMCRValueParametersCriterion = r; };
00374
00375
00376
00377 void MCMCSetMarkovChainTrees(std::vector <TTree *> trees);
00378
00379
00380
00381
00382
00383 int SetMarginalized(int index, TH1D * h);
00384
00385
00386
00387
00388
00389
00390 int SetMarginalized(int index1, int index2, TH2D * h);
00391
00392
00393
00394 void MCMCSetValuesDefault();
00395
00396
00397
00398 void MCMCSetValuesQuick();
00399
00400
00401
00402 void MCMCSetValuesDetail();
00403
00404
00406
00407
00408
00409
00410
00411
00412
00413 int MCMCAddParameter(double min, double max);
00414
00415
00416
00417
00418
00419
00420
00421 virtual void MCMCTrialFunction(int chain, std::vector <double> &x);
00422
00423
00424
00425
00426
00427
00428
00429
00430 virtual void MCMCTrialFunctionSingle(int ichain, int iparameter, std::vector <double> &x);
00431
00432
00433
00434
00435
00436
00437 bool MCMCGetProposalPointMetropolis(int chain, std::vector <double> &x);
00438
00439
00440
00441
00442
00443
00444 bool MCMCGetProposalPointMetropolis(int chain, int parameter, std::vector <double> &x);
00445
00446
00447
00448
00449 bool MCMCGetNewPointMetropolis(int chain = 0);
00450 bool MCMCGetNewPointMetropolis(int chain, int parameter);
00451
00452
00453
00454 void MCMCUpdateStatisticsCheckMaximum();
00455
00456
00457
00458 void MCMCUpdateStatisticsFillHistograms();
00459
00460
00461
00462 void MCMCUpdateStatisticsTestConvergenceAllChains();
00463
00464
00465
00466 void MCMCUpdateStatisticsWriteChains();
00467
00468
00469
00470
00471 virtual double LogEval(std::vector <double> parameters);
00472
00473
00474
00475 int MCMCMetropolis();
00476
00477
00478
00479 int MCMCMetropolisPreRun();
00480
00481
00482
00483 void MCMCResetRunStatistics();
00484
00485
00486
00487 void MCMCInitializeMarkovChains();
00488
00489
00490
00491 int MCMCInitialize();
00492
00493
00494
00495
00496
00497 virtual void MCMCIterationInterface()
00498 {};
00499
00500
00501
00502 private:
00503
00504
00505
00506 void Copy(BCEngineMCMC & enginemcmc) const;
00507
00508
00509
00510 typedef bool (BCEngineMCMC::*MCMCPointerToGetProposalPoint) (int chain, std::vector <double> xnew, std::vector <double> xold) const;
00511
00512
00513
00514 MCMCPointerToGetProposalPoint fMCMCPointerToGetProposalPoint;
00515
00516 protected:
00517
00518
00519
00520 int fMCMCNParameters;
00521
00522
00523
00524 std::vector <double> fMCMCBoundaryMin;
00525 std::vector <double> fMCMCBoundaryMax;
00526
00527
00528
00529 std::vector <bool> fMCMCFlagsFillHistograms;
00530
00531
00532
00533 int fMCMCNChains;
00534
00535
00536
00537 int fMCMCNLag;
00538
00539
00540
00541
00542 std::vector<int> fMCMCNIterations;
00543
00544
00545
00546 int fMCMCNIterationsUpdate;
00547
00548
00549
00550 int fMCMCNIterationsUpdateMax;
00551
00552
00553
00554
00555 int fMCMCNIterationsConvergenceGlobal;
00556
00557
00558
00559 bool fMCMCFlagConvergenceGlobal;
00560
00561
00562
00563 int fMCMCNIterationsMax;
00564
00565
00566
00567 int fMCMCNIterationsRun;
00568
00569
00570
00571 int fMCMCNIterationsPreRunMin;
00572
00573
00574
00575
00576 int fMCMCNIterationsBurnIn;
00577
00578
00579
00580
00581 std::vector<int> fMCMCNTrialsTrue;
00582
00583
00584
00585
00586 std::vector<int> fMCMCNTrialsFalse;
00587
00588
00589
00590
00591 std::vector <double> fMCMCMean;
00592
00593
00594
00595
00596 std::vector <double> fMCMCVariance;
00597
00598
00599
00600
00601 std::vector <double> fMCMCMeanx;
00602
00603
00604
00605
00606 std::vector <double> fMCMCVariancex;
00607
00608
00609
00610 bool fMCMCFlagWriteChainToFile;
00611
00612
00613
00614
00615 std::vector <double> fMCMCTrialFunctionScaleFactor;
00616
00617
00618
00619
00620 std::vector <double> fMCMCTrialFunctionScaleFactorStart;
00621
00622
00623
00624 bool fMCMCFlagPreRun;
00625
00626
00627
00628 bool fMCMCFlagRun;
00629
00630
00631
00632
00633
00634
00635 std::vector <double> fMCMCInitialPosition;
00636
00637
00638
00639 double fMCMCEfficiencyMin;
00640
00641
00642
00643 double fMCMCEfficiencyMax;
00644
00645
00646
00647
00648
00649 int fMCMCFlagInitialPosition;
00650
00651
00652
00653
00654 bool fMCMCFlagOrderParameters;
00655
00656
00657
00658 bool fMCMCFlagFillHistograms;
00659
00660
00661
00662
00663
00664
00665 std::vector <double> fMCMCx;
00666
00667
00668
00669 std::vector <double> fMCMCxLocal;
00670
00671
00672
00673
00674 std::vector<double> fMCMCLogProbx;
00675
00676
00677
00678
00679
00680 std::vector <double> fMCMCMaximumPoints;
00681
00682
00683
00684
00685 std::vector <double> fMCMCMaximumLogProb;
00686
00687
00688
00689 double fMCMCRValueCriterion;
00690
00691
00692
00693 double fMCMCRValueParametersCriterion;
00694
00695
00696
00697 double fMCMCRValue;
00698
00699
00700 std::vector <double> fMCMCRValueParameters;
00701
00702
00703
00704 TRandom3 * fMCMCRandom;
00705
00706
00707
00708 std::vector<int> fMCMCH1NBins;
00709
00710
00711
00712 std::vector <TH1D *> fMCMCH1Marginalized;
00713 std::vector <TH2D *> fMCMCH2Marginalized;
00714
00715
00716
00717
00718 std::vector<TTree *> fMCMCTrees;
00719 };
00720
00721
00722
00723 #endif