-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
LikelihoodGradientWrapper.h
71 lines (58 loc) · 3.32 KB
/
LikelihoodGradientWrapper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Project: RooFit
* Authors:
* PB, Patrick Bos, Netherlands eScience Center, p.bos@esciencecenter.nl
*
* Copyright (c) 2021, CERN
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted according to the terms
* listed in LICENSE (http://roofit.sourceforge.net/license.txt)
*/
#ifndef ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper
#define ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper
#include <Fit/ParameterSettings.h>
#include <Math/IFunctionfwd.h>
#include "Math/MinimizerOptions.h"
#include <vector>
#include <memory> // shared_ptr
// forward declaration
class RooMinimizer;
namespace RooFit {
namespace TestStatistics {
// forward declaration
class RooAbsL;
struct WrapperCalculationCleanFlags;
class LikelihoodGradientWrapper {
public:
LikelihoodGradientWrapper(std::shared_ptr<RooAbsL> likelihood, std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean, std::size_t N_dim, RooMinimizer* minimizer);
virtual ~LikelihoodGradientWrapper() = default;
virtual LikelihoodGradientWrapper* clone() const = 0;
virtual void fillGradient(double *grad) = 0;
virtual void
fillGradientWithPrevResult(double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) = 0;
/// Synchronize minimizer settings with calculators in child classes.
virtual void synchronizeWithMinimizer(const ROOT::Math::MinimizerOptions &options);
virtual void synchronizeParameterSettings(const std::vector<ROOT::Fit::ParameterSettings> ¶meter_settings);
virtual void synchronizeParameterSettings(ROOT::Math::IMultiGenFunction* function, const std::vector<ROOT::Fit::ParameterSettings> ¶meter_settings) = 0;
/// Minuit passes in parameter values that may not conform to RooFit internal standards (like applying range clipping),
/// but that the specific calculator does need. This function can be implemented to receive these Minuit-internal values.
virtual void updateMinuitInternalParameterValues(const std::vector<double>& minuit_internal_x);
virtual void updateMinuitExternalParameterValues(const std::vector<double>& minuit_external_x);
/// \brief Implement usesMinuitInternalValues to return true when you want Minuit to send this class Minuit-internal values, or return false when you want "regular" Minuit-external values.
///
/// Minuit internally uses a transformed parameter space to graciously handle externally mandated parameter range
/// boundaries. Transformation from Minuit-internal to external (i.e. "regular") parameters is done using
/// trigonometric functions that in some cases can cause a few bits of precision loss with respect to the original
/// parameter values. To circumvent this, Minuit also allows external gradient providers (like LikelihoodGradientWrapper)
/// to take the Minuit-internal parameter values directly, without transformation. This way, the gradient provider
/// (e.g. the implementation of this class) can handle transformation manually, possibly with higher precision.
virtual bool usesMinuitInternalValues() = 0;
protected:
std::shared_ptr<RooAbsL> likelihood_;
RooMinimizer * minimizer_;
std::shared_ptr<WrapperCalculationCleanFlags> calculation_is_clean_;
};
} // namespace TestStatistics
} // namespace RooFit
#endif // ROOT_ROOFIT_TESTSTATISTICS_LikelihoodGradientWrapper