Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
LikelihoodGradientWrapper.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_LikelihoodGradientWrapper
14#define ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper
15
17#include <Math/IFunctionfwd.h>
19
20#include <vector>
21#include <memory> // shared_ptr
22
23// forward declaration
24class RooMinimizer;
25
26namespace RooFit {
27namespace TestStatistics {
28
29// forward declaration
30class RooAbsL;
31struct WrapperCalculationCleanFlags;
32
34
36public:
37 LikelihoodGradientWrapper(std::shared_ptr<RooAbsL> likelihood,
38 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, std::size_t N_dim,
39 RooMinimizer *minimizer);
40 virtual ~LikelihoodGradientWrapper() = default;
41 virtual LikelihoodGradientWrapper *clone() const = 0;
42
43 static std::unique_ptr<LikelihoodGradientWrapper>
44 create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr<RooAbsL> likelihood,
45 std::shared_ptr<WrapperCalculationCleanFlags> calculationIsClean, std::size_t nDim, RooMinimizer *minimizer);
46
47 virtual void fillGradient(double *grad) = 0;
48 virtual void
49 fillGradientWithPrevResult(double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) = 0;
50
51 /// Synchronize minimizer settings with calculators in child classes.
52 virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options);
53 virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> &parameter_settings);
55 const std::vector<ROOT::Fit::ParameterSettings> &parameter_settings) = 0;
56 /// Minuit passes in parameter values that may not conform to RooFit internal standards (like applying range
57 /// clipping), but that the specific calculator does need. This function can be implemented to receive these
58 /// Minuit-internal values.
59 virtual void updateMinuitInternalParameterValues(const std::vector<double> &minuit_internal_x);
60 virtual void updateMinuitExternalParameterValues(const std::vector<double> &minuit_external_x);
61
62 /// \brief Implement usesMinuitInternalValues to return true when you want Minuit to send this class Minuit-internal
63 /// values, or return false when you want "regular" Minuit-external values.
64 ///
65 /// Minuit internally uses a transformed parameter space to graciously handle externally mandated parameter range
66 /// boundaries. Transformation from Minuit-internal to external (i.e. "regular") parameters is done using
67 /// trigonometric functions that in some cases can cause a few bits of precision loss with respect to the original
68 /// parameter values. To circumvent this, Minuit also allows external gradient providers (like
69 /// LikelihoodGradientWrapper) to take the Minuit-internal parameter values directly, without transformation. This
70 /// way, the gradient provider (e.g. the implementation of this class) can handle transformation manually, possibly
71 /// with higher precision.
72 virtual bool usesMinuitInternalValues() = 0;
73
74 /// Reports whether or not the gradient is currently being calculated.
75 ///
76 /// This is used in MinuitFcnGrad to switch between LikelihoodWrapper implementations
77 /// inside and outside of a LikelihoodGradientJob calculation when the LikelihoodWrapper
78 /// used is LikelihoodJob. This is to prevent Jobs from being started within Jobs.
79 virtual bool isCalculating() = 0;
80
81protected:
82 std::shared_ptr<RooAbsL> likelihood_;
84 std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_;
85};
86
87} // namespace TestStatistics
88} // namespace RooFit
89
90#endif // ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Virtual base class for implementation of likelihood gradient calculation strategies.
virtual bool usesMinuitInternalValues()=0
Implement usesMinuitInternalValues to return true when you want Minuit to send this class Minuit-inte...
virtual bool isCalculating()=0
Reports whether or not the gradient is currently being calculated.
std::shared_ptr< WrapperCalculationCleanFlags > calculation_is_clean_
virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options)
Synchronize minimizer settings with calculators in child classes.
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 synchronizeParameterSettings(ROOT::Math::IMultiGenFunction *function, const std::vector< ROOT::Fit::ParameterSettings > &parameter_settings)=0
static std::unique_ptr< LikelihoodGradientWrapper > create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, std::size_t nDim, RooMinimizer *minimizer)
Factory method.
virtual void synchronizeParameterSettings(const std::vector< ROOT::Fit::ParameterSettings > &parameter_settings)
virtual void fillGradientWithPrevResult(double *grad, double *previous_grad, double *previous_g2, double *previous_gstep)=0
virtual void updateMinuitExternalParameterValues(const std::vector< double > &minuit_external_x)
virtual LikelihoodGradientWrapper * clone() const =0
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26