Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

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

#include </scratch/z5/marcocle/GaudiDocs/lhcb-release/825/GAUDI/GAUDI_v26r3/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 ()
 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 ()
 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

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 36 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 53 of file NumericalDerivative.cpp.

56  : AbsFunction ()
57  , m_function ( function.clone() )
58  , m_index ( index )
59  , m_DIM ( function.dimensionality() )
60  , m_type ( type )
61  , m_argument ( function.dimensionality() )
62  , m_result ( GSL_NEGINF )
63  , m_error ( GSL_POSINF )
64  {
65  if( m_index >= m_DIM )
66  { Exception ( "::constructor invalid variable index " ) ; };
67  }
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 74 of file NumericalDerivative.cpp.

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

virtual destructor

destructor

Definition at line 89 of file NumericalDerivative.cpp.

90  { if( 0 != m_function ) { delete m_function ; m_function = 0 ; } }
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 ( )
virtual

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 98 of file NumericalDerivative.h.

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

dimensionality of the problem

Definition at line 98 of file NumericalDerivative.h.

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

the absolute error estimate for the last call

Definition at line 126 of file NumericalDerivative.h.

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

the absolute error estimate for the last call

Definition at line 126 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 183 of file NumericalDerivative.cpp.

185  {
186  throw GaudiException( "NumericalDerivative" + message ,
187  "*GaudiMath*" , sc ) ;
188  return sc ;
189  }
Define general base for Gaudi exception.
const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function ( ) const
inline

access to the function itself

Definition at line 114 of file NumericalDerivative.h.

const AbsFunction& Genfun::GaudiMathImplementation::NumericalDerivative::function ( ) const
inline

access to the function itself

Definition at line 114 of file NumericalDerivative.h.

virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative ( ) const
inlinevirtual

Does this function have an analytic derivative?

Definition at line 106 of file NumericalDerivative.h.

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

Does this function have an analytic derivative?

Definition at line 106 of file NumericalDerivative.h.

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

index

Definition at line 116 of file NumericalDerivative.h.

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

index

Definition at line 116 of file NumericalDerivative.h.

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

Function value.

Definition at line 164 of file NumericalDerivative.cpp.

165  {
166  // reset the result and the error
167  m_result = GSL_NEGINF ;
168  m_error = GSL_POSINF ;
169 
170  // check the argument
171  if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }
172 
173  Argument arg(1) ;
174  arg[0] = argument ;
175  return (*this)( arg ) ;
176  }
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 118 of file NumericalDerivative.cpp.

119  {
120  // reset the result and the error
121  m_result = GSL_NEGINF ;
122  m_error = GSL_POSINF ;
123 
124  // check the argument
125  if( argument.dimension() != m_DIM )
126  { Exception ( "::operator():invalid argument size" ) ; };
127 
129  {for( size_t i = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}}
130 
131  // create the helper object
132  GSL_Helper helper( *m_function , m_argument , m_index );
133 
135  gsl_function F ;
136  F.function = &GSL_Adaptor ;
137  F.params = &helper ;
138 
139  double x = argument[m_index];
140  int ierrno = 0 ;
141  switch ( type() )
142  {
143  case Central :
144  ierrno = gsl_diff_central ( &F , x , &m_result , &m_error ) ; break ;
145  case Forward :
146  ierrno = gsl_diff_forward ( &F , x , &m_result , &m_error ) ; break ;
147  case Backward :
148  ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
149  default:
150  Exception ( "::operator(): invalid diffrentiation type " ) ;
151  }
152 
153  if( ierrno )
154  { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" ,
155  __FILE__ , __LINE__ , ierrno ) ; }
156 
157  return result() ;
158  }
double GSL_Adaptor(double x, void *params)
Definition: Helpers.cpp:38
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 104 of file NumericalDerivative.cpp.

105  {
106  if( idx >= m_DIM )
107  { Exception ( "::partial(i): invalid variable index" ) ; }
108  const AbsFunction& aux =
109  NumericalDerivative( *this , idx , type() ) ;
110  return FunctionNoop( &aux ) ;
111  }
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 124 of file NumericalDerivative.h.

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

the result of the last call

Definition at line 124 of file NumericalDerivative.h.

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

change the type of the adaptive differentiation

Definition at line 97 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 118 of file NumericalDerivative.h.

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

type

Definition at line 118 of file NumericalDerivative.h.

Member Data Documentation

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

Definition at line 147 of file NumericalDerivative.h.

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

Definition at line 144 of file NumericalDerivative.h.

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

Definition at line 149 of file NumericalDerivative.h.

const AbsFunction * Genfun::GaudiMathImplementation::NumericalDerivative::m_function
private

Definition at line 142 of file NumericalDerivative.h.

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

Definition at line 143 of file NumericalDerivative.h.

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

Definition at line 148 of file NumericalDerivative.h.

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

Definition at line 145 of file NumericalDerivative.h.


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