![]() |
Stan
1.0
probability, sampling & optimization
|
The variable implementation base class. More...
#include <agrad.hpp>
Public Member Functions | |
| vari (const double x) | |
| Construct a variable implementation from a value. More... | |
| ~vari () | |
| Throw an illegal argument exception. More... | |
| virtual void | init_dependent () |
| Initialize the adjoint for this (dependent) variable to 1. More... | |
| virtual void | set_zero_adjoint () |
| Set the adjoint value of this variable to 0. More... | |
| vari (const double x) | |
| Construct a variable implementation from a value. More... | |
| virtual void | chain () |
| Apply the chain rule to this variable based on the variables on which it depends. More... | |
Public Member Functions inherited from stan::agrad::chainable | |
| chainable () | |
| Construct a chainable object. More... | |
| ~chainable () | |
| Throws a logic exception. More... | |
Static Public Member Functions | |
| static void * | operator new (size_t nbytes) |
| Allocate memory from the underlying memory pool. More... | |
| static void | recover_memory () |
| Recover memory used for all variables for reuse. More... | |
| static void | free_memory () |
| Return all memory used for gradients back to the system. More... | |
Static Public Member Functions inherited from stan::agrad::chainable | |
| static void * | operator new (size_t nbytes) |
| Allocate memory from the underlying memory pool. More... | |
Public Attributes | |
| const double | val_ |
| The value of this variable. More... | |
| double | adj_ |
| The adjoint of this variable, which is the partial derivative of this variable with respect to the root variable. More... | |
Friends | |
| class | var |
| std::ostream & | operator<< (std::ostream &os, const vari *v) |
| Insertion operator for vari. More... | |
The variable implementation base class.
A variable implementation is constructed with a constant value. It also stores the adjoint for storing the partial derivative with respect to the root of the derivative tree.
The chain() method applies the chain rule. Concrete extensions of this class will represent base variables or the result of operations such as addition or subtraction. These extended classes will store operand variables and propagate derivative information via an implementation of chain().
|
inline |
Construct a variable implementation from a value.
The adjoint is initialized to zero.
All constructed variables are added to the stack. Variables should be constructed before variables on which they depend to insure proper partial derivative propagation. During derivative propagation, the chain() method of each variable will be called in the reverse order of construction.
| x | Value of the constructed variable. |
|
inline |
|
inline |
Construct a variable implementation from a value.
The adjoint is initialized to zero.
All constructed variables are added to the stack. Variables should be constructed before variables on which they depend to insure proper partial derivative propagation. During derivative propagation, the chain() method of each variable will be called in the reverse order of construction.
| x | Value of the constructed variable. |
Definition at line 81 of file agrad_thread_safe.hpp.
|
inlinevirtual |
Apply the chain rule to this variable based on the variables on which it depends.
The base implementation in this class is a no-op.
Reimplemented from stan::agrad::chainable.
Reimplemented in stan::agrad::partials_vari, and stan::agrad::gevv_vvv_vari.
Definition at line 92 of file agrad_thread_safe.hpp.
|
inlinestatic |
Return all memory used for gradients back to the system.
Definition at line 122 of file agrad_thread_safe.hpp.
|
inlinevirtual |
Initialize the adjoint for this (dependent) variable to 1.
This operation is applied to the dependent variable before propagating derivatives.
Reimplemented from stan::agrad::chainable.
|
inlinestatic |
Allocate memory from the underlying memory pool.
This memory is is managed by the gradient program and will be recovered as a whole. Classes should not be allocated with this operator if they have non-trivial destructors.
| nbytes | Number of bytes to allocate. |
Definition at line 104 of file agrad_thread_safe.hpp.
|
inlinestatic |
Recover memory used for all variables for reuse.
Definition at line 113 of file agrad_thread_safe.hpp.
|
inlinevirtual |
Set the adjoint value of this variable to 0.
Reimplemented from stan::agrad::chainable.
|
friend |
| double stan::agrad::vari::adj_ |
| const double stan::agrad::vari::val_ |