| # Gaudi Framework, version v22r2 |

Home |  | Generated: Tue May 10 2011

Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

# Genfun::GaudiMathImplementation::NumericalDerivative Class Reference

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

`#include <NumericalDerivative.h>`

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

List of all members.

## 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.
| NumericalDerivative (const NumericalDerivative &right)
| copy constructor
virtual | ~NumericalDerivative ()
| virtual destructor
virtual unsigned int | dimensionality () const
| dimensionality of the problem
virtual double | operator() (double argument) const
| Function value.
virtual double | operator() (const Argument &argument) const
| Function value.
virtual bool | hasAnalyticDerivative () const
| Does this function have an analytic derivative?
virtual Derivative | partial (unsigned int index) const
| Derivatives.
const AbsFunction & | function () const
| access to the function itself
size_t | index () const
| index
const Type & | type () const
| type
const Type & | setType (const Type &value)
| change the type of the adaptive differentiation
double | result () const
| the result of the last call
double | error () const
| the absolute error estimate for the last call
## Protected Member Functions
StatusCode | Exception (const std::string &message, const StatusCode &sc=StatusCode::FAILURE) const
| Exception.
## Private Member Functions
| NumericalDerivative ()
NumericalDerivative & | operator= (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)

Author:
  Vanya BELYAEV Ivan.Belyaev@itep.ru

Date:
  2003-08-27

Definition at line 36 of file NumericalDerivative.h.

## Member Enumeration Documentation

enum Genfun::GaudiMathImplementation::NumericalDerivative::Type

the type of numerical differentiation

Enumerator:

  Central |
  Forward |
  Backward |

Definition at line 40 of file NumericalDerivative.h.

            { Central  ,
              Forward  ,
              Backward } ;

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

- 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

The standard constructor from AbsFunction and the index of the variable

Parameters:

  function | the function
  index | the variable index

Definition at line 53 of file NumericalDerivative.cpp.

          : AbsFunction ()
          , m_function  ( function.clone()          )
          , m_index     ( index                     )
          , m_DIM       ( function.dimensionality() )
          , m_type      ( type                      )
          , m_argument  ( function.dimensionality() )
          , m_result    ( GSL_NEGINF                )
          , m_error     ( GSL_POSINF                )
        {
          if( m_index >= m_DIM )
            { Exception ( "::constructor invalid variable index " ) ; };
        }

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

copy constructor

Definition at line 74 of file NumericalDerivative.cpp.

          : AbsFunction ()
          , m_function  ( right.m_function->clone() )
          , m_index     ( right.m_index             )
          , m_DIM       ( right.m_DIM               )
          , m_type      ( right.m_type              )
          , m_argument  ( right.m_DIM               )
          , m_result    ( GSL_NEGINF                )
          , m_error     ( GSL_POSINF                )
        {}

Genfun::GaudiMathImplementation::NumericalDerivative::~NumericalDerivative | ( | ) | `[virtual]`

virtual destructor

destructor

Definition at line 89 of file NumericalDerivative.cpp.

        { if( 0 != m_function ) { delete m_function ; m_function = 0 ; } }

Genfun::GaudiMathImplementation::NumericalDerivative::NumericalDerivative | ( | ) | `[private]`

## Member Function Documentation

virtual unsigned int Genfun::GaudiMathImplementation::NumericalDerivative::dimensionality | ( | ) | const`[inline, virtual]`

dimensionality of the problem

Definition at line 98 of file NumericalDerivative.h.

    { return m_DIM ; }

double Genfun::GaudiMathImplementation::NumericalDerivative::error | ( | ) | const`[inline]`

the absolute error estimate for the last call

Definition at line 126 of file NumericalDerivative.h.

    { return m_error     ; }

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.

        {
          throw GaudiException( "NumericalDerivative" + message ,
                                "*GaudiMath*"         , sc      ) ;
          return sc ;
        }

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

access to the function itself

Definition at line 114 of file NumericalDerivative.h.

    { return *m_function ; }

virtual bool Genfun::GaudiMathImplementation::NumericalDerivative::hasAnalyticDerivative | ( | ) | const`[inline, virtual]`

Does this function have an analytic derivative?

Definition at line 106 of file NumericalDerivative.h.

    { return true ;}

size_t Genfun::GaudiMathImplementation::NumericalDerivative::index | ( | ) | const`[inline]`

index

Definition at line 116 of file NumericalDerivative.h.

    { return  m_index    ; }

double Genfun::GaudiMathImplementation::NumericalDerivative::operator() | ( | double | argument ) | const`[virtual]`

Function value.

Definition at line 164 of file NumericalDerivative.cpp.

        {
          // reset the result and the error
          m_result = GSL_NEGINF ;
          m_error  = GSL_POSINF ;

          // check the argument
          if( 1 != m_DIM ) { Exception ( "operator(): invalid argument size " ); }

          Argument arg(1) ;
          arg[0] = argument ;
          return (*this)( arg ) ;
        }

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.

        {
          // reset the result and the error
          m_result = GSL_NEGINF ;
          m_error  = GSL_POSINF ;

          // check the argument
          if( argument.dimension() != m_DIM )
            { Exception ( "::operator():invalid argument size" ) ; };

          {for( size_t i  = 0 ; i < m_DIM ; ++i ){ m_argument[i] = argument[i];}}

          // create the helper object
          GSL_Helper helper( *m_function , m_argument , m_index );

          gsl_function F ;
          F.function = &GSL_Adaptor ;
          F.params   = &helper                 ;

          double x       = argument[m_index];
          int    ierrno  = 0                   ;
          switch ( type() )
            {
            case Central  :
              ierrno = gsl_diff_central  ( &F , x , &m_result , &m_error ) ; break ;
            case Forward  :
              ierrno = gsl_diff_forward  ( &F , x , &m_result , &m_error ) ; break ;
            case Backward :
              ierrno = gsl_diff_backward ( &F , x , &m_result , &m_error ) ; break ;
            default:
              Exception ( "::operator(): invalid diffrentiation type " ) ;
            }

          if( ierrno )
            { gsl_error ( " NumericalDerivative:: the error from gsl_diff_XXXX" ,
                          __FILE__ , __LINE__ , ierrno ) ; }

          return result() ;
        }

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.

        {
          if( idx >= m_DIM )
            { Exception ( "::partial(i): invalid variable index" ) ; }
          const  AbsFunction& aux =
            NumericalDerivative( *this , idx , type() ) ;
          return FunctionNoop( &aux ) ;
        }

double Genfun::GaudiMathImplementation::NumericalDerivative::result | ( | ) | const`[inline]`

the result of the last call

Definition at line 124 of file NumericalDerivative.h.

    { return m_result    ; }

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.

        { m_type = value ; return type() ; }

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

type

Definition at line 118 of file NumericalDerivative.h.

    { return  m_type     ; }

## Member Data Documentation

Argument Genfun::GaudiMathImplementation::NumericalDerivative::m_argument`[mutable, private]`

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`[mutable, private]`

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`[mutable, private]`

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:

- /afs/.cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r2/GaudiGSL/GaudiMath/NumericalDerivative.h
- /afs/.cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r2/GaudiGSL/src/Lib/NumericalDerivative.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines