ReFRACtor
FullPhysics::AutoDerivative< T > Class Template Reference

There are a number of tools that can be used to do "Automatic Differentiation" (see for example http://www.autodiff.org/?module=Tools). More...

#include <auto_derivative.h>

+ Inheritance diagram for FullPhysics::AutoDerivative< T >:
+ Collaboration diagram for FullPhysics::AutoDerivative< T >:

Public Types

typedef T value_type
 

Public Member Functions

 AutoDerivative ()
 Default constructor, data is uninitialized. More...
 
 AutoDerivative (const T &Val, const blitz::Array< T, 1 > &G)
 Constructor that takes a value and a gradient. More...
 
 AutoDerivative (const AutoDerivativeRef< T > &V)
 Convert AutoDerivativeRef to a AutoDerivative. More...
 
 AutoDerivative (const T &Val, int i_th, int nvars)
 Constructor for a value of the i_th independent variable (0 based). More...
 
 AutoDerivative (const T &Val)
 Constructor for a value that is a constant. More...
 
 AutoDerivative (const AutoDerivative< T > &D)
 Copy constructor. This does a deep copy. More...
 
AutoDerivative< T > copy () const
 Create deep copy. More...
 
const blitz::Array< T, 1 > & gradient () const
 Gradient. More...
 
blitz::Array< T, 1 > & gradient ()
 
bool is_constant () const
 Is this object a constant (with a gradient() all zeros)? More...
 
int number_variable () const
 Number of variables in gradient. More...
 
AutoDerivative< T > & operator*= (const AutoDerivative< T > &V)
 
AutoDerivative< T > & operator*= (const T &V)
 
AutoDerivative< T > & operator+= (const AutoDerivative< T > &V)
 
AutoDerivative< T > & operator+= (const T &V)
 
AutoDerivative< T > & operator-= (const AutoDerivative< T > &V)
 
AutoDerivative< T > & operator-= (const T &V)
 
AutoDerivative< T > & operator/= (const AutoDerivative< T > &V)
 
AutoDerivative< T > & operator/= (const T &V)
 
bool operator< (const AutoDerivative< T > &V) const
 
bool operator< (const T &V) const
 
AutoDerivative< T > & operator= (const AutoDerivative< T > &D)
 Assignment operator. This makes a deep copy. More...
 
bool operator== (const AutoDerivative< T > &V) const
 
bool operator== (const T &V) const
 
bool operator> (const AutoDerivative< T > &V) const
 
bool operator> (const T &V) const
 
void print (std::ostream &Os) const
 
std::string print_to_string () const
 Print to string. More...
 
const T & value () const
 Convert to type T. More...
 
T & value ()
 

Friends

AutoDerivative< T > operator* (const AutoDerivative< T > &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator* (const AutoDerivative< T > &X, const T &Y)
 
AutoDerivative< T > operator* (const T &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator+ (const AutoDerivative< T > &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator+ (const AutoDerivative< T > &X, const T &Y)
 
AutoDerivative< T > operator+ (const T &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator- (const AutoDerivative< T > &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator- (const AutoDerivative< T > &X)
 
AutoDerivative< T > operator- (const AutoDerivative< T > &X, const T &Y)
 
AutoDerivative< T > operator- (const T &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator/ (const AutoDerivative< T > &X, const AutoDerivative< T > &Y)
 
AutoDerivative< T > operator/ (const AutoDerivative< T > &X, const T &Y)
 
AutoDerivative< T > operator/ (const T &X, const AutoDerivative< T > &Y)
 

Detailed Description

template<class T>
class FullPhysics::AutoDerivative< T >

There are a number of tools that can be used to do "Automatic Differentiation" (see for example http://www.autodiff.org/?module=Tools).

We examined several of the tools, and while these packages have a number of advantages (in particular, the ability to run the calculation either forward or backwards) for our particular needs a simpler forward only calculation was selected. This uses a number of type T, along with the first order gradient with respect to a set of independent variables. We then overload the standard operations such as "+" and "*" to apply the chain rule, to propagate the derivatives forward.

This is a newer field, so there doesn't seem to be standard terminology. In "Scientific and Engineering C++" by John Barton and Lee Nackman, this is call "Rall numbers" after a paper by L.B. Rall. On wikipedia at http://en.wikipedia.org/wiki/Automatic_differentiation this is called "Automatic differentiation using dual numbers".

As the existing automatic differentiation packages mature, we may want to revisit this choice and replace this class with a fuller library.

This class is not as efficient as hand coding derivative calculation, although it is much easier to use. If profiling shows a particular bottle neck, you might want to hand code derivatives for that specific location, which can then be placed into a AutoDerivative for use elsewhere (see the Absco class for an example of doing this).

See also ArrayAd which work with this class for Arrays of AutoDerivative.

Definition at line 12 of file auto_derivative.h.

Member Typedef Documentation

◆ value_type

template<class T>
typedef T FullPhysics::AutoDerivative< T >::value_type

Definition at line 212 of file auto_derivative.h.

Constructor & Destructor Documentation

◆ AutoDerivative() [1/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( )
inline

Default constructor, data is uninitialized.

Definition at line 218 of file auto_derivative.h.

◆ AutoDerivative() [2/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( const T &  Val,
const blitz::Array< T, 1 > &  G 
)
inline

Constructor that takes a value and a gradient.

This makes a shallow copy of the gradient, so we point to the same area in memory as G. If you want a deep copy, then pass in G.copy() rather than G.

Definition at line 226 of file auto_derivative.h.

◆ AutoDerivative() [3/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( const AutoDerivativeRef< T > &  V)
inline

Convert AutoDerivativeRef to a AutoDerivative.

Definition at line 232 of file auto_derivative.h.

◆ AutoDerivative() [4/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( const T &  Val,
int  i_th,
int  nvars 
)
inline

Constructor for a value of the i_th independent variable (0 based).

We create a gradient that is all 0, except for "1" in the i_th location.

Definition at line 240 of file auto_derivative.h.

◆ AutoDerivative() [5/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( const T &  Val)
inline

Constructor for a value that is a constant.

Definition at line 252 of file auto_derivative.h.

◆ AutoDerivative() [6/6]

template<class T>
FullPhysics::AutoDerivative< T >::AutoDerivative ( const AutoDerivative< T > &  D)
inline

Copy constructor. This does a deep copy.

Definition at line 261 of file auto_derivative.h.

Member Function Documentation

◆ copy()

template<class T>
AutoDerivative<T> FullPhysics::AutoDerivative< T >::copy ( ) const
inline

Create deep copy.

Definition at line 285 of file auto_derivative.h.

◆ gradient() [1/2]

template<class T>
const blitz::Array<T, 1>& FullPhysics::AutoDerivative< T >::gradient ( ) const
inline

Gradient.

Definition at line 299 of file auto_derivative.h.

◆ gradient() [2/2]

template<class T>
blitz::Array<T, 1>& FullPhysics::AutoDerivative< T >::gradient ( )
inline

Definition at line 300 of file auto_derivative.h.

◆ is_constant()

template<class T>
bool FullPhysics::AutoDerivative< T >::is_constant ( ) const
inline

Is this object a constant (with a gradient() all zeros)?

Definition at line 312 of file auto_derivative.h.

◆ number_variable()

template<class T>
int FullPhysics::AutoDerivative< T >::number_variable ( ) const
inline

Number of variables in gradient.

Definition at line 306 of file auto_derivative.h.

◆ operator*=() [1/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator*= ( const AutoDerivative< T > &  V)
inline

Definition at line 355 of file auto_derivative.h.

◆ operator*=() [2/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator*= ( const T &  V)
inline

Definition at line 371 of file auto_derivative.h.

◆ operator+=() [1/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator+= ( const AutoDerivative< T > &  V)
inline

Definition at line 324 of file auto_derivative.h.

◆ operator+=() [2/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator+= ( const T &  V)
inline

Definition at line 337 of file auto_derivative.h.

◆ operator-=() [1/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator-= ( const AutoDerivative< T > &  V)
inline

Definition at line 339 of file auto_derivative.h.

◆ operator-=() [2/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator-= ( const T &  V)
inline

Definition at line 353 of file auto_derivative.h.

◆ operator/=() [1/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator/= ( const AutoDerivative< T > &  V)
inline

Definition at line 373 of file auto_derivative.h.

◆ operator/=() [2/2]

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator/= ( const T &  V)
inline

Definition at line 389 of file auto_derivative.h.

◆ operator<() [1/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator< ( const AutoDerivative< T > &  V) const
inline

Definition at line 318 of file auto_derivative.h.

◆ operator<() [2/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator< ( const T &  V) const
inline

Definition at line 319 of file auto_derivative.h.

◆ operator=()

template<class T>
AutoDerivative<T>& FullPhysics::AutoDerivative< T >::operator= ( const AutoDerivative< T > &  D)
inline

Assignment operator. This makes a deep copy.

Definition at line 270 of file auto_derivative.h.

◆ operator==() [1/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator== ( const AutoDerivative< T > &  V) const
inline

Definition at line 322 of file auto_derivative.h.

◆ operator==() [2/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator== ( const T &  V) const
inline

Definition at line 323 of file auto_derivative.h.

◆ operator>() [1/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator> ( const AutoDerivative< T > &  V) const
inline

Definition at line 320 of file auto_derivative.h.

◆ operator>() [2/2]

template<class T>
bool FullPhysics::AutoDerivative< T >::operator> ( const T &  V) const
inline

Definition at line 321 of file auto_derivative.h.

◆ print()

template<class T>
void FullPhysics::AutoDerivative< T >::print ( std::ostream &  Os) const
inline

Definition at line 391 of file auto_derivative.h.

◆ print_to_string()

std::string FullPhysics::Printable< AutoDerivative< T > >::print_to_string ( ) const
inlineinherited

Print to string.

This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.

Definition at line 31 of file printable.h.

◆ value() [1/2]

template<class T>
const T& FullPhysics::AutoDerivative< T >::value ( ) const
inline

Convert to type T.

Definition at line 292 of file auto_derivative.h.

◆ value() [2/2]

template<class T>
T& FullPhysics::AutoDerivative< T >::value ( )
inline

Definition at line 293 of file auto_derivative.h.

Friends And Related Function Documentation

◆ operator* [1/3]

template<class T>
AutoDerivative<T> operator* ( const AutoDerivative< T > &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 413 of file auto_derivative.h.

◆ operator* [2/3]

template<class T>
AutoDerivative<T> operator* ( const AutoDerivative< T > &  X,
const T &  Y 
)
friend

Definition at line 437 of file auto_derivative.h.

◆ operator* [3/3]

template<class T>
AutoDerivative<T> operator* ( const T &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 461 of file auto_derivative.h.

◆ operator+ [1/3]

template<class T>
AutoDerivative<T> operator+ ( const AutoDerivative< T > &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 396 of file auto_derivative.h.

◆ operator+ [2/3]

template<class T>
AutoDerivative<T> operator+ ( const AutoDerivative< T > &  X,
const T &  Y 
)
friend

Definition at line 425 of file auto_derivative.h.

◆ operator+ [3/3]

template<class T>
AutoDerivative<T> operator+ ( const T &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 449 of file auto_derivative.h.

◆ operator- [1/4]

template<class T>
AutoDerivative<T> operator- ( const AutoDerivative< T > &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 402 of file auto_derivative.h.

◆ operator- [2/4]

template<class T>
AutoDerivative<T> operator- ( const AutoDerivative< T > &  X)
friend

Definition at line 408 of file auto_derivative.h.

◆ operator- [3/4]

template<class T>
AutoDerivative<T> operator- ( const AutoDerivative< T > &  X,
const T &  Y 
)
friend

Definition at line 431 of file auto_derivative.h.

◆ operator- [4/4]

template<class T>
AutoDerivative<T> operator- ( const T &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 455 of file auto_derivative.h.

◆ operator/ [1/3]

template<class T>
AutoDerivative<T> operator/ ( const AutoDerivative< T > &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 419 of file auto_derivative.h.

◆ operator/ [2/3]

template<class T>
AutoDerivative<T> operator/ ( const AutoDerivative< T > &  X,
const T &  Y 
)
friend

Definition at line 443 of file auto_derivative.h.

◆ operator/ [3/3]

template<class T>
AutoDerivative<T> operator/ ( const T &  X,
const AutoDerivative< T > &  Y 
)
friend

Definition at line 467 of file auto_derivative.h.


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

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:12