ReFRACtor
|
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>
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 () |
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.
typedef T FullPhysics::AutoDerivative< T >::value_type |
Definition at line 212 of file auto_derivative.h.
|
inline |
Default constructor, data is uninitialized.
Definition at line 218 of file auto_derivative.h.
|
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.
|
inline |
Convert AutoDerivativeRef to a AutoDerivative.
Definition at line 232 of file auto_derivative.h.
|
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.
|
inline |
Constructor for a value that is a constant.
Definition at line 252 of file auto_derivative.h.
|
inline |
Copy constructor. This does a deep copy.
Definition at line 261 of file auto_derivative.h.
|
inline |
Create deep copy.
Definition at line 285 of file auto_derivative.h.
|
inline |
Gradient.
Definition at line 299 of file auto_derivative.h.
|
inline |
Definition at line 300 of file auto_derivative.h.
|
inline |
Is this object a constant (with a gradient() all zeros)?
Definition at line 312 of file auto_derivative.h.
|
inline |
Number of variables in gradient.
Definition at line 306 of file auto_derivative.h.
|
inline |
Definition at line 355 of file auto_derivative.h.
|
inline |
Definition at line 371 of file auto_derivative.h.
|
inline |
Definition at line 324 of file auto_derivative.h.
|
inline |
Definition at line 337 of file auto_derivative.h.
|
inline |
Definition at line 339 of file auto_derivative.h.
|
inline |
Definition at line 353 of file auto_derivative.h.
|
inline |
Definition at line 373 of file auto_derivative.h.
|
inline |
Definition at line 389 of file auto_derivative.h.
|
inline |
Definition at line 318 of file auto_derivative.h.
|
inline |
Definition at line 319 of file auto_derivative.h.
|
inline |
Assignment operator. This makes a deep copy.
Definition at line 270 of file auto_derivative.h.
|
inline |
Definition at line 322 of file auto_derivative.h.
|
inline |
Definition at line 323 of file auto_derivative.h.
|
inline |
Definition at line 320 of file auto_derivative.h.
|
inline |
Definition at line 321 of file auto_derivative.h.
|
inline |
Definition at line 391 of file auto_derivative.h.
|
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.
|
inline |
Convert to type T.
Definition at line 292 of file auto_derivative.h.
|
inline |
Definition at line 293 of file auto_derivative.h.
|
friend |
Definition at line 413 of file auto_derivative.h.
|
friend |
Definition at line 437 of file auto_derivative.h.
|
friend |
Definition at line 461 of file auto_derivative.h.
|
friend |
Definition at line 396 of file auto_derivative.h.
|
friend |
Definition at line 425 of file auto_derivative.h.
|
friend |
Definition at line 449 of file auto_derivative.h.
|
friend |
Definition at line 402 of file auto_derivative.h.
|
friend |
Definition at line 408 of file auto_derivative.h.
|
friend |
Definition at line 431 of file auto_derivative.h.
|
friend |
Definition at line 455 of file auto_derivative.h.
|
friend |
Definition at line 419 of file auto_derivative.h.
|
friend |
Definition at line 443 of file auto_derivative.h.
|
friend |
Definition at line 467 of file auto_derivative.h.