![]() |
Stan
2.5.0
probability, sampling & optimization
|
This is a var implementation class that takes precomputed gradient values. More...
#include <precomputed_gradients.hpp>
Public Member Functions | |
| precomputed_gradients_vari (const double val, std::vector< vari * > &varis, const std::vector< double > &gradients) | |
| Constructs a precomputed_gradients_vari. More... | |
| void | chain () |
| Implements the chain rule for this variable. More... | |
Public Member Functions inherited from stan::agrad::vari | |
| vari (const double x) | |
| Construct a variable implementation from a value. More... | |
| vari (const double x, bool stacked) | |
| virtual | ~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... | |
Public Member Functions inherited from stan::agrad::chainable | |
| chainable () | |
| Construct a chainable object. More... | |
| virtual | ~chainable () |
| Chainables are not destructible and should go on the function call stack or be allocated with operator new. More... | |
Protected Attributes | |
| std::vector< vari * > | varis_ |
| std::vector< double > | gradients_ |
Additional Inherited Members | |
Static Public Member Functions inherited from stan::agrad::chainable | |
| static void * | operator new (size_t nbytes) |
| Allocate memory from the underlying memory pool. More... | |
| static void | operator delete (void *) |
| Delete a pointer from the underlying memory pool. More... | |
Public Attributes inherited from stan::agrad::vari | |
| 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... | |
This is a var implementation class that takes precomputed gradient values.
Stan users should use function precomputed_gradients directly.
Definition at line 20 of file precomputed_gradients.hpp.
|
inline |
Constructs a precomputed_gradients_vari.
The the value, pointers to the varis, and gradient values need to be provided.
Note: this class is slow since it
| val | The value of the variable. |
| varis | Vector of pointers to the varis of independent variables of this class. |
| gradients | Vector of gradients with respect to the independent variables. These must be indexed in the same order as varis. |
| std::invalid_argument | if the sizes don't match |
Definition at line 41 of file precomputed_gradients.hpp.
|
inlinevirtual |
Implements the chain rule for this variable.
Each of the independent variables' adjoints are updated with the appropriate gradient value.
Reimplemented from stan::agrad::chainable.
Definition at line 58 of file precomputed_gradients.hpp.
|
protected |
Definition at line 23 of file precomputed_gradients.hpp.
|
protected |
Definition at line 22 of file precomputed_gradients.hpp.