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 34 of file MinuitFcnGrad.h.
Public Member Functions | |
MinuitFcnGrad (const std::shared_ptr< RooFit::TestStatistics::RooAbsL > &_likelihood, RooMinimizer *context, std::vector< ROOT::Fit::ParameterSettings > ¶meters, LikelihoodMode likelihoodMode, LikelihoodGradientMode likelihoodGradientMode, bool verbose=false) | |
ROOT::Math::IMultiGradFunction * | Clone () const override |
Clone a function. | |
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. | |
void | Gradient (const double *x, double *grad) const override |
IMultiGradFunction overrides necessary for Minuit. | |
void | GradientWithPrevResult (const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const override |
unsigned int | NDim () const override |
Part of IMultiGradFunction interface, used widely both in Minuit and in RooFit. | |
bool | returnsInMinuit2ParameterSpace () const override |
void | setOffsetting (Bool_t flag) override |
Enable or disable offsetting on the function to be minimized, which enhances numerical precision. | |
void | setOptimizeConstOnFunction (RooAbsArg::ConstOpCode opcode, Bool_t 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_t | Synchronize (std::vector< ROOT::Fit::ParameterSettings > ¶meter_settings, Bool_t optConst, Bool_t verbose=kFALSE) override |
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization. | |
![]() | |
virtual | ~IGradientFunctionMultiDimTempl () |
Virtual Destructor (no operations) | |
virtual void | FdF (const T *x, T &f, T *df) const |
Optimized method to evaluate at the same time the function value and derivative at a point x. | |
virtual void | Gradient (const T *x, T *grad) const |
Evaluate all the vector of function derivatives (gradient) at a point x. | |
virtual void | GradientWithPrevResult (const T *x, T *grad, T *previous_grad, T *previous_g2, T *previous_gstep) const |
In some cases, the gradient algorithm will use information from the previous step, these can be passed in with this overload. | |
![]() | |
IBaseFunctionMultiDimTempl () | |
virtual | ~IBaseFunctionMultiDimTempl () |
virtual destructor | |
T | operator() (const T *x) const |
Evaluate the function at a point x[]. | |
![]() | |
virtual | ~IGradientMultiDimTempl () |
virual destructor | |
T | Derivative (const T *x, unsigned int icoord, T *previous_grad, T *previous_g2, T *previous_gstep) const |
In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload. | |
T | Derivative (const T *x, unsigned int icoord=0) const |
Return the partial derivative with respect to the passed coordinate. | |
![]() | |
RooAbsMinimizerFcn (const RooAbsMinimizerFcn &other) | |
RooAbsMinimizerFcn (RooArgList paramList, RooMinimizer *context, bool verbose=false) | |
virtual | ~RooAbsMinimizerFcn ()=default |
void | ApplyCovarianceMatrix (TMatrixDSym &V) |
Set different external covariance matrix. | |
void | BackProp (const ROOT::Fit::FitResult &results) |
Put Minuit results back into RooFit objects. | |
Int_t | evalCounter () const |
RooArgList * | GetConstParamList () |
RooArgList * | GetFloatParamList () |
Logistics. | |
RooArgList * | GetInitConstParamList () |
RooArgList * | GetInitFloatParamList () |
std::ofstream * | GetLogFile () |
Double_t & | 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. | |
bool | getOptConst () |
std::vector< double > | getParameterValues () const |
unsigned int | NDim () const |
void | SetEvalErrorWall (Bool_t flag) |
Bool_t | 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_t | SetPdfParamVal (int index, double value) const |
Set value of parameter i. | |
void | SetPrintEvalErrors (Int_t numEvalErrors) |
void | SetRecoverFromNaNStrength (double strength) |
Try to recover from invalid function values. | |
void | SetVerbose (Bool_t flag=kTRUE) |
Bool_t | synchronizeParameterSettings (std::vector< ROOT::Fit::ParameterSettings > ¶meters, Bool_t optConst, Bool_t verbose) |
Informs Minuit through its parameter_settings vector of RooFit parameter properties. | |
void | zeroEvalCount () |
Public Attributes | |
std::shared_ptr< WrapperCalculationCleanFlags > | calculation_is_clean |
bool | minuit_internal_roofit_x_mismatch_ = false |
Private Member Functions | |
double | DoDerivative (const double *x, unsigned int icoord) const override |
This override should not be used in this class, so it throws. | |
double | DoEval (const double *x) const override |
IMultiGradFunction override necessary for Minuit. | |
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 | |
std::shared_ptr< LikelihoodGradientWrapper > | gradient |
std::shared_ptr< LikelihoodWrapper > | likelihood |
std::vector< double > | minuit_external_x_ |
std::vector< double > | minuit_internal_x_ |
Additional Inherited Members | |
![]() | |
typedef IBaseFunctionMultiDimTempl< T > | BaseFunc |
typedef IGradientMultiDimTempl< T > | BaseGrad |
![]() | |
typedef T | BackendType |
typedef IBaseFunctionMultiDimTempl< T > | BaseFunc |
![]() | |
void | ClearPdfParamAsymErr (Int_t index) |
Modify PDF parameter error by ordinal index (needed by MINUIT) | |
void | optimizeConstantTerms (bool constStatChange, bool constValChange) |
void | printEvalErrors () const |
Print information about why evaluation failed. | |
void | SetPdfParamErr (Int_t index, Double_t loVal, Double_t hiVal) |
Modify PDF parameter error by ordinal index (needed by MINUIT) | |
void | SetPdfParamErr (Int_t index, Double_t value) |
Modify PDF parameter error by ordinal index (needed by MINUIT) | |
![]() | |
std::unique_ptr< RooArgList > | _constParamList |
RooMinimizer * | _context |
bool | _doEvalErrorWall {true} |
int | _evalCounter {0} |
std::unique_ptr< RooArgList > | _floatParamList |
double | _funcOffset {0.} |
std::unique_ptr< RooArgList > | _initConstParamList |
std::unique_ptr< RooArgList > | _initFloatParamList |
std::ofstream * | _logfile = nullptr |
double | _maxFCN = -std::numeric_limits<double>::infinity() |
unsigned int | _nDim = 0 |
int | _numBadNLL = 0 |
Bool_t | _optConst = kFALSE |
int | _printEvalErrors = 10 |
double | _recoverFromNaNStrength {10.} |
bool | _verbose |
RooFit::TestStatistics::MinuitFcnGrad::MinuitFcnGrad | ( | const std::shared_ptr< RooFit::TestStatistics::RooAbsL > & | _likelihood, |
RooMinimizer * | context, | ||
std::vector< ROOT::Fit::ParameterSettings > & | parameters, | ||
LikelihoodMode | likelihoodMode, | ||
LikelihoodGradientMode | likelihoodGradientMode, | ||
bool | verbose = false |
||
) |
[in] | context | RooMinimizer that creates and owns this class. |
[in] | parameters | The vector of ParameterSettings objects that describe the parameters used in the Minuit 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 44 of file MinuitFcnGrad.cxx.
|
inlineoverridevirtual |
Clone a function.
Each derived class must implement their version of the Clone method
Implements ROOT::Math::IBaseFunctionMultiDimTempl< T >.
Definition at line 40 of file MinuitFcnGrad.h.
|
overrideprivate |
This override should not be used in this class, so it throws.
Definition at line 234 of file MinuitFcnGrad.cxx.
IMultiGradFunction override necessary for Minuit.
Definition at line 67 of file MinuitFcnGrad.cxx.
|
inlineoverridevirtual |
RooMinimizer sometimes needs the name of the minimized function. Implement this in the derived class.
Implements RooAbsMinimizerFcn.
Definition at line 67 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 69 of file MinuitFcnGrad.h.
|
override |
IMultiGradFunction overrides necessary for Minuit.
Definition at line 221 of file MinuitFcnGrad.cxx.
|
override |
Definition at line 227 of file MinuitFcnGrad.cxx.
|
inlineoverridevirtual |
Part of IMultiGradFunction interface, used widely both in Minuit and in RooFit.
Reimplemented from ROOT::Math::IGradientFunctionMultiDimTempl< T >.
Definition at line 65 of file MinuitFcnGrad.h.
|
inlineoverridevirtual |
Reimplemented from ROOT::Math::IGradientFunctionMultiDimTempl< T >.
Definition at line 47 of file MinuitFcnGrad.h.
Enable or disable offsetting on the function to be minimized, which enhances numerical precision.
Implements RooAbsMinimizerFcn.
Definition at line 71 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 49 of file MinuitFcnGrad.h.
|
overridevirtual |
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
Reimplemented from RooAbsMinimizerFcn.
Definition at line 240 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 minuit_internal_x_ but the values after SetPdfParamVal did not get set to the intended value, the minuit_internal_roofit_x_mismatch_ 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 171 of file MinuitFcnGrad.cxx.
|
mutable |
Definition at line 84 of file MinuitFcnGrad.h.
|
private |
Definition at line 81 of file MinuitFcnGrad.h.
|
private |
Definition at line 80 of file MinuitFcnGrad.h.
|
mutableprivate |
Definition at line 88 of file MinuitFcnGrad.h.
|
mutable |
Definition at line 91 of file MinuitFcnGrad.h.
|
mutableprivate |
Definition at line 87 of file MinuitFcnGrad.h.