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