Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches

GradFunctor class for Multidimensional gradient functions.

It is used to wrap in a very C++ callable object to make gradient functions. It can be constructed in three different way:

  1. from an object implementing both double operator()( const double * ) for the function evaluation and double Derivative(const double *, int icoord) for the partial derivatives
  2. from an object implementing any member function like Foo::XXX(const double *) for the function evaluation and any member function like Foo::XXX(const double *, int icoord) for the partial derivatives
  3. from two function objects implementing double operator()( const double * ) for the function evaluation and another function object implementing double operator() (const double *, int icoord) for the partial derivatives
  4. from two function objects

The function dimension is required when constructing the functor.

Definition at line 144 of file Functor.h.

Public Types

typedef double BackendType
typedef IBaseFunctionMultiDimTempl< doubleBaseFunc

Public Member Functions

 GradFunctor ()=default
 Default constructor.
template<typename Func>
 GradFunctor (const Func &f, unsigned int dim)
 construct from a callable object of multi-dimension implementing operator()(const double *x) and Derivative(const double * x,icoord)
template<class PtrObj, typename MemFn, typename DerivMemFn, std::enable_if_t< std::is_floating_point< decltype((std::declval< std::remove_pointer_t< PtrObj > >().*std::declval< DerivMemFn >())(std::declval< const double * >(), std::declval< int >()))>::value, bool>
 GradFunctor (const PtrObj &p, MemFn memFn, DerivMemFn gradFn, unsigned int dim)
 Construct from a pointer to member function and member function types for function and derivative evaluations.
template<class PtrObj, typename MemFn, typename GradMemFn, std::enable_if_t< std::is_void< decltype((std::declval< std::remove_pointer_t< PtrObj > >().*std::declval< GradMemFn >())(std::declval< const double * >(), std::declval< double * >()))>::value, bool>
 GradFunctor (const PtrObj &p, MemFn memFn, GradMemFn gradFn, unsigned int dim)
 Construct from a pointer to member function and member function, types for function and full derivative evaluations.
 GradFunctor (std::function< double(double const *)> const &f, std::function< double(double const *, unsigned int)> const &g, unsigned int dim)
 Construct for Gradient Functions of multi-dimension Func gives the function evaluation, GradFunc the partial derivatives The function dimension is required.
 GradFunctor (std::function< double(double const *)> const &f, unsigned int dim, std::function< void(double const *, double *)> const &g)
 Construct a new GradFunctor object using 2 std::function, one for the function evaluation and one for the Gradient Note the difference with the constructor above where partial derivative function is used as input.
GradFunctorClone () const override
 Clone a function.
double Derivative (const double *x, unsigned int icoord, double *previous_grad, double *previous_g2, double *previous_gstep) const
 In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.
double Derivative (const double *x, unsigned int icoord=0) const
 Return the partial derivative with respect to the passed coordinate.
virtual void FdF (const double *x, double &f, double *df) const
 Optimized method to evaluate at the same time the function value and derivative at a point x.
void Gradient (const double *x, double *g) const override
 Evaluate all the vector of function derivatives (gradient) at a point x.
bool HasGradient () const override
unsigned int NDim () const override
 Retrieve the dimension of the function.
double operator() (const double *x) const
 Evaluate the function at a point x[].

Private Member Functions

double DoDerivative (const double *x, unsigned int icoord) const override
 Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.
double DoEval (const double *x) const override
 Implementation of the evaluation function. Must be implemented by derived classes.

Private Attributes

std::function< double(double const *, unsigned int)> fDerivFunc
unsigned int fDim
std::function< double(const double *)> fFunc
std::function< void(const double *, double *)> fGradFunc

#include <Math/Functor.h>

Inheritance diagram for ROOT::Math::GradFunctor:
ROOT::Math::IGradientFunctionMultiDimTempl< double > ROOT::Math::IBaseFunctionMultiDimTempl< double >

Member Typedef Documentation

◆ BackendType

Definition at line 67 of file IFunction.h.

◆ BaseFunc

Constructor & Destructor Documentation

◆ GradFunctor() [1/6]

ROOT::Math::GradFunctor::GradFunctor ( )
default

Default constructor.

◆ GradFunctor() [2/6]

template<typename Func>
ROOT::Math::GradFunctor::GradFunctor ( const Func & f,
unsigned int dim )
inline

construct from a callable object of multi-dimension implementing operator()(const double *x) and Derivative(const double * x,icoord)

Definition at line 158 of file Functor.h.

◆ GradFunctor() [3/6]

template<class PtrObj, typename MemFn, typename DerivMemFn, std::enable_if_t< std::is_floating_point< decltype((std::declval< std::remove_pointer_t< PtrObj > >().*std::declval< DerivMemFn >())(std::declval< const double * >(), std::declval< int >()))>::value, bool>
ROOT::Math::GradFunctor::GradFunctor ( const PtrObj & p,
MemFn memFn,
DerivMemFn gradFn,
unsigned int dim )
inline

Construct from a pointer to member function and member function types for function and derivative evaluations.

Definition at line 168 of file Functor.h.

◆ GradFunctor() [4/6]

template<class PtrObj, typename MemFn, typename GradMemFn, std::enable_if_t< std::is_void< decltype((std::declval< std::remove_pointer_t< PtrObj > >().*std::declval< GradMemFn >())(std::declval< const double * >(), std::declval< double * >()))>::value, bool>
ROOT::Math::GradFunctor::GradFunctor ( const PtrObj & p,
MemFn memFn,
GradMemFn gradFn,
unsigned int dim )
inline

Construct from a pointer to member function and member function, types for function and full derivative evaluations.

Definition at line 181 of file Functor.h.

◆ GradFunctor() [5/6]

ROOT::Math::GradFunctor::GradFunctor ( std::function< double(double const *)> const & f,
std::function< double(double const *, unsigned int)> const & g,
unsigned int dim )
inline

Construct for Gradient Functions of multi-dimension Func gives the function evaluation, GradFunc the partial derivatives The function dimension is required.

Definition at line 191 of file Functor.h.

◆ GradFunctor() [6/6]

ROOT::Math::GradFunctor::GradFunctor ( std::function< double(double const *)> const & f,
unsigned int dim,
std::function< void(double const *, double *)> const & g )
inline

Construct a new GradFunctor object using 2 std::function, one for the function evaluation and one for the Gradient Note the difference with the constructor above where partial derivative function is used as input.

Parameters
f: function object computing the function value
dim: number of function dimension
g: function object computing the function gradient

Definition at line 206 of file Functor.h.

Member Function Documentation

◆ Clone()

GradFunctor * ROOT::Math::GradFunctor::Clone ( ) const
inlineoverridevirtual

Clone a function.

Each derived class must implement their version of the Clone method.

Implements ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 212 of file Functor.h.

◆ Derivative() [1/2]

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::Derivative ( const double * x,
unsigned int icoord,
double * previous_grad,
double * previous_g2,
double * previous_gstep ) const
inlineinherited

In some cases, the derivative algorithm will use information from the previous step, these can be passed in with this overload.

The previous_* arrays can also be used to return second derivative and step size so that these can be passed forward again as well at the call site, if necessary.

Definition at line 120 of file IFunction.h.

◆ Derivative() [2/2]

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::Derivative ( const double * x,
unsigned int icoord = 0 ) const
inlineinherited

Return the partial derivative with respect to the passed coordinate.

Definition at line 115 of file IFunction.h.

◆ DoDerivative()

double ROOT::Math::GradFunctor::DoDerivative ( const double * ,
unsigned int  ) const
inlineoverrideprivatevirtual

Function to evaluate the derivative with respect each coordinate. To be implemented by the derived class.

Reimplemented from ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 233 of file Functor.h.

◆ DoEval()

double ROOT::Math::GradFunctor::DoEval ( const double * x) const
inlineoverrideprivatevirtual

Implementation of the evaluation function. Must be implemented by derived classes.

Implements ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 229 of file Functor.h.

◆ FdF()

virtual void ROOT::Math::IBaseFunctionMultiDimTempl< double >::FdF ( const double * x,
double & f,
double * df ) const
inlinevirtualinherited

Optimized method to evaluate at the same time the function value and derivative at a point x.

Often both value and derivatives are needed and it is often more efficient to compute them at the same time. Derived class should implement this method if performances play an important role and if it is faster to evaluate value and derivative at the same time

Reimplemented in ROOT::Math::LSResidualFunc< Func >.

Definition at line 108 of file IFunction.h.

◆ Gradient()

void ROOT::Math::GradFunctor::Gradient ( const double * x,
double * grad ) const
inlineoverridevirtual

Evaluate all the vector of function derivatives (gradient) at a point x.

Derived classes must re-implement it if more efficient than evaluating one at a time

Reimplemented from ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 217 of file Functor.h.

◆ HasGradient()

bool ROOT::Math::IGradientFunctionMultiDimTempl< double >::HasGradient ( ) const
inlineoverridevirtualinherited

Reimplemented from ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 243 of file IFunction.h.

◆ NDim()

unsigned int ROOT::Math::GradFunctor::NDim ( ) const
inlineoverridevirtual

Retrieve the dimension of the function.

Implements ROOT::Math::IBaseFunctionMultiDimTempl< double >.

Definition at line 215 of file Functor.h.

◆ operator()()

double ROOT::Math::IBaseFunctionMultiDimTempl< double >::operator() ( const double * x) const
inlineinherited

Evaluate the function at a point x[].

Use the pure virtual private method DoEval which must be implemented by the sub-classes.

Definition at line 81 of file IFunction.h.

Member Data Documentation

◆ fDerivFunc

std::function<double(double const *, unsigned int)> ROOT::Math::GradFunctor::fDerivFunc
private

Definition at line 247 of file Functor.h.

◆ fDim

unsigned int ROOT::Math::GradFunctor::fDim
private

Definition at line 245 of file Functor.h.

◆ fFunc

std::function<double(const double *)> ROOT::Math::GradFunctor::fFunc
private

Definition at line 246 of file Functor.h.

◆ fGradFunc

std::function<void(const double *, double*)> ROOT::Math::GradFunctor::fGradFunc
private

Definition at line 248 of file Functor.h.


The documentation for this class was generated from the following file: