Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

Numerical derivative (using GSL adaptive numerical differentiation) More...

#include </scratch/z5/marcocle/GaudiDocs/lhcb-release/996/GAUDI/GAUDI_v26r4/InstallArea/x86_64-slc6-gcc48-opt/include/GaudiMath/NumericalDerivative.h>

Inheritance diagram for Genfun::GaudiMathImplementation::NumericalDerivative:
Collaboration diagram for Genfun::GaudiMathImplementation::NumericalDerivative:

Public Types

enum  Type {
  Central, Forward, Backward, Central,
  Forward, Backward
}
 the type of numerical differentiation More...
 
enum  Type {
  Central, Forward, Backward, Central,
  Forward, Backward
}
 the type of numerical differentiation More...
 

Public Member Functions

 NumericalDerivative (const AbsFunction &function, const size_t index, const Type &type=Central)
 From CLHEP/GenericFunctions. More...
 
 NumericalDerivative (const NumericalDerivative &right)
 copy constructor More...
 
virtual ~NumericalDerivative ()=default
 virtual destructor More...
 
virtual unsigned int dimensionality () const
 dimensionality of the problem More...
 
virtual double operator() (double argument) const
 Function value. More...
 
virtual double operator() (const Argument &argument) const
 Function value. More...
 
virtual bool hasAnalyticDerivative () const
 Does this function have an analytic derivative? More...
 
virtual Derivative partial (unsigned int index) const
 Derivatives. More...
 
const AbsFunction & function () const
 access to the function itself More...
 
size_t index () const
 index More...
 
const Typetype () const
 type More...
 
const TypesetType (const Type &value)
 change the type of the adaptive differentiation More...
 
double result () const
 the result of the last call More...
 
double error () const
 the absolute error estimate for the last call More...
 
 NumericalDerivative (const AbsFunction &function, const size_t index, const Type &type=Central)
 From CLHEP/GenericFunctions. More...
 
 NumericalDerivative (const NumericalDerivative &right)
 copy constructor More...
 
virtual ~NumericalDerivative ()=default
 virtual destructor More...
 
virtual unsigned int dimensionality () const
 dimensionality of the problem More...
 
virtual double operator() (double argument) const
 Function value. More...
 
virtual double operator() (const Argument &argument) const
 Function value. More...
 
virtual bool hasAnalyticDerivative () const
 Does this function have an analytic derivative? More...
 
virtual Derivative partial (unsigned int index) const
 Derivatives. More...
 
const AbsFunction & function () const
 access to the function itself More...
 
size_t index () const
 index More...
 
const Typetype () const
 type More...
 
const TypesetType (const Type &value)
 change the type of the adaptive differentiation More...
 
double result () const
 the result of the last call More...
 
double error () const
 the absolute error estimate for the last call More...
 

Protected Member Functions

StatusCode Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
 Exception. More...
 
StatusCode Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
 

Private Member Functions

 NumericalDerivative ()
 
NumericalDerivativeoperator= (const NumericalDerivative &)
 
 NumericalDerivative ()
 
NumericalDerivativeoperator= (const NumericalDerivative &)
 

Private Attributes

std::unique_ptr< const AbsFunction > m_function
 
size_t m_index
 
size_t m_DIM
 
Type m_type
 
Argument m_argument
 
double m_result
 
double m_error
 

Detailed Description

Numerical derivative (using GSL adaptive numerical differentiation)

\[ {\mathcal{F}}_i \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) = \frac{\partial}{\partial x_i} f \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) \]

Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@i.nosp@m.tep..nosp@m.ru
Date
2003-08-27

Definition at line 34 of file NumericalDerivative.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( const AbsFunction &  function,
const size_t  index,
const Type type = Central 
)

From CLHEP/GenericFunctions.

from CLHEP/GenericFunctions

The standard constructor from AbsFunction and the index of the variable

The function, created with this constructor compute the numerical derivatived by finite differencing,. An adaptive algorithm is used to find teh best choice of finite difference and to estimate the error in derivative

\[ {\mathcal{F}}_i \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) = \frac{\partial}{\partial x_i} f \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) \]

  • The central difference algorithm gsl_diff_central is used for type = Type::Central
  • The forward difference algorithm gsl_diff_forward is used for type = Type::Forward. The function is evaluated only at points greater than x_i and x_i itself. This function should be used if f(x) has a singularity or if it is undefined for values less than x_i
  • The backward difference algorithm gsl_diff_backward is used for type = Type::Backward. The function is evaluated only at points smaller than x_i and x_i itself. This function should be used if f(x) has a singularity or if it is undefined for values greater than x_i

The adaptime numerical differentiation is used

Parameters
functionthe function
indexthe variable index

The standard constructor from AbsFunction and the index of the variable

Parameters
functionthe function
indexthe variable index

Definition at line 52 of file NumericalDerivative.cpp.

55  : AbsFunction ()
56  , m_function ( function.clone() )
57  , m_index ( index )
58  , m_DIM ( function.dimensionality() )
59  , m_type ( type )
60  , m_argument ( function.dimensionality() )
61  , m_result ( GSL_NEGINF )
62  , m_error ( GSL_POSINF )
63  {
64  if( m_index >= m_DIM )
65  { Exception ( "::constructor invalid variable index " ) ; };
66  }
virtual unsigned int dimensionality() const
dimensionality of the problem
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( const NumericalDerivative right)

copy constructor

Definition at line 73 of file NumericalDerivative.cpp.

virtual Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative ( )
virtualdefault

virtual destructor

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( )
private
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( const AbsFunction &  function,
const size_t  index,
const Type type = Central 
)

From CLHEP/GenericFunctions.

The standard constructor from AbsFunction and the index of the variable

The function, created with this constructor compute the numerical derivatived by finite differencing,. An adaptive algorithm is used to find teh best choice of finite difference and to estimate the error in derivative

\[ {\mathcal{F}}_i \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) = \frac{\partial}{\partial x_i} f \left(x_1, \dots , x_{i-1}, x_i , x_{i+1}, \dots , x_n \right) \]

  • The central difference algorithm gsl_diff_central is used for type = Type::Central
  • The forward difference algorithm gsl_diff_forward is used for type = Type::Forward. The function is evaluated only at points greater than x_i and x_i itself. This function should be used if f(x) has a singularity or if it is undefined for values less than x_i
  • The backward difference algorithm gsl_diff_backward is used for type = Type::Backward. The function is evaluated only at points smaller than x_i and x_i itself. This function should be used if f(x) has a singularity or if it is undefined for values greater than x_i

The adaptime numerical differentiation is used

Parameters
functionthe function
indexthe variable index
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( const NumericalDerivative right)

copy constructor

virtual Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative ( )
virtualdefault

virtual destructor

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative ( )
private

Member Function Documentation

virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality ( ) const
inlinevirtual

dimensionality of the problem

Definition at line 96 of file NumericalDerivative.h.

virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality ( ) const
inlinevirtual

dimensionality of the problem

Definition at line 96 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::error ( ) const
inline

the absolute error estimate for the last call

Definition at line 124 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::error ( ) const
inline

the absolute error estimate for the last call

Definition at line 124 of file NumericalDerivative.h.

StatusCode Genfun::GaudiMathImplementation::NumericalDerivative::Exception ( const std::string &  message,
const StatusCode sc = StatusCode::FAILURE 
) const
protected
StatusCode Genfun::GaudiMathImplementation::NumericalDerivative::Exception ( const std::string &  message,
const StatusCode sc = StatusCode::FAILURE 
) const
protected

Exception.

Definition at line 175 of file NumericalDerivative.cpp.

177  {
178  throw GaudiException( "NumericalDerivative" + message ,
179  "*GaudiMath*" , sc ) ;
180  return sc ;
181  }
Define general base for Gaudi exception.
const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function ( ) const
inline

access to the function itself

Definition at line 112 of file NumericalDerivative.h.

112 { return *m_function ; }
const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function ( ) const
inline

access to the function itself

Definition at line 112 of file NumericalDerivative.h.

112 { return *m_function ; }
virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative ( ) const
inlinevirtual

Does this function have an analytic derivative?

Definition at line 104 of file NumericalDerivative.h.

104 { return true ;}
virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative ( ) const
inlinevirtual

Does this function have an analytic derivative?

Definition at line 104 of file NumericalDerivative.h.

104 { return true ;}
size_t Genfun::GaudiMathImplementation::NumericalDerivative::index ( ) const
inline

index

Definition at line 114 of file NumericalDerivative.h.

size_t Genfun::GaudiMathImplementation::NumericalDerivative::index ( ) const
inline

index

Definition at line 114 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() ( double  argument) const
virtual

Function value.

Definition at line 156 of file NumericalDerivative.cpp.

157  {
158  // reset the result and the error
159  m_result = GSL_NEGINF ;
160  m_error = GSL_POSINF ;
161 
162  // check the argument
163  if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }
164 
165  Argument arg(1) ;
166  arg[0] = argument ;
167  return (*this)( arg ) ;
168  }
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
virtual double Genfun::GaudiMathImplementation::NumericalDerivative::operator() ( double  argument) const
virtual

Function value.

virtual double Genfun::GaudiMathImplementation::NumericalDerivative::operator() ( const Argument &  argument) const
virtual

Function value.

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() ( const Argument &  argument) const
virtual

Function value.

copy the argument

use GSL to evaluate the numerical derivative

Definition at line 110 of file NumericalDerivative.cpp.

111  {
112  // reset the result and the error
113  m_result = GSL_NEGINF ;
114  m_error = GSL_POSINF ;
115 
116  // check the argument
117  if( argument.dimension() != m_DIM )
118  { Exception ( "::operator():invalid argument size" ) ; };
119 
121  {for( size_t i = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}}
122 
123  // create the helper object
124  GSL_Helper helper( *m_function , m_argument , m_index );
125 
127  gsl_function F ;
128  F.function = &GSL_Adaptor ;
129  F.params = &helper ;
130 
131  double x = argument[m_index];
132  int ierrno = 0 ;
133  switch ( type() )
134  {
135  case Central :
136  ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ;
137  case Forward :
138  ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ;
139  case Backward :
140  ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
141  default:
142  Exception ( "::operator(): invalid diffrentiation type " ) ;
143  }
144 
145  if( ierrno )
146  { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" ,
147  __FILE__ , __LINE__ , ierrno ) ; }
148 
149  return result() ;
150  }
double GSL_Adaptor(double x, void *params)
Definition: Helpers.cpp:37
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
list i
Definition: ana.py:128
double result() const
the result of the last call
NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= ( const NumericalDerivative )
private
NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= ( const NumericalDerivative )
private
Genfun::Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial ( unsigned int  index) const
virtual

Derivatives.

Definition at line 96 of file NumericalDerivative.cpp.

97  {
98  if( idx >= m_DIM )
99  { Exception ( "::partial(i): invalid variable index" ) ; }
100  const AbsFunction& aux =
101  NumericalDerivative( *this , idx , type() ) ;
102  return FunctionNoop( &aux ) ;
103  }
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
virtual Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial ( unsigned int  index) const
virtual

Derivatives.

double Genfun::GaudiMathImplementation::NumericalDerivative::result ( ) const
inline

the result of the last call

Definition at line 122 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::result ( ) const
inline

the result of the last call

Definition at line 122 of file NumericalDerivative.h.

const NumericalDerivative::Type & Genfun::GaudiMathImplementation::NumericalDerivative::setType ( const Type value)

change the type of the adaptive differentiation

Definition at line 89 of file NumericalDerivative.cpp.

const Type& Genfun::GaudiMathImplementation::NumericalDerivative::setType ( const Type value)

change the type of the adaptive differentiation

const Type& Genfun::GaudiMathImplementation::NumericalDerivative::type ( ) const
inline

type

Definition at line 116 of file NumericalDerivative.h.

const Type& Genfun::GaudiMathImplementation::NumericalDerivative::type ( ) const
inline

type

Definition at line 116 of file NumericalDerivative.h.

Member Data Documentation

Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
mutableprivate

Definition at line 145 of file NumericalDerivative.h.

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
private

Definition at line 142 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_error
mutableprivate

Definition at line 147 of file NumericalDerivative.h.

std::unique_ptr< const AbsFunction > Genfun::GaudiMathImplementation::NumericalDerivative::m_function
private

Definition at line 140 of file NumericalDerivative.h.

size_t Genfun::GaudiMathImplementation::NumericalDerivative::m_index
private

Definition at line 141 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_result
mutableprivate

Definition at line 146 of file NumericalDerivative.h.

Type Genfun::GaudiMathImplementation::NumericalDerivative::m_type
private

Definition at line 143 of file NumericalDerivative.h.


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