![]() |
MaCh3
2.5.0
Reference Guide
|
Implementation of Prior/Posterior Predictive and Bayesian p-Value calculations following the approach described in [11] , [12], [14]. More...
#include <Fitters/PredictiveThrower.h>
Public Member Functions | |
| PredictiveThrower (Manager *const fitMan) | |
| Constructor. More... | |
| virtual | ~PredictiveThrower () |
| Destructor. More... | |
| void | ProduceToys () |
| Produce toys by throwing from MCMC. More... | |
| void | RunPredictiveAnalysis () |
| Main routine responsible for producing posterior predictive distributions and $p$-value. More... | |
| void | RunMCMC () override |
| This is not used in this class. More... | |
Public Member Functions inherited from FitterBase | |
| FitterBase (Manager *const fitMan) | |
| Constructor. More... | |
| virtual | ~FitterBase () |
| Destructor for the FitterBase class. More... | |
| void | AddSampleHandler (SampleHandlerInterface *sample) |
| This function adds a sample PDF object to the analysis framework. The sample PDF object will be utilized in fitting procedures or likelihood scans. More... | |
| void | AddSystObj (ParameterHandlerBase *cov) |
| This function adds a Covariance object to the analysis framework. The Covariance object will be utilized in fitting procedures or likelihood scans. More... | |
| void | DragRace (const int NLaps=100) |
| Calculates the required time for each sample or covariance object in a drag race simulation. Inspired by Dan's feature. More... | |
| void | RunLLHScan () |
| Perform a 1D likelihood scan. More... | |
| void | RunLLHMap () |
| Perform a general multi-dimensional likelihood scan. More... | |
| void | GetStepScaleBasedOnLLHScan (const std::string &filename="") |
| LLH scan is good first estimate of step scale. More... | |
| void | Run2DLLHScan () |
| Perform a 2D likelihood scan. More... | |
| void | RunSigmaVar () |
| Perform a 1D/2D sigma var for all samples. More... | |
| virtual void | StartFromPreviousFit (const std::string &FitName) |
| Allow to start from previous fit/chain. More... | |
| std::string | GetName () const |
| Get name of class. More... | |
Private Member Functions | |
| void | SetParamters (std::vector< std::string > &ParameterGroupsNotVaried, std::unordered_set< int > &ParameterOnlyToVary) |
| This set some params to prior value this way you can evaluate errors from subset of errors. More... | |
| void | SetupToyGeneration (std::vector< std::string > &ParameterGroupsNotVaried, std::unordered_set< int > &ParameterOnlyToVary, std::vector< const M3::float_t * > &BoundValuePointer, std::vector< std::pair< double, double >> &ParamBounds) |
| Setup useful variables etc before stating toy generation. More... | |
| bool | LoadToys () |
| Load existing toys. More... | |
| void | WriteToy (TDirectory *ToyDirectory, TDirectory *Toy_1DDirectory, TDirectory *Toy_2DDirectory, const int iToy) |
| Save histograms for a single MCMC Throw/Toy. More... | |
| void | SetupSampleInformation () |
| Setup sample information. More... | |
| std::vector< std::string > | GetStoredFancyName (ParameterHandlerBase *Systematics) const |
| Get Fancy parameters stored in mcmc chains for passed ParameterHandler. More... | |
| std::vector< std::unique_ptr< TH1 > > | MakePredictive (const std::vector< std::vector< std::unique_ptr< TH1 >>> &Toys, const std::vector< TDirectory * > &Director, const std::string &suffix, const bool DebugHistograms, const bool WriteHist) |
| Produce posterior predictive distribution. More... | |
| void | Study1DProjections (const std::vector< TDirectory * > &SampleDirectories) const |
| Load 1D projections and later produce violin plots for each. More... | |
| void | ProduceSpectra (const std::vector< std::vector< std::vector< std::unique_ptr< TH1D >>>> &Toys, const std::vector< TDirectory * > &Director, const std::string suffix) const |
| Produce Violin style spectra. More... | |
| void | MakeFluctuatedHistogram (TH1 *FluctHist, TH1 *PolyHist) |
| Make Poisson fluctuation of TH1D hist. More... | |
| void | PredictiveLLH (const std::vector< std::unique_ptr< TH1 >> &Data_histogram, const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< std::unique_ptr< TH1 >> &PostPred_w, const std::vector< TDirectory * > &SampleDir) |
| Calculate Posterior Predictive LLH. More... | |
| void | PosteriorPredictivepValue (const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< TDirectory * > &SampleDir) |
| Calculate Posterior Predictive $p$-value Compares observed data to toy datasets generated from: More... | |
| void | ExtractLLH (TH1 *DatHist, TH1 *MCHist, TH1 *W2Hist, const SampleHandlerInterface *SampleHandler) const |
| Calculate the LLH for TH1, set the LLH to title of MCHist. More... | |
| double | CalcLLH (const double data, const double mc, const double w2, const SampleHandlerInterface *SampleHandler) const |
| Calculates the -2LLH (likelihood) for a single sample. More... | |
| double | CalcLLH (const TH1 *DatHist, const TH1 *MCHist, const TH1 *W2Hist, const SampleHandlerInterface *SampleHandler) const |
| Calculates the likelihood (-2LLH) for a single sample; dynamically casts to call the correct GetLLH overload. More... | |
| double | GetLLH (const TH1D *DatHist, const TH1D *MCHist, const TH1D *W2Hist, const SampleHandlerInterface *SampleHandler) const |
| Helper functions to calculate likelihoods using TH1D. More... | |
| double | GetLLH (const TH2D *DatHist, const TH2D *MCHist, const TH2D *W2Hist, const SampleHandlerInterface *SampleHandler) const |
| Helper functions to calculate likelihoods using TH2D. More... | |
| double | GetLLH (const TH2Poly *DatHist, const TH2Poly *MCHist, const TH2Poly *W2Hist, const SampleHandlerInterface *SampleHandler) const |
| Helper functions to calculate likelihoods using TH2Poly. More... | |
| void | MakeChi2Plots (const std::vector< std::vector< double >> &Chi2_x, const std::string &Chi2_x_title, const std::vector< std::vector< double >> &Chi2_y, const std::string &Chi2_y_title, const std::vector< TDirectory * > &SampleDir, const std::string Title) |
| Produce Chi2 plot for a single sample based on which $p$-value is calculated. More... | |
| void | StudyInformationCriterion (M3::kInfCrit Criterion, const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< std::unique_ptr< TH1 >> &PostPred_w) |
| Information Criterion. More... | |
| void | StudyBIC (const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< std::unique_ptr< TH1 >> &PostPred_w) |
| Study Bayesian Information Criterion (BIC) The BIC is defined as: More... | |
| void | StudyDIC (const std::vector< std::unique_ptr< TH1 >> &PostPred_mc, const std::vector< std::unique_ptr< TH1 >> &PostPred_w) |
| KS: Get the Deviance Information Criterion (DIC) The deviance is defined as: More... | |
| void | StudyWAIC () |
| KS: Get the Watanabe-Akaike information criterion (WAIC) More... | |
| std::string | GetBinName (TH1 *hist, const bool uniform, const int Dim, const std::vector< int > &bins) const |
| Construct a human-readable label describing a specific analysis bin. More... | |
| std::vector< std::unique_ptr< TH1D > > | PerBinHistogram (TH1 *hist, const int SampleId, const int Dim, const std::string &suffix) const |
| Create per-bin posterior histograms for a given sample. More... | |
| void | StudyBetaParameters (TDirectory *PredictiveDir) |
| Evaluate prior/post predictive distribution for beta parameters (used for evaluating impact MC statistical uncertainty) More... | |
| void | MakeCutEventRate (TH1D *Histogram, const double DataRate) const |
| Make the 1D Event Rate Hist. More... | |
| void | RateAnalysis (const std::vector< std::vector< std::unique_ptr< TH1 >>> &Toys, const std::vector< TDirectory * > &SampleDirectories) const |
| Produce distribution of number of events for each sample. More... | |
Private Attributes | |
| bool | FullLLH |
| KS: Use Full LLH or only sample contribution based on discussion with Asher we almost always only want the sample likelihood. More... | |
| int | NModelParams |
| KS: Count total number of model parameters which can be used for stuff like BIC. More... | |
| bool | Is_PriorPredictive |
| Whether it is Prior or Posterior predictive. More... | |
| int | TotalNumberOfSamples |
| Number of toys we are generating analysing. More... | |
| std::vector< PredictiveSample > | SampleInfo |
| Handy struct for all sample info. More... | |
| int | Ntoys |
| Number of toys we are generating analysing. More... | |
| ParameterHandlerGeneric * | ModelSystematic |
| Pointer to El Generico. More... | |
| std::vector< std::unique_ptr< TH1 > > | Data_Hist |
| Vector of Data histograms. More... | |
| std::vector< std::unique_ptr< TH1 > > | MC_Nom_Hist |
| Vector of MC histograms. More... | |
| std::vector< std::unique_ptr< TH1 > > | W2_Nom_Hist |
| Vector of W2 histograms. More... | |
| std::vector< std::vector< std::unique_ptr< TH1 > > > | MC_Hist_Toy |
| std::vector< std::vector< std::unique_ptr< TH1 > > > | W2_Hist_Toy |
| std::vector< double > | ReweightWeight |
| Reweighting factors applied for each toy, by default 1. More... | |
| std::vector< double > | PenaltyTerm |
| Penalty term values for each toy by default 0. More... | |
| bool | StandardFluctuation |
| KS: We have two methods for Poissonian fluctuation. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from FitterBase | |
| void | ProcessMCMC () |
| Process MCMC output. More... | |
| void | PrepareOutput () |
| Prepare the output file. More... | |
| void | SaveOutput () |
| Save output and close files. More... | |
| void | SanitiseInputs () |
| Remove obsolete memory and make other checks before fit starts. More... | |
| void | SaveSettings () |
| Save the settings that the MCMC was run with. More... | |
| bool | GetScanRange (std::map< std::string, std::vector< double >> &scanRanges) const |
| YSP: Set up a mapping to store parameters with user-specified ranges, suggested by D. Barrow. More... | |
| void | GetParameterScanRange (const ParameterHandlerBase *cov, const int i, double &CentralValue, double &lower, double &upper, const int n_points, const std::string &suffix="") const |
| Helper function to get parameter scan range, central value. More... | |
| bool | CheckSkipParameter (const std::vector< std::string > &SkipVector, const std::string &ParamName) const |
| KS: Check whether we want to skip parameter using skip vector. More... | |
| void | CustomRange (const std::string &ParName, const double sigma, double &ParamShiftValue) const |
| For comparison with other fitting frameworks (like P-Theta) we usually have to apply different parameter values then usual 1, 3 sigma. More... | |
Protected Attributes inherited from FitterBase | |
| Manager * | fitMan |
| The manager for configuration handling. More... | |
| unsigned int | step |
| current state More... | |
| double | logLCurr |
| current likelihood More... | |
| double | logLProp |
| proposed likelihood More... | |
| double | accProb |
| current acceptance prob More... | |
| int | accCount |
| counts accepted steps More... | |
| unsigned int | stepStart |
| step start, by default 0 if we start from previous chain then it will be different More... | |
| std::vector< double > | sample_llh |
| store the llh breakdowns More... | |
| std::vector< double > | syst_llh |
| systematic llh breakdowns More... | |
| std::vector< SampleHandlerInterface * > | samples |
| Sample holder. More... | |
| unsigned int | TotalNSamples |
| Total number of samples used, single SampleHandler can store more than one analysis sample! More... | |
| std::vector< ParameterHandlerBase * > | systematics |
| Systematic holder. More... | |
| std::unique_ptr< TStopwatch > | clock |
| tells global time how long fit took More... | |
| std::unique_ptr< TStopwatch > | stepClock |
| tells how long single step/fit iteration took More... | |
| double | stepTime |
| Time of single step. More... | |
| std::unique_ptr< TRandom3 > | random |
| Random number. More... | |
| TFile * | outputFile |
| Output. More... | |
| TDirectory * | CovFolder |
| Output cov folder. More... | |
| TDirectory * | SampleFolder |
| Output sample folder. More... | |
| TTree * | outTree |
| Output tree with posteriors. More... | |
| int | auto_save |
| auto save every N steps More... | |
| bool | fTestLikelihood |
| Necessary for some fitting algorithms like PSO. More... | |
| bool | FileSaved |
| Checks if file saved not repeat some operations. More... | |
| bool | SettingsSaved |
| Checks if setting saved not repeat some operations. More... | |
| bool | OutputPrepared |
| Checks if output prepared not repeat some operations. More... | |
| std::string | AlgorithmName |
| Name of fitting algorithm that is being used. More... | |
Implementation of Prior/Posterior Predictive and Bayesian p-Value calculations following the approach described in [11] , [12], [14].
For more information, visit the Posterior Predictive page.
add BIC, DIC, WAIC
add Rate $p$-value
add plots by mode
Post Pred LLH
unify code with SampleSummary
Definition at line 38 of file PredictiveThrower.h.
| PredictiveThrower::PredictiveThrower | ( | Manager *const | fitMan | ) |
Constructor.
| fitMan | A pointer to a manager object, which will handle all settings. |
Definition at line 10 of file PredictiveThrower.cpp.
|
virtual |
Destructor.
Definition at line 37 of file PredictiveThrower.cpp.
|
private |
Calculates the -2LLH (likelihood) for a single sample.
| data | Data value for the sample. |
| mc | MC (Monte Carlo) value for the sample. |
| w2 | W2 value for the sample. |
| SampleHandler | Pointer to SampleHandlerInterface providing the LLH test statistic. |
Definition at line 1071 of file PredictiveThrower.cpp.
|
private |
Calculates the likelihood (-2LLH) for a single sample; dynamically casts to call the correct GetLLH overload.
| DatHist | Data histogram with data distribution for a single sample |
| MCHist | MC histogram with MC distribution for a single sample |
| W2Hist | W2 histogram with W2 distribution for a single sample |
| SampleHandler | Pointer to SampleHandlerInterface providing LLH test statistic |
Definition at line 1082 of file PredictiveThrower.cpp.
|
private |
Calculate the LLH for TH1, set the LLH to title of MCHist.
| DatHist | Data histogram with data distribution for a single sample |
| MCHist | MC histogram with MC distribution for a single sample |
| W2Hist | W2 histogram with W2 distribution for a single sample |
| SampleHandler | Pointer to SampleHandlerInterface providing LLH test statistic |
Definition at line 1431 of file PredictiveThrower.cpp.
|
private |
Construct a human-readable label describing a specific analysis bin.
| hist | Histogram providing the binning definition. |
| uniform | Flag indicating whether the histogram uses regular axis binning (TH1/TH2) or irregular polygonal binning (e.g. TH2Poly). |
| Dim | Dimensionality of the original distribution. |
| bins | Vector of per-dimension bin indices in analysis coordinates. |
Definition at line 825 of file PredictiveThrower.cpp.
|
private |
Helper functions to calculate likelihoods using TH1D.
| DatHist | Data histogram with data distribution for a single sample |
| MCHist | MC histogram with MC distribution for a single sample |
| W2Hist | W2 histogram with W2 distribution for a single sample |
| SampleHandler | Pointer to SampleHandlerInterface providing LLH test statistic |
Definition at line 1116 of file PredictiveThrower.cpp.
|
private |
Helper functions to calculate likelihoods using TH2D.
| DatHist | Data 2D histogram with data distribution for a single sample |
| MCHist | MC 2D histogram with MC distribution for a single sample |
| W2Hist | W2 2D histogram with W2 distribution for a single sample |
| SampleHandler | Pointer to SampleHandlerInterface providing LLH test statistic |
Definition at line 1152 of file PredictiveThrower.cpp.
|
private |
Helper functions to calculate likelihoods using TH2Poly.
| DatHist | Data 2D poly histogram with data distribution for a single sample |
| MCHist | MC 2D poly histogram with MC distribution for a single sample |
| W2Hist | W2 2D poly histogram with W2 distribution for a single sample |
| SampleHandler | Pointer to SampleHandlerInterface providing LLH test statistic |
Definition at line 1134 of file PredictiveThrower.cpp.
|
private |
Get Fancy parameters stored in mcmc chains for passed ParameterHandler.
Definition at line 328 of file PredictiveThrower.cpp.
|
private |
Load existing toys.
Definition at line 235 of file PredictiveThrower.cpp.
|
private |
Produce Chi2 plot for a single sample based on which $p$-value is calculated.
Definition at line 1295 of file PredictiveThrower.cpp.
|
private |
Make the 1D Event Rate Hist.
Definition at line 1442 of file PredictiveThrower.cpp.
|
private |
Make Poisson fluctuation of TH1D hist.
| FluctHist | Histogram to store fluctuated values (must match Hist type) |
| Hist | Original histogram to fluctuate |
Definition at line 1180 of file PredictiveThrower.cpp.
|
private |
Produce posterior predictive distribution.
Definition at line 916 of file PredictiveThrower.cpp.
|
private |
Create per-bin posterior histograms for a given sample.
For each analysis bin of the input histogram, this function allocates a new 1D histogram intended to accumulate the distribution of predicted event counts (e.g. across throws, toys, or posterior evaluations).
The number of output histograms therefore equals the number of physical bins:
| hist | Input histogram defining the bin structure for this sample. |
| SampleId | Index identifying the sample in SampleInfo. |
| Dim | Dimensionality of the original distribution. |
| suffix | String appended to histogram names (e.g. to distinguish stages). |
Definition at line 859 of file PredictiveThrower.cpp.
|
private |
Calculate Posterior Predictive $p$-value Compares observed data to toy datasets generated from:
Computes two discrepancy metrics: • Shape+Rate : bin-by-bin likelihood • Rate-only : total event normalization
TODO This can be multithreaded but be careful for Clone!!!
Definition at line 1207 of file PredictiveThrower.cpp.
|
private |
Calculate Posterior Predictive LLH.
Definition at line 1279 of file PredictiveThrower.cpp.
|
private |
Produce Violin style spectra.
Definition at line 732 of file PredictiveThrower.cpp.
| void PredictiveThrower::ProduceToys | ( | ) |
Produce toys by throwing from MCMC.
KS: Names of parameter groups that will not be varied
KS: Index of parameters that will be varied
this store value of parameters sampled from a chain
Definition at line 439 of file PredictiveThrower.cpp.
|
private |
Produce distribution of number of events for each sample.
Definition at line 1493 of file PredictiveThrower.cpp.
|
inlineoverridevirtual |
This is not used in this class.
Implements FitterBase.
Definition at line 53 of file PredictiveThrower.h.
| void PredictiveThrower::RunPredictiveAnalysis | ( | ) |
Main routine responsible for producing posterior predictive distributions and $p$-value.
Definition at line 1013 of file PredictiveThrower.cpp.
|
private |
This set some params to prior value this way you can evaluate errors from subset of errors.
Have ability to not throw legacy matrices
Alternatively vary only selected params
Definition at line 43 of file PredictiveThrower.cpp.
|
private |
|
private |
Setup useful variables etc before stating toy generation.
Let's ask the manager what are the file with covariance matrix
Definition at line 110 of file PredictiveThrower.cpp.
|
private |
Load 1D projections and later produce violin plots for each.
Definition at line 638 of file PredictiveThrower.cpp.
|
private |
Evaluate prior/post predictive distribution for beta parameters (used for evaluating impact MC statistical uncertainty)
ROOT enumerates from 1 while MaCh3 from 0
Definition at line 1337 of file PredictiveThrower.cpp.
|
private |
Study Bayesian Information Criterion (BIC) The BIC is defined as:
\[ \mathrm{BIC} = -2 \log L + k \log(n) \]
where:
Definition at line 1584 of file PredictiveThrower.cpp.
|
private |
KS: Get the Deviance Information Criterion (DIC) The deviance is defined as:
\[ D(\theta) = -2 \log L(\theta) \]
The DIC statistic is then:
\[ \mathrm{DIC} = D(\hat{\theta}) + 2p_D \]
where:
\[ p_D = \bar{D} - D(\hat{\theta}) \]
is the effective number of parameters, and
\[ \bar{D} = E_{\theta|y}[D(\theta)] \]
Definition at line 1620 of file PredictiveThrower.cpp.
|
private |
Information Criterion.
Definition at line 1554 of file PredictiveThrower.cpp.
|
private |
KS: Get the Watanabe-Akaike information criterion (WAIC)
WAIC is a fully Bayesian measure of model fit that estimates the predictive accuracy, taking into account the effective number of parameters in the model.
It is defined as:
\[ \text{WAIC} = -2 \left( \text{lppd} - p_\text{WAIC} \right), \]
where
\[ \text{lppd} = \sum_{i=1}^n \log \left( \frac{1}{S} \sum_{s=1}^S p(y_i \mid \theta_s) \right) \]
is the log pointwise predictive density and
\[ p_\text{WAIC} = \sum_{i=1}^n \text{Var}_{s=1,\dots,S} \left[ \log p(y_i \mid \theta_s) \right] \]
is the effective number of parameters (variance of log-likelihood over posterior samples).
Definition at line 1691 of file PredictiveThrower.cpp.
|
private |
Save histograms for a single MCMC Throw/Toy.
Definition at line 365 of file PredictiveThrower.cpp.
|
private |
Vector of Data histograms.
Definition at line 302 of file PredictiveThrower.h.
|
private |
KS: Use Full LLH or only sample contribution based on discussion with Asher we almost always only want the sample likelihood.
Definition at line 283 of file PredictiveThrower.h.
|
private |
Whether it is Prior or Posterior predictive.
Definition at line 287 of file PredictiveThrower.h.
|
private |
Vector of MC histograms per sample and toy experiment. Indexed as [sample][toy].
Definition at line 310 of file PredictiveThrower.h.
|
private |
Vector of MC histograms.
Definition at line 304 of file PredictiveThrower.h.
|
private |
Pointer to El Generico.
Definition at line 299 of file PredictiveThrower.h.
|
private |
KS: Count total number of model parameters which can be used for stuff like BIC.
Definition at line 285 of file PredictiveThrower.h.
|
private |
Number of toys we are generating analysing.
Definition at line 296 of file PredictiveThrower.h.
|
private |
Penalty term values for each toy by default 0.
Definition at line 318 of file PredictiveThrower.h.
|
private |
Reweighting factors applied for each toy, by default 1.
Definition at line 316 of file PredictiveThrower.h.
|
private |
Handy struct for all sample info.
Definition at line 293 of file PredictiveThrower.h.
|
private |
KS: We have two methods for Poissonian fluctuation.
Definition at line 321 of file PredictiveThrower.h.
|
private |
Number of toys we are generating analysing.
Definition at line 290 of file PredictiveThrower.h.
|
private |
Vector of W² histograms per sample and toy experiment. Indexed as [sample][toy]
Definition at line 313 of file PredictiveThrower.h.
|
private |
Vector of W2 histograms.
Definition at line 306 of file PredictiveThrower.h.