proj home

Files   Classes   Functions   Hierarchy  

partialderivative< EXP > Class Template Reference

Evaluate a functions partial derivative. More...

#include <partialderivative.h>

Collaboration diagram for partialderivative< EXP >:

List of all members.

Public Types

typedef typeop< EXP >
::Tbare::FNtype 
FN
typedef typeop< EXP >::Tbare::Ttype T

Public Member Functions

 partialderivative (typename typeop< EXP >::Tref exp_)
 Construct with explorer.
 ~partialderivative ()
 Clean up memory.
void operator() ()
 Evaluate the partial derivative, store result in dxi.
T const squared () const
 The partial derivative doted with itself.
T const absvalue () const
 The sum of the absolute value of the components.

Public Attributes

typeop< EXP >::Tref exp
 Explorer.
Tdxi
 The partial derivative.
uintc N
 The dimension.


Detailed Description

template<typename EXP>
class partialderivative< EXP >

Evaluate a functions partial derivative.

This class numerically calculates the partial derivative from another algorithm exp which has f(x).

Definition at line 17 of file partialderivative.h.


Member Typedef Documentation

template<typename EXP>
typedef typeop<EXP>::Tbare::FNtype partialderivative< EXP >::FN

Definition at line 24 of file partialderivative.h.

template<typename EXP>
typedef typeop<EXP>::Tbare::Ttype partialderivative< EXP >::T

Definition at line 25 of file partialderivative.h.


Constructor & Destructor Documentation

template<typename EXP >
partialderivative< EXP >::partialderivative ( typename typeop< EXP >::Tref  exp_  )  [inline]

Construct with explorer.

Definition at line 102 of file partialderivative.h.

00105   : exp(exp_), N(exp_.N)
00106 {
00107   dxi = new T[N];
00108 }

template<typename EXP >
partialderivative< EXP >::~partialderivative (  )  [inline]

Clean up memory.

Definition at line 111 of file partialderivative.h.

References partialderivative< EXP >::dxi.

00112 {
00113   delete[] dxi;
00114 }


Member Function Documentation

template<typename EXP>
T const partialderivative< EXP >::absvalue (  )  const [inline]

The sum of the absolute value of the components.

Definition at line 56 of file partialderivative.h.

References partialderivative< EXP >::dxi, and partialderivative< EXP >::N.

Referenced by partialderivativetest01().

00057   {
00058     T val(0);
00059     for (uint i=0; i<N; ++i)
00060       val += abs(dxi[i]);
00061 
00062     return val;
00063   }

template<typename EXP >
void partialderivative< EXP >::operator() (  )  [inline]

Evaluate the partial derivative, store result in dxi.

Definition at line 71 of file partialderivative.h.

References partialderivative< EXP >::dxi, partialderivative< EXP >::exp, and partialderivative< EXP >::N.

00072 {
00073   T x;
00074   T fnb;
00075   T fna;
00076 
00077   T h;
00078 
00079   // O(N).O(fn) complexity
00080   for (uint i=0; i<N; ++i)
00081   {
00082     h = exp.hi[i];
00083     x = exp.fn.xi[i];
00084     exp.fn.xi[i] -= h;
00085     exp.fn(fna);
00086     exp.fn.xi[i] = x + h;
00087     exp.fn(fnb);
00088     // Restore xi
00089     exp.fn.xi[i] = x;
00090     
00091     // Compute the partial derivative.
00092     assert(h!=0.0);
00093     dxi[i] = (fnb-fna)/h*0.5;
00094   }
00095 
00096   // Restore the current state.
00097   exp.fn(fna);
00098 }

template<typename EXP>
T const partialderivative< EXP >::squared (  )  const [inline]

The partial derivative doted with itself.

Definition at line 46 of file partialderivative.h.

References partialderivative< EXP >::dxi, and partialderivative< EXP >::N.

00047   {
00048     T val(0);
00049     for (uint i=0; i<N; ++i)
00050       val += dxi[i]*dxi[i];
00051 
00052     return val;
00053   }


Member Data Documentation

template<typename EXP>
T* partialderivative< EXP >::dxi

template<typename EXP>
typeop<EXP>::Tref partialderivative< EXP >::exp

Explorer.

Definition at line 22 of file partialderivative.h.

Referenced by partialderivative< EXP >::operator()().

template<typename EXP>
uintc partialderivative< EXP >::N


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

Generated on Fri Mar 4 00:50:08 2011 for Chelton Evans Source by  doxygen 1.5.8