| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

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

`#include <GaudiMath/NumericalDerivative.h>`

Inheritance diagram for Genfun::GaudiMathImplementation::NumericalDerivative:
[legend]
Collaboration diagram for Genfun::GaudiMathImplementation::NumericalDerivative:
[legend]

## Public Types
enum | Type { 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...
| ~NumericalDerivative () override=default
| destructor More...
unsigned int | dimensionality () const override
| dimensionality of the problem More...
double | operator() (double argument) const override
| Function value. More...
double | operator() (const Argument &argument) const override
| Function value. More...
bool | hasAnalyticDerivative () const override
| Does this function have an analytic derivative? More...
Derivative | partial (unsigned int index) const override
| Derivatives. More...
const AbsFunction & | function () const
| access to the function itself More...
size_t | index () const
| index More...
const Type & | type () const
| type More...
const Type & | setType (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...

## Private Member Functions
| NumericalDerivative ()
NumericalDerivative & | operator= (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 42 of file NumericalDerivative.h.

## Member Enumeration Documentation

enum Genfun::GaudiMathImplementation::NumericalDerivative::Type

the type of numerical differentiation

Enumerator
Central |
Forward |
Backward |

Definition at line 46 of file NumericalDerivative.h.

47 { Central ,
48 Forward ,
49 Backward } ;
Genfun::GaudiMathImplementation::NumericalDerivative::Forward
Definition: NumericalDerivative.h:48
Genfun::GaudiMathImplementation::NumericalDerivative::Central
Definition: NumericalDerivative.h:47
Genfun::GaudiMathImplementation::NumericalDerivative::Backward
Definition: NumericalDerivative.h:49

## Constructor & Destructor Documentation

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 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

  function | the function
  index | the variable index
  function | the function
  index | the variable index

Definition at line 48 of file NumericalDerivative.cpp.

51 : AbsFunction ()
52 , m_function ( function.clone() )
53 , m_index ( index )
54 , m_DIM ( function.dimensionality() )
55 , m_type ( type )
56 , m_argument ( function.dimensionality() )
57 , m_result ( GSL_NEGINF )
58 , m_error ( GSL_POSINF )
59 {
60 if( m_index >= m_DIM )
61 { Exception ( "::constructor invalid variable index " ) ; };
62 }
Genfun::GaudiMathImplementation::NumericalDerivative::index
size_t index() const
index
Definition: NumericalDerivative.h:122
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:124
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:153
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:148
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:155
Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality
unsigned int dimensionality() const override
dimensionality of the problem
Definition: NumericalDerivative.h:104
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:149
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:150
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:151
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:154
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:171

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | const NumericalDerivative & | right | ) |

copy constructor

Definition at line 69 of file NumericalDerivative.cpp.

70 : AbsFunction ()
71 , m_function ( right.m_function->clone() )
72 , m_index ( right.m_index )
73 , m_DIM ( right.m_DIM )
74 , m_type ( right.m_type )
75 , m_argument ( right.m_DIM )
76 , m_result ( GSL_NEGINF )
77 , m_error ( GSL_POSINF )
78 {}
std::right
T right(T...args)
Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
Argument m_argument
Definition: NumericalDerivative.h:153
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:148
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:155
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:149
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:150
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:151
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:154

Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative | ( |  | ) |
| override default

destructor

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

## Member Function Documentation

unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality | ( |  | ) | const
| inline override

dimensionality of the problem

Definition at line 104 of file NumericalDerivative.h.

104 { return m_DIM ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:150

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

the absolute error estimate for the last call

Definition at line 132 of file NumericalDerivative.h.

132 { return m_error ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:155

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

Exception.

Definition at line 171 of file NumericalDerivative.cpp.

173 {
174 throw GaudiException( "NumericalDerivative" + message ,
175 "*GaudiMath*" , sc ) ;
176 return sc ;
177 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23

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

access to the function itself

Definition at line 120 of file NumericalDerivative.h.

120 { return *m_function ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_function
std::unique_ptr< const AbsFunction > m_function
Definition: NumericalDerivative.h:148

bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative | ( |  | ) | const
| inline override

Does this function have an analytic derivative?

Definition at line 112 of file NumericalDerivative.h.

112 { return true ;}

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

index

Definition at line 122 of file NumericalDerivative.h.

122 { return m_index ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_index
size_t m_index
Definition: NumericalDerivative.h:149

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | double | argument | ) | const
| override

Function value.

Definition at line 152 of file NumericalDerivative.cpp.

153 {
154 // reset the result and the error
155 m_result = GSL_NEGINF ;
156 m_error = GSL_POSINF ;
157
158 // check the argument
159 if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }
160
161 Argument arg(1) ;
162 arg[0] = argument ;
163 return (*this)( arg ) ;
164 }
Genfun::GaudiMathImplementation::NumericalDerivative::m_error
double m_error
Definition: NumericalDerivative.h:155
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:150
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:154
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:171

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

Function value.

copy the argument

use GSL to evaluate the numerical derivative

Definition at line 106 of file NumericalDerivative.cpp.

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

NumericalDerivative& Genfun::GaudiMathImplementation::NumericalDerivative::operator= | ( | const NumericalDerivative & |  | ) |
| private

Genfun::Derivative Genfun::GaudiMathImplementation::NumericalDerivative::partial | ( | unsigned int | index | ) | const
| override

Derivatives.

Definition at line 92 of file NumericalDerivative.cpp.

93 {
94 if( idx >= m_DIM )
95 { Exception ( "::partial(i): invalid variable index" ) ; }
96 const AbsFunction& aux =
97 NumericalDerivative( *this , idx , type() ) ;
98 return FunctionNoop( &aux ) ;
99 }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:124
Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative
NumericalDerivative()
Genfun::GaudiMathImplementation::NumericalDerivative::m_DIM
size_t m_DIM
Definition: NumericalDerivative.h:150
Genfun::GaudiMathImplementation::NumericalDerivative::Exception
StatusCode Exception(const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
Exception.
Definition: NumericalDerivative.cpp:171

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

the result of the last call

Definition at line 130 of file NumericalDerivative.h.

130 { return m_result ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_result
double m_result
Definition: NumericalDerivative.h:154

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

change the type of the adaptive differentiation

Definition at line 85 of file NumericalDerivative.cpp.

86 { m_type = value ; return type() ; }
Genfun::GaudiMathImplementation::NumericalDerivative::type
const Type & type() const
type
Definition: NumericalDerivative.h:124
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:151

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

type

Definition at line 124 of file NumericalDerivative.h.

124 { return m_type ; }
Genfun::GaudiMathImplementation::NumericalDerivative::m_type
Type m_type
Definition: NumericalDerivative.h:151

## Member Data Documentation

Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument
| mutable private

Definition at line 153 of file NumericalDerivative.h.

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

Definition at line 150 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_error
| mutable private

Definition at line 155 of file NumericalDerivative.h.

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

Definition at line 148 of file NumericalDerivative.h.

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

Definition at line 149 of file NumericalDerivative.h.

double Genfun::GaudiMathImplementation::NumericalDerivative::m_result
| mutable private

Definition at line 154 of file NumericalDerivative.h.

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

Definition at line 151 of file NumericalDerivative.h.

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

- GaudiGSL/GaudiMath/NumericalDerivative.h
- GaudiGSL/src/Lib/NumericalDerivative.cpp