23namespace TestStatistics {
30 MinuitGradFunctor(MinuitFcnGrad
const &fcn) :
_fcn{fcn} {}
34 unsigned int NDim()
const override {
return _fcn.NDim(); }
36 void Gradient(
const double *
x,
double *grad)
const override {
return _fcn.Gradient(
x, grad); }
38 void GradientWithPrevResult(
const double *
x,
double *grad,
double *previous_grad,
double *previous_g2,
39 double *previous_gstep)
const override
41 return _fcn.GradientWithPrevResult(
x, grad, previous_grad, previous_g2, previous_gstep);
44 bool returnsInMinuit2ParameterSpace()
const override {
return _fcn.returnsInMinuit2ParameterSpace(); }
47 double DoEval(
const double *
x)
const override {
return _fcn(
x); }
49 double DoDerivative(
double const * ,
unsigned int )
const override
51 throw std::runtime_error(
"MinuitGradFunctor::DoDerivative is not implemented, please use Gradient instead.");
84 std::vector<ROOT::Fit::ParameterSettings> ¶meters,
LikelihoodMode likelihoodMode,
87 _minuitInternalX(NDim(), 0),
88 _minuitExternalX(NDim(), 0),
89 _multiGenFcn{std::make_unique<MinuitGradFunctor>(*this)}
143 likelihoodHere.evaluate();
144 double fvalue = likelihoodHere.getResult().Sum();
151 std::cout <<
"\nprevFCN" << (likelihoodHere.isOffsetting() ?
"-offset" :
"") <<
" = " << std::setprecision(10)
152 << fvalue << std::setprecision(4) <<
" ";
199 bool aParamWasUpdated =
false;
200 if (minuit_internal) {
202 throw std::logic_error(
"Updating Minuit-internal parameters only makes sense for (gradient) calculators that "
203 "are defined in Minuit-internal parameter space.");
206 for (std::size_t ix = 0; ix <
NDim(); ++ix) {
208 if (parameter_changed) {
211 aParamWasUpdated |= parameter_changed;
214 if (aParamWasUpdated) {
220 bool aParamIsMismatched =
false;
222 for (std::size_t ix = 0; ix <
NDim(); ++ix) {
232 aParamWasUpdated |= parameter_changed;
233 aParamIsMismatched |=
239 if (aParamWasUpdated) {
245 return aParamWasUpdated;
258 double *previous_gstep)
const
263 _gradient->fillGradientWithPrevResult(grad, previous_grad, previous_g2, previous_gstep);
271 _gradient->synchronizeParameterSettings(parameters);
MinuitFcnGrad const & _fcn
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
const FitConfig & Config() const
access to the fit configuration (const method)
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
std::unique_ptr< RooArgList > _floatParamList
double applyEvalErrorHandling(double fvalue) const
Apply corrections on the fvalue if errors were signaled.
RooMinimizer::Config const & cfg() const
void finishDoEval() const
bool synchronizeParameterSettings(std::vector< ROOT::Fit::ParameterSettings > ¶meters, bool optConst)
Informs Minuit through its parameter_settings vector of RooFit parameter properties.
unsigned int NDim() const
bool SetPdfParamVal(int index, double value) const
Set value of parameter i.
unsigned int getNDim() const
static std::unique_ptr< LikelihoodGradientWrapper > create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, std::size_t nDim, RooMinimizer *minimizer, SharedOffset offset)
Factory method.
static std::unique_ptr< LikelihoodWrapper > create(LikelihoodMode likelihoodMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, SharedOffset offset)
Factory method.
void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const
double operator()(const double *x) const
bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > ¶meter_settings) override
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
void Gradient(const double *x, double *grad) const
IMultiGradFunction overrides necessary for Minuit.
std::vector< double > _minuitInternalX
std::shared_ptr< LikelihoodWrapper > _likelihood
ROOT::Math::IMultiGenFunction * getMultiGenFcn() override
bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x.
bool _minuitInternalRooFitXMismatch
std::unique_ptr< LikelihoodGradientWrapper > _gradient
void syncOffsets() const
Make sure the offsets are up to date.
std::shared_ptr< WrapperCalculationCleanFlags > _calculationIsClean
bool _calculatingGradient
std::vector< double > _minuitExternalX
std::shared_ptr< LikelihoodWrapper > _likelihoodInGradient
void applyToLikelihood(Func &&func) const
MinuitFcnGrad(const std::shared_ptr< RooFit::TestStatistics::RooAbsL > &absL, RooMinimizer *context, std::vector< ROOT::Fit::ParameterSettings > ¶meters, LikelihoodMode likelihoodMode, LikelihoodGradientMode likelihoodGradientMode)
bool returnsInMinuit2ParameterSpace() const
Wrapper class around ROOT::Fit:Fitter that provides a seamless interface between the minimizer functi...
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
Variable that can be changed from the outside.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...