[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| DualVector< T, N > Class Template Reference |

`#include <vigra/autodiff.hxx>`

## Public Types
typedef TinyVector< T, N > | Gradient
| type of the gradient vector
typedef T | value_type
| type of function values and gradient elements

## Public Member Functions
| DualVector ()
| DualVector (T const &val)
| DualVector (T const &val, Gradient const &grad)
| DualVector (T const &val, T const &g0)
| DualVector (T const &val, T const &g0, T const &g1)
| DualVector (T const &val, int targetElement)
Gradient const & | gradient () const
T | value () const

## Detailed Description

### template<class T, int N>
class vigra::autodiff::DualVector< T, N >

Number type for automatic differentiation.

Automatic differentiation allows one to compute the value of a numeric expression and its gradient with respect to the expression's arguments automatically and in one go. To support this, one needs a special number type that holds a scalar value and the corresponding gradient vector of appropriate length. This is the purpose of hte template class `DualVector<T, N>`, where `T` is the underlying numerical type (usually 'double'), and `N` denotes the length of the gradient vector.

The standard arithmetic and algebraic functions are overloaded for `DualVector` in order to implement the required arithmetic of dual numbers. When you replace all arguments in a numeric expression with the appropriate `DualVector` instances, the result will be a `DualVector` that contains the result value and gradient of the expression, evaluated at the point defined by the input values.

Usage:

#include <vigra/autodiff.hxx>
Namespace: vigra::autodiff

typedef DualVector<double, 2> N; // for expressions with two arguments
N x(1.0, 0); // first argument of the expression
N s(2.0, 1); // second argument of the expression
N y = exp(-0.5 * sq(x / s));
std::cout << "Evaluated exp(- x^2 / (2 s^2)) at x=1 and s = 2:\n";
std::cout << "result = " << y.value() <<", gradient = " << y.gradient() << "\n";

Note that the second argument of the `DualVector` constructors specifies that the derivative w.r.t 'x' shall be the element 0 of the gradient vector, and the derivative w.r.t. 's' shall be element 1.

## Constructor & Destructor Documentation

DualVector | ( |  | ) |

Zero initialization.

DualVector | ( | T const & | val | ) |
| explicit

Provide a value, but zero-initialize the gradient.

DualVector | ( | T const & | val,
|  | Gradient const & | grad
| ) |  |

Initialize with given value and gradient.

DualVector | ( | T const & | val,
|  | T const & | g0
| ) |  |

Shorthand for `DualVector(val, Gradient(g0))` when `N == 1`.

Not to be used when `N != 1`.

DualVector | ( | T const & | val,
|  | T const & | g0,
|  | T const & | g1
| ) |  |

Shorthand for `DualVector(val, Gradient(g0, g1))` when `N == 2`.

Not to be used when `N != 2`.

DualVector | ( | T const & | val,
|  | int | targetElement
| ) |  |

Initialize value to represent the argument number 'targetElement' in an expression.

The derivative of the expression w.r.t. this variable will be element 'targetElement' of the resulting gradient vector.

## Member Function Documentation

T value | ( |  | ) | const

Get current value.

Gradient const& gradient | ( |  | ) | const

Get current gradient.

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

- vigra/autodiff.hxx

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)