Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LikelihoodWrapper.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
5 *
6 * Copyright (c) 2021, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef ROOT_ROOFIT_TESTSTATISTICS_LikelihoodWrapper
14#define ROOT_ROOFIT_TESTSTATISTICS_LikelihoodWrapper
15
17
18#include "RooArgSet.h"
19#include "RooAbsArg.h" // enum ConstOpCode
20
23#include <Math/Util.h>
24
25#include <memory> // shared_ptr
26#include <string>
27
28// forward declaration
29class RooMinimizer;
30
31namespace RooFit {
32namespace TestStatistics {
33
34// forward declaration
35class RooAbsL;
36
37/// For communication with wrappers, an instance of this struct must be shared between them and MinuitFcnGrad. It keeps
38/// track of what has been evaluated for the current parameter set provided by Minuit.
40 // indicate whether that part has been calculated since the last parameter update
41 bool likelihood = false;
42 bool gradient = false;
43
44 void set_all(bool value)
45 {
48 }
49};
50
52
54
55/// Previously, offsetting was only implemented for RooNLLVar components of a likelihood,
56/// not for RooConstraintSum terms. To emulate this behavior, use OffsettingMode::legacy. To
57/// also offset the RooSubsidiaryL component (equivalent of RooConstraintSum) of RooSumL
58/// likelihoods, use OffsettingMode::full.
59enum class OffsettingMode { legacy, full };
60
62protected:
63 LikelihoodWrapper(std::shared_ptr<RooAbsL> likelihood,
64 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, SharedOffset offset);
65
66public:
67 virtual ~LikelihoodWrapper() = default;
70
71 static std::unique_ptr<LikelihoodWrapper> create(LikelihoodMode likelihoodMode, std::shared_ptr<RooAbsL> likelihood,
72 std::shared_ptr<WrapperCalculationCleanFlags> calculationIsClean,
74
75 /// \brief Triggers (possibly asynchronous) evaluation of the likelihood
76 ///
77 /// In parallel strategies, it may be advantageous to allow a calling process to continue on with other tasks while
78 /// the calculation is offloaded to another process or device, like a GPU. For this reason, evaluate() does not
79 /// return the result, this is done in getResult().
80 virtual void evaluate() = 0;
81 /// \brief Return the latest result of a likelihood evaluation.
82 ///
83 /// Returns the result that was stored after calling evaluate(). It is up to the implementer to make sure the stored
84 /// value represents the most recent evaluation call, e.g. by using a mutex.
86
87 /// Synchronize minimizer settings with calculators in child classes
88 virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options);
89 virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> &parameter_settings);
90 /// Minuit passes in parameter values that may not conform to RooFit internal standards (like applying range
91 /// clipping), but that the specific calculator does need. This function can be implemented to receive these
92 /// Minuit-internal values:
93 virtual void updateMinuitInternalParameterValues(const std::vector<double> &minuit_internal_x);
94 virtual void updateMinuitExternalParameterValues(const std::vector<double> &minuit_external_x);
95
96 // The following functions are necessary from MinuitFcnGrad to reach likelihood properties:
97 void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt);
98 double defaultErrorLevel() const;
99 virtual std::string GetName() const;
100 virtual std::string GetTitle() const;
101 inline virtual bool isOffsetting() const { return do_offset_; }
102 virtual void enableOffsetting(bool flag);
104 void setApplyWeightSquared(bool flag);
105
106protected:
107 std::shared_ptr<RooAbsL> likelihood_;
109 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_;
110
111 bool do_offset_ = false;
113 void calculate_offsets();
115};
116
117} // namespace TestStatistics
118} // namespace RooFit
119
120#endif // ROOT_ROOFIT_TESTSTATISTICS_LikelihoodWrapper
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char mode
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
Virtual base class for implementation of likelihood calculation strategies.
virtual void synchronizeParameterSettings(const std::vector< ROOT::Fit::ParameterSettings > &parameter_settings)
void constOptimizeTestStatistic(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt)
LikelihoodWrapper & operator=(const LikelihoodWrapper &)=delete
LikelihoodWrapper(const LikelihoodWrapper &)=delete
virtual void updateMinuitExternalParameterValues(const std::vector< double > &minuit_external_x)
virtual void updateMinuitInternalParameterValues(const std::vector< double > &minuit_internal_x)
Minuit passes in parameter values that may not conform to RooFit internal standards (like applying ra...
void calculate_offsets()
(Re)calculate (on each worker) all component offsets.
static std::unique_ptr< LikelihoodWrapper > create(LikelihoodMode likelihoodMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, SharedOffset offset)
Factory method.
virtual void evaluate()=0
Triggers (possibly asynchronous) evaluation of the likelihood.
virtual ROOT::Math::KahanSum< double > getResult() const =0
Return the latest result of a likelihood evaluation.
virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options)
Synchronize minimizer settings with calculators in child classes.
std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean_
Wrapper class around ROOT::Fit:Fitter that provides a seamless interface between the minimizer functi...
OffsettingMode
Previously, offsetting was only implemented for RooNLLVar components of a likelihood,...
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26
For communication with wrappers, an instance of this struct must be shared between them and MinuitFcn...