![]() |
Stan
1.0
probability, sampling & optimization
|
Independent (input) and dependent (output) variables for gradients. More...
#include <agrad.hpp>
Public Types | |
| typedef double | Scalar |
| typedef double | Scalar |
Public Member Functions | |
| bool | is_uninitialized () |
Return true if this variable has been declared, but not been defined. More... | |
| var (vari *vi) | |
| Construct a variable from a pointer to a variable implementation. More... | |
| var () | |
| Construct a variable for later assignment. More... | |
| var (bool b) | |
Construct a variable by static casting the specified value to double. More... | |
| var (char c) | |
Construct a variable by static casting the specified value to double. More... | |
| var (short n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned short n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (long int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned long int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned long long n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (long long n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (float x) | |
Construct a variable by static casting the specified value to double. More... | |
| var (double x) | |
| Construct a variable with the specified value. More... | |
| var (long double x) | |
Construct a variable by static casting the specified value to double. More... | |
| double | val () const |
| Return the value of this variable. More... | |
| double | adj () const |
| Return the derivative of the root expression with respect to this expression. More... | |
| void | grad (std::vector< var > &x, std::vector< double > &g) |
| Compute the gradient of this (dependent) variable with respect to the specified vector of (independent) variables, assigning the specified vector to the gradient. More... | |
| void | grad () |
| Compute gradients of this dependent variable with respect to all variables on which it depends. More... | |
| vari & | operator* () |
| Return a reference to underlying implementation of this variable. More... | |
| vari * | operator-> () |
| Return a pointer to the underlying implementation of this variable. More... | |
| var & | operator+= (const var &b) |
| The compound add/assignment operator for variables (C++). More... | |
| var & | operator+= (const double b) |
| The compound add/assignment operator for scalars (C++). More... | |
| var & | operator-= (const var &b) |
| The compound subtract/assignment operator for variables (C++). More... | |
| var & | operator-= (const double b) |
| The compound subtract/assignment operator for scalars (C++). More... | |
| var & | operator*= (const var &b) |
| The compound multiply/assignment operator for variables (C++). More... | |
| var & | operator*= (const double b) |
| The compound multiply/assignment operator for scalars (C++). More... | |
| var & | operator/= (const var &b) |
| The compound divide/assignment operator for variables (C++). More... | |
| var & | operator/= (const double b) |
| The compound divide/assignment operator for scalars (C++). More... | |
| var (vari *vi) | |
| Construct a variable from a pointer to a variable implementation. More... | |
| var () | |
| Construct a variable for later assignment. More... | |
| var (bool b) | |
Construct a variable by static casting the specified value to double. More... | |
| var (char c) | |
Construct a variable by static casting the specified value to double. More... | |
| var (short n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned short n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (long int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (unsigned long int n) | |
Construct a variable by static casting the specified value to double. More... | |
| var (float x) | |
Construct a variable by static casting the specified value to double. More... | |
| var (double x) | |
| Construct a variable with the specified value. More... | |
| var (long double x) | |
Construct a variable by static casting the specified value to double. More... | |
| double | val () const |
| Return the value of this variable. More... | |
| void | grad (std::vector< var > &x, std::vector< double > &g) |
| Compute the gradient of this dependent variable with respect to the specified vector of independent variables, assigning the gradients componentwise to the specified vector of gradients. More... | |
| void | grad () |
| Compute gradients of this dependent variable with respect to all variables on which it depends. More... | |
| var & | operator+= (const var &b) |
| The compound add/assignment operator for variables (C++). More... | |
| var & | operator+= (const double &b) |
| The compound add/assignment operator for scalars (C++). More... | |
| var & | operator-= (const var &b) |
| The compound subtract/assignment operator for variables (C++). More... | |
| var & | operator-= (const double &b) |
| The compound subtract/assignment operator for scalars (C++). More... | |
| var & | operator*= (const var &b) |
| The compound multiply/assignment operator for variables (C++). More... | |
| var & | operator*= (const double &b) |
| The compound multiply/assignment operator for scalars (C++). More... | |
| var & | operator/= (const var &b) |
| The compound divide/assignment operator for variables (C++). More... | |
| var & | operator/= (const double &b) |
| The compound divide/assignment operator for scalars (C++). More... | |
Public Attributes | |
| vari * | vi_ |
| Pointer to the implementation of this variable. More... | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const var &v) |
| Write the value of this auto-dif variable and its adjoint to the specified output stream. More... | |
Independent (input) and dependent (output) variables for gradients.
This class acts as a smart pointer, with resources managed by an agenda-based memory manager scoped to a single gradient calculation.
An agrad::var is constructed with a double and used like any other scalar. Arithmetical functions like negation, addition, and subtraction, as well as a range of mathematical functions like exponentiation and powers are overridden to operate on agrad::var values objects.
An agrad::var is constructed with a double and used like any other scalar. Arithmetical functions like negation, addition, and subtraction, as well as a range of mathematical functions like exponentiation and powers are overridden to operate on agrad::var values objects.
| typedef double stan::agrad::var::Scalar |
| typedef double stan::agrad::var::Scalar |
Definition at line 703 of file agrad_thread_safe.hpp.
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineexplicit |
Construct a variable from a pointer to a variable implementation.
| vi | Variable implementation. |
Definition at line 719 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable for later assignment.
This is implemented as a no-op, leaving the underlying implementation dangling. Before an assignment, the behavior is thus undefined just as for a basic double.
Definition at line 730 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| b | Value. |
Definition at line 740 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| c | Value. |
Definition at line 750 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 760 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 770 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 780 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 790 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 800 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| n | Value. |
Definition at line 810 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| x | Value. |
Definition at line 820 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable with the specified value.
| x | Value of the variable. |
Definition at line 829 of file agrad_thread_safe.hpp.
|
inline |
Construct a variable by static casting the specified value to double.
| x | Value. |
Definition at line 839 of file agrad_thread_safe.hpp.
|
inline |
|
inline |
Compute gradients of this dependent variable with respect to all variables on which it depends.
Memory is recovered, but not freed after this operation, calling recover_memory(); see free_all() to release resources back to the system rather than saving them for reuse).
Until the next creation of a stan::agrad::var instance, the gradient values will be available from an instance x of stan::agrad::var via x.adj(). It may be slightly more efficient to do this without the intermediate creation and population of two vectors as done in the two-argument form grad(std::vector<var>&, std::vector<double>&).
|
inline |
Compute gradients of this dependent variable with respect to all variables on which it depends.
Memory is recovered, but not freed after this operation, calling vari::recover_memory(); see vari::free_all() to release resources back to the system rather than saving them for reuse).
Until the next creation of a stan::agrad::var instance, the gradient values will be available from an instance x of stan::agrad::var via x.vi_->adj_. It may be slightly more efficient to do this without the intermediate creation and population of two vectors as done in the two-argument form grad(std::vector<var>&, std::vector<double>&).
Definition at line 889 of file agrad_thread_safe.hpp.
|
inline |
Compute the gradient of this (dependent) variable with respect to the specified vector of (independent) variables, assigning the specified vector to the gradient.
After the computation of the gradient and value, memory is recovered.
| x | Vector of independent variables. |
| g | Gradient vector of partial derivatives of this variable with respect to x. |
|
inline |
Compute the gradient of this dependent variable with respect to the specified vector of independent variables, assigning the gradients componentwise to the specified vector of gradients.
After the computation of the gradient and value, memory is recovered.
| x | Vector of independent variables. |
| g | Gradient vector of partial derivatives of this variable with respect to x. |
Definition at line 864 of file agrad_thread_safe.hpp.
|
inline |
|
inline |
|
inline |
The compound multiply/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a *= b) behaves exactly the same way as (a = a * b). Note that the result is an assignable lvalue.
| b | The scalar to multiply this variable by. |
Definition at line 985 of file agrad_thread_safe.hpp.
|
inline |
The compound multiply/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a *= b) behaves exactly the same way as (a = a * b). Note that the result is an assignable lvalue.
| b | The scalar to multiply this variable by. |
The compound multiply/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a *= b) behaves exactly the same way as (a = a * b). Note that the result is an assignable lvalue.
| b | The variable to multiply this variable by. |
The compound multiply/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a *= b) behaves exactly the same way as (a = a * b). Note that the result is an assignable lvalue.
| b | The variable to multiply this variable by. |
Definition at line 969 of file agrad_thread_safe.hpp.
|
inline |
The compound add/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a += b) behaves exactly the same way as (a = a + b). Note that the result is an assignable lvalue.
| b | The scalar to add to this variable. |
Definition at line 921 of file agrad_thread_safe.hpp.
|
inline |
The compound add/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a += b) behaves exactly the same way as (a = a + b). Note that the result is an assignable lvalue.
| b | The scalar to add to this variable. |
The compound add/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a += b) behaves exactly the same way as (a = a + b), creating an intermediate variable representing (a + b).
| b | The variable to add to this variable. |
The compound add/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a += b) behaves exactly the same way as (a = a + b), creating an intermediate variable representing (a + b).
| b | The variable to add to this variable. |
Definition at line 906 of file agrad_thread_safe.hpp.
|
inline |
The compound subtract/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a -= b) behaves exactly the same way as (a = a - b). Note that the result is an assignable lvalue.
| b | The scalar to subtract from this variable. |
Definition at line 953 of file agrad_thread_safe.hpp.
|
inline |
The compound subtract/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a -= b) behaves exactly the same way as (a = a - b). Note that the result is an assignable lvalue.
| b | The scalar to subtract from this variable. |
The compound subtract/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a -= b) behaves exactly the same way as (a = a - b). Note that the result is an assignable lvalue.
| b | The variable to subtract from this variable. |
The compound subtract/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a -= b) behaves exactly the same way as (a = a - b). Note that the result is an assignable lvalue.
| b | The variable to subtract from this variable. |
Definition at line 937 of file agrad_thread_safe.hpp.
|
inline |
|
inline |
The compound divide/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a /= b) behaves exactly the same way as (a = a / b). Note that the result is an assignable lvalue.
| b | The scalar to divide this variable by. |
Definition at line 1016 of file agrad_thread_safe.hpp.
|
inline |
The compound divide/assignment operator for scalars (C++).
If this variable is a and the argument is the scalar b, then (a /= b) behaves exactly the same way as (a = a / b). Note that the result is an assignable lvalue.
| b | The scalar to divide this variable by. |
The compound divide/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a /= b) behaves exactly the same way as (a = a / b). Note that the result is an assignable lvalue.
| b | The variable to divide this variable by. |
The compound divide/assignment operator for variables (C++).
If this variable is a and the argument is the variable b, then (a /= b) behaves exactly the same way as (a = a / b). Note that the result is an assignable lvalue.
| b | The variable to divide this variable by. |
Definition at line 1000 of file agrad_thread_safe.hpp.
|
inline |
|
inline |
Return the value of this variable.
Definition at line 848 of file agrad_thread_safe.hpp.
|
friend |
| vari * stan::agrad::var::vi_ |