Minuit-RooMinimizer interface which synchronizes parameter data and coordinates evaluation of likelihood (gradient) values.
This class provides an interface between RooFit and Minuit. It synchronizes parameter values from Minuit, calls calculator classes to evaluate likelihood and likelihood gradient values and returns them to Minuit. The Wrapper objects do the actual calculations. These are constructed inside the MinuitFcnGrad constructor using the RooAbsL likelihood passed in to the constructor, usually directly from RooMinimizer, with which this class is intimately coupled, being a RooAbsMinimizerFcn implementation. MinuitFcnGrad inherits from ROOT::Math::IMultiGradFunction as well, which allows it to be used as the FCN and GRAD parameters Minuit expects.
Definition at line 31 of file MinuitFcnGrad.h.
Public Member Functions | |
MinuitFcnGrad (const std::shared_ptr< RooFit::TestStatistics::RooAbsL > &absL, RooMinimizer *context, std::vector< ROOT::Fit::ParameterSettings > ¶meters, LikelihoodMode likelihoodMode, LikelihoodGradientMode likelihoodGradientMode) | |
std::string | getFunctionName () const override |
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class. | |
std::string | getFunctionTitle () const override |
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class. | |
ROOT::Math::IMultiGenFunction * | getMultiGenFcn () override |
void | Gradient (const double *x, double *grad) const |
IMultiGradFunction overrides necessary for Minuit. | |
void | GradientWithPrevResult (const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const |
double | operator() (const double *x) const |
bool | returnsInMinuit2ParameterSpace () const |
void | setOffsetting (bool flag) override |
Enable or disable offsetting on the function to be minimized, which enhances numerical precision. | |
void | setOptimizeConstOnFunction (RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt) override |
This function must be overridden in the derived class to pass on constant term optimization configuration to the function to be minimized. | |
bool | Synchronize (std::vector< ROOT::Fit::ParameterSettings > ¶meter_settings) override |
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization. | |
![]() | |
RooAbsMinimizerFcn (RooArgList paramList, RooMinimizer *context) | |
virtual | ~RooAbsMinimizerFcn ()=default |
RooArgList const & | allParams () const |
void | ApplyCovarianceMatrix (TMatrixDSym &V) |
Set different external covariance matrix. | |
void | BackProp () |
Put Minuit results back into RooFit objects. | |
RooMinimizer::Config const & | cfg () const |
RooArgList | constParams () const |
Int_t | evalCounter () const |
RooRealVar & | floatableParam (std::size_t i) const |
RooArgList | floatParams () const |
std::ofstream * | GetLogFile () |
double & | GetMaxFCN () |
unsigned int | getNDim () const |
Int_t | GetNumInvalidNLL () const |
double & | getOffset () const |
Return a possible offset that's applied to the function to separate invalid function values from valid ones. | |
RooArgList | initFloatParams () const |
bool | SetLogFile (const char *inLogfile) |
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter space. | |
void | setOptimizeConst (Int_t flag) |
bool | SetPdfParamVal (int index, double value) const |
Set value of parameter i. | |
bool | synchronizeParameterSettings (std::vector< ROOT::Fit::ParameterSettings > ¶meters, bool optConst) |
Informs Minuit through its parameter_settings vector of RooFit parameter properties. | |
void | zeroEvalCount () |
Private Member Functions | |
template<class Func > | |
void | applyToLikelihood (Func &&func) const |
void | syncOffsets () const |
Make sure the offsets are up to date. | |
bool | syncParameterValuesFromMinuitCalls (const double *x, bool minuit_internal) const |
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x. | |
Private Attributes | |
bool | _calculatingGradient = false |
std::shared_ptr< WrapperCalculationCleanFlags > | _calculationIsClean |
std::unique_ptr< LikelihoodGradientWrapper > | _gradient |
std::shared_ptr< LikelihoodWrapper > | _likelihood |
std::shared_ptr< LikelihoodWrapper > | _likelihoodInGradient |
std::vector< double > | _minuitExternalX |
bool | _minuitInternalRooFitXMismatch = false |
std::vector< double > | _minuitInternalX |
std::unique_ptr< ROOT::Math::IMultiGradFunction > | _multiGenFcn |
bool | offsets_reset_ = false |
Additional Inherited Members | |
![]() | |
double | applyEvalErrorHandling (double fvalue) const |
Apply corrections on the fvalue if errors were signaled. | |
void | finishDoEval () const |
void | optimizeConstantTerms (bool constStatChange, bool constValChange) |
void | printEvalErrors () const |
Print information about why evaluation failed. | |
![]() | |
static bool | canBeFloating (RooAbsArg const &arg) |
static bool | treatAsConstant (RooAbsArg const &arg) |
![]() | |
RooArgList | _allParams |
RooArgList | _allParamsInit |
RooMinimizer * | _context = nullptr |
int | _evalCounter {0} |
std::vector< std::size_t > | _floatableParamIndices |
double | _funcOffset {0.} |
std::ofstream * | _logfile = nullptr |
double | _maxFCN = -std::numeric_limits<double>::infinity() |
int | _numBadNLL = 0 |
bool | _optConst = false |
#include </github/home/ROOT-CI/src/roofit/roofitcore/src/TestStatistics/MinuitFcnGrad.h>
RooFit::TestStatistics::MinuitFcnGrad::MinuitFcnGrad | ( | const std::shared_ptr< RooFit::TestStatistics::RooAbsL > & | absL, |
RooMinimizer * | context, | ||
std::vector< ROOT::Fit::ParameterSettings > & | parameters, | ||
LikelihoodMode | likelihoodMode, | ||
LikelihoodGradientMode | likelihoodGradientMode ) |
[in] | absL | The input likelihood. |
[in] | context | RooMinimizer that creates and owns this class. |
[in] | parameters | The vector of ParameterSettings objects that describe the parameters used in the Minuit |
[in] | likelihoodMode | Lmode |
[in] | likelihoodGradientMode | Lgrad |
[in] | verbose | true for verbose output Fitter. Note that these must match the set used in the Fitter used by context! It can be passed in from RooMinimizer with fitter()->Config().ParamsSettings(). |
Definition at line 83 of file MinuitFcnGrad.cxx.
|
inlineprivate |
Definition at line 73 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
Implements RooAbsMinimizerFcn.
Definition at line 57 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
RooMinimizer sometimes needs the title of the minimized function. Implement this in the derived class.
Implements RooAbsMinimizerFcn.
Definition at line 59 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
Implements RooAbsMinimizerFcn.
Definition at line 48 of file MinuitFcnGrad.h.
IMultiGradFunction overrides necessary for Minuit.
Definition at line 247 of file MinuitFcnGrad.cxx.
void RooFit::TestStatistics::MinuitFcnGrad::GradientWithPrevResult | ( | const double * | x, |
double * | grad, | ||
double * | previous_grad, | ||
double * | previous_g2, | ||
double * | previous_gstep ) const |
Definition at line 256 of file MinuitFcnGrad.cxx.
Definition at line 135 of file MinuitFcnGrad.cxx.
|
inline |
Definition at line 41 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
Implements RooAbsMinimizerFcn.
Definition at line 61 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
This function must be overridden in the derived class to pass on constant term optimization configuration to the function to be minimized.
For a RooAbsArg, this would be RooAbsArg::constOptimizeTestStatistic.
Implements RooAbsMinimizerFcn.
Definition at line 43 of file MinuitFcnGrad.h.
|
overridevirtual |
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
Reimplemented from RooAbsMinimizerFcn.
Definition at line 266 of file MinuitFcnGrad.cxx.
|
private |
Make sure the offsets are up to date.
If the offsets need to be updated, this function triggers a likelihood evaluation. The likelihood will make sure the offset is set correctly in their shared_ptr offsets object, that is also shared with possible other LikelihoodWrapper members of MinuitFcnGrad and also the LikelihoodGradientWrapper member. Other necessary synchronization steps are also performed from the Wrapper child classes (e.g. sending the values to workers from MultiProcess::Jobs).
Definition at line 127 of file MinuitFcnGrad.cxx.
|
private |
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x.
This function syncs these values to the proper places in RooFit.
The first twist, and reason this function is more complicated than one may imagine, is that Minuit internally uses a transformed parameter space to account for parameter boundaries. Whether we receive these Minuit "internal" parameter values or "regular"/untransformed RooFit parameter space values depends on the situation.
The second twist is that the Minuit external parameters may still be different from the ones used in RooFit. This happens when Minuit tries out values that lay outside the RooFit parameter's range(s). RooFit's setVal (called inside SetPdfParamVal) then clips the RooAbsArg's value to one of the range limits, instead of setting it to the value Minuit intended. When this happens, i.e. syncParameterValuesFromMinuitCalls is called with minuit_internal = false and the values do not match the previous values stored in _minuitInternalX but the values after SetPdfParamVal did not get set to the intended value, the _minuitInternalRooFitXMismatch flag is set. This information can be used by calculators, if desired, for instance when a calculator does not want to make use of the range information in the RooAbsArg parameters.
Definition at line 197 of file MinuitFcnGrad.cxx.
Definition at line 86 of file MinuitFcnGrad.h.
|
mutableprivate |
Definition at line 88 of file MinuitFcnGrad.h.
|
private |
Definition at line 85 of file MinuitFcnGrad.h.
|
private |
Definition at line 83 of file MinuitFcnGrad.h.
|
private |
Definition at line 84 of file MinuitFcnGrad.h.
|
mutableprivate |
Definition at line 91 of file MinuitFcnGrad.h.
Definition at line 99 of file MinuitFcnGrad.h.
|
mutableprivate |
Definition at line 90 of file MinuitFcnGrad.h.
|
private |
Definition at line 97 of file MinuitFcnGrad.h.
Definition at line 94 of file MinuitFcnGrad.h.