Adapter class to wrap user-provided functions into the FCNBase interface.
This class allows users to supply their function (and optionally its gradient, diagonal second derivatives, and Hessian) in the form of std::function
objects. It adapts these functions so that they can be used transparently with the MINUIT minimizers via the FCNBase
interface.
Typical usage:
Definition at line 37 of file FCNAdapter.h.
Public Member Functions | |
FCNAdapter (std::function< double(double const *)> f, double up=1.) | |
Construct an adapter around a user-provided function. | |
std::vector< double > | G2 (std::vector< double > const &x) const override |
Return the diagonal elements of the Hessian (second derivatives). | |
std::vector< double > | Gradient (std::vector< double > const &v) const override |
Evaluate the gradient of the function at the given parameter vector. | |
bool | HasG2 () const override |
Indicate whether analytic second derivatives (diagonal of the Hessian) are available. | |
bool | HasGradient () const override |
Indicate whether an analytic gradient has been provided. | |
bool | HasHessian () const override |
Indicate whether an analytic Hessian has been provided. | |
std::vector< double > | Hessian (std::vector< double > const &x) const override |
Return the full Hessian matrix. | |
double | operator() (std::vector< double > const &v) const override |
Evaluate the function at the given parameter vector. | |
void | SetErrorDef (double up) override |
Update the error definition parameter. | |
void | SetG2Function (std::function< std::vector< double >(std::vector< double > const &)> f) |
Set the function providing diagonal second derivatives (G2). | |
void | SetGradientFunction (std::function< void(double const *, double *)> f) |
Set the analytic gradient function. | |
void | SetHessianFunction (std::function< bool(std::vector< double > const &, double *)> f) |
Set the function providing the full Hessian matrix. | |
double | Up () const override |
Return the error definition parameter (up ). | |
![]() | |
virtual | ~FCNBase ()=default |
virtual double | ErrorDef () const |
Error definition of the function. | |
virtual std::vector< double > | GradientWithPrevResult (std::vector< double > const ¶meters, double *, double *, double *) const |
virtual GradientParameterSpace | gradParameterSpace () const |
Private Types | |
using | Function = std::function<double(double const *)> |
using | G2Function = std::function<std::vector<double>(std::vector<double> const &)> |
using | GradFunction = std::function<void(double const *, double *)> |
using | HessianFunction = std::function<bool(std::vector<double> const &, double *)> |
Private Attributes | |
Function | fFunc |
Wrapped function to minimize. | |
G2Function | fG2Func |
Optional diagonal second-derivative function. | |
GradFunction | fGradFunc |
Optional gradient function. | |
std::vector< double > | fHessian |
Storage for intermediate Hessian values. | |
HessianFunction | fHessianFunc |
Optional Hessian function. | |
double | fUp = 1. |
Error definition parameter. | |
#include <Minuit2/FCNAdapter.h>
|
private |
Definition at line 164 of file FCNAdapter.h.
|
private |
Definition at line 166 of file FCNAdapter.h.
|
private |
Definition at line 165 of file FCNAdapter.h.
|
private |
Definition at line 167 of file FCNAdapter.h.
|
inline |
Construct an adapter around a user-provided function.
f | Function to minimize. It must take a pointer to the parameter array (double const* ) and return the function value. |
up | Error definition parameter (defaults to 1.0). |
Definition at line 45 of file FCNAdapter.h.
|
inlineoverridevirtual |
Return the diagonal elements of the Hessian (second derivatives).
If a G2 function is set, it is used directly. If only a Hessian function is available, the diagonal is extracted from the full Hessian.
x | Parameter vector. |
Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 91 of file FCNAdapter.h.
|
inlineoverridevirtual |
Evaluate the gradient of the function at the given parameter vector.
v | Parameter vector. |
Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 77 of file FCNAdapter.h.
|
inlineoverridevirtual |
Indicate whether analytic second derivatives (diagonal of the Hessian) are available.
true
if a G2 function or a Hessian function has been set, otherwise false
. Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 55 of file FCNAdapter.h.
|
inlineoverridevirtual |
Indicate whether an analytic gradient has been provided.
true
if a gradient function was set, otherwise false
. Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 50 of file FCNAdapter.h.
|
inlineoverridevirtual |
Indicate whether an analytic Hessian has been provided.
true
if a Hessian function was set, otherwise false
. Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 60 of file FCNAdapter.h.
|
inlineoverridevirtual |
Return the full Hessian matrix.
If a Hessian function is available, it is used to fill the matrix. If the Hessian function fails, it is cleared and not used again.
x | Parameter vector. |
Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 118 of file FCNAdapter.h.
|
inlineoverridevirtual |
Evaluate the function at the given parameter vector.
v | Parameter vector. |
Implements ROOT::Minuit2::FCNBase.
Definition at line 66 of file FCNAdapter.h.
|
inlineoverridevirtual |
Update the error definition parameter.
up | New error definition value. |
Reimplemented from ROOT::Minuit2::FCNBase.
Definition at line 161 of file FCNAdapter.h.
|
inline |
Set the function providing diagonal second derivatives (G2).
f | Function taking a parameter vector and returning the diagonal of the Hessian matrix as a vector. |
Definition at line 145 of file FCNAdapter.h.
|
inline |
Set the analytic gradient function.
f | Gradient function of type void(double const*, double*) . The first argument is the parameter array, the second is the output array for the gradient values. |
Definition at line 139 of file FCNAdapter.h.
|
inline |
Set the function providing the full Hessian matrix.
f | Function of type bool(std::vector<double> const&, double*) . The first argument is the parameter vector, the second is the output buffer (flattened matrix). The return value should be true on success, false on failure. |
Definition at line 153 of file FCNAdapter.h.
|
inlineoverridevirtual |
Return the error definition parameter (up
).
Implements ROOT::Minuit2::FCNBase.
Definition at line 71 of file FCNAdapter.h.
|
private |
Wrapped function to minimize.
Definition at line 172 of file FCNAdapter.h.
|
private |
Optional diagonal second-derivative function.
Definition at line 174 of file FCNAdapter.h.
|
private |
Optional gradient function.
Definition at line 173 of file FCNAdapter.h.
|
mutableprivate |
Storage for intermediate Hessian values.
Definition at line 170 of file FCNAdapter.h.
|
mutableprivate |
Optional Hessian function.
Definition at line 175 of file FCNAdapter.h.
|
private |
Error definition parameter.
Definition at line 169 of file FCNAdapter.h.