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