Automatic Differentiation
 
Loading...
Searching...
No Matches
stan::math::fvar< T > Struct Template Reference

Detailed Description

template<typename T>
struct stan::math::fvar< T >

This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.

When performing operations on instances of this class, all operands should be either primitive integer or double values or dual numbers representing derivatives in the same direction. The typical use case is to have a unit length directional derivative in the direction of a single independent variable.

By using reverse-mode automatic derivative variables, second-order derivatives may be calculated. By using fvar<var> instances, third-order derivatives may be calculated. These are called mixed-mode automatic differentiation variable in Stan.

Specialized functionals that perform differentiation on functors may be found in the matrix subdirectories of the reverse, forward, and mixed-mode directories.

The Wikipedia page on automatic differentiation describes how forward-mode automatic differentiation works mathematically in terms of dual numbers.

Template Parameters
Ttype of value and tangent

Definition at line 40 of file fvar.hpp.

#include <fvar.hpp>

Public Types

using Scalar = std::decay_t< T >
 The type of values and tangents.
 

Public Member Functions

Scalar val () const
 Return the value of this variable.
 
Scalar d () const
 Return the tangent (derivative) of this variable.
 
 fvar ()
 Construct a forward variable with zero value and tangent.
 
template<typename V , std::enable_if_t< ad_promotable< V, T >::value > * = nullptr, require_not_same_t< V, fvar< T > > * = nullptr>
 fvar (const V &v)
 Construct a forward variable with the specified value and zero tangent.
 
template<typename V , typename D >
 fvar (const V &v, const D &d)
 Construct a forward variable with the specified value and tangent.
 
fvar< T > & operator+= (const fvar< T > &x2)
 Add the specified variable to this variable and return a reference to this variable.
 
fvar< T > & operator+= (double x2)
 Add the specified value to this variable and return a reference to this variable.
 
fvar< T > & operator-= (const fvar< T > &x2)
 Subtract the specified variable from this variable and return a reference to this variable.
 
fvar< T > & operator-= (double x2)
 Subtract the specified value from this variable and return a reference to this variable.
 
fvar< T > & operator*= (const fvar< T > &x2)
 Multiply this variable by the the specified variable and return a reference to this variable.
 
fvar< T > & operator*= (double x2)
 Multiply this variable by the the specified value and return a reference to this variable.
 
fvar< T > & operator/= (const fvar< T > &x2)
 Divide this variable by the the specified variable and return a reference to this variable.
 
fvar< T > & operator/= (double x2)
 Divide this value by the the specified variable and return a reference to this variable.
 
fvar< T > & operator++ ()
 Increment this variable by one and return a reference to this variable after the increment.
 
fvar< T > operator++ (int)
 Increment this variable by one and return a reference to a copy of this variable before it was incremented.
 
fvar< T > & operator-- ()
 Decrement this variable by one and return a reference to this variable after the decrement.
 
fvar< T > operator-- (int)
 Decrement this variable by one and return a reference to a copy of this variable before it was decremented.
 

Public Attributes

Scalar val_
 The value of this variable.
 
Scalar d_
 The tangent (derivative) of this variable.
 

Friends

std::ostream & operator<< (std::ostream &os, const fvar< T > &v)
 Write the value of the specified variable to the specified output stream, returning a reference to the output stream.
 

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