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
22#include <Math/Util.h>
23
24#include <memory> // shared_ptr
25#include <string>
26
27// forward declaration
28class RooMinimizer;
29
30namespace RooFit {
31namespace TestStatistics {
32
33// forward declaration
34class RooAbsL;
35
36/// For communication with wrappers, an instance of this struct must be shared between them and MinuitFcnGrad. It keeps
37/// track of what has been evaluated for the current parameter set provided by Minuit.
39 // indicate whether that part has been calculated since the last parameter update
40 bool likelihood = false;
41 bool gradient = false;
42
43 void set_all(bool value)
44 {
47 }
48};
49
51
53
54/// Previously, offsetting was only implemented for RooNLLVar components of a likelihood,
55/// not for RooConstraintSum terms. To emulate this behavior, use OffsettingMode::legacy. To
56/// also offset the RooSubsidiaryL component (equivalent of RooConstraintSum) of RooSumL
57/// likelihoods, use OffsettingMode::full.
58enum class OffsettingMode { legacy, full };
59
61protected:
62 LikelihoodWrapper(std::shared_ptr<RooAbsL> likelihood,
63 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, SharedOffset offset);
64
65public:
66 virtual ~LikelihoodWrapper() = default;
69
70 static std::unique_ptr<LikelihoodWrapper> create(LikelihoodMode likelihoodMode, std::shared_ptr<RooAbsL> likelihood,
71 std::shared_ptr<WrapperCalculationCleanFlags> calculationIsClean,
73
74 /// \brief Triggers (possibly asynchronous) evaluation of the likelihood
75 ///
76 /// In parallel strategies, it may be advantageous to allow a calling process to continue on with other tasks while
77 /// the calculation is offloaded to another process or device, like a GPU. For this reason, evaluate() does not
78 /// return the result, this is done in getResult().
79 virtual void evaluate() = 0;
80 /// \brief Return the latest result of a likelihood evaluation.
81 ///
82 /// Returns the result that was stored after calling evaluate(). It is up to the implementer to make sure the stored
83 /// value represents the most recent evaluation call, e.g. by using a mutex.
85
86 /// Synchronize minimizer settings with calculators in child classes
87 virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options);
88 virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> &parameter_settings);
89 /// Minuit passes in parameter values that may not conform to RooFit internal standards (like applying range
90 /// clipping), but that the specific calculator does need. This function can be implemented to receive these
91 /// Minuit-internal values:
92 virtual void updateMinuitInternalParameterValues(const std::vector<double> &minuit_internal_x);
93 virtual void updateMinuitExternalParameterValues(const std::vector<double> &minuit_external_x);
94
95 // The following functions are necessary from MinuitFcnGrad to reach likelihood properties:
96 double defaultErrorLevel() const;
97 virtual std::string GetName() const;
98 virtual std::string GetTitle() const;
99 inline virtual bool isOffsetting() const { return do_offset_; }
100 virtual void enableOffsetting(bool flag);
102 void setApplyWeightSquared(bool flag);
103
104protected:
105 std::shared_ptr<RooAbsL> likelihood_;
107 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_;
108
109 bool do_offset_ = false;
111 void calculate_offsets();
113};
114
115} // namespace TestStatistics
116} // namespace RooFit
117
118#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:141
Virtual base class for implementation of likelihood calculation strategies.
virtual void synchronizeParameterSettings(const std::vector< ROOT::Fit::ParameterSettings > &parameter_settings)
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.
LikelihoodWrapper(std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean, SharedOffset offset)
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::Math::Minimizer that provides a seamless interface between the minimizer f...
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 CodegenImpl.h:73
For communication with wrappers, an instance of this struct must be shared between them and MinuitFcn...