![]() |
Stan Math Library
2.15.0
reverse mode automatic differentiation
|
The variable implementation base class. More...
#include <vari.hpp>
Public Member Functions | |
vari (double x) | |
Construct a variable implementation from a value. More... | |
vari (double x, bool stacked) | |
virtual | ~vari () |
Throw an illegal argument exception. More... | |
virtual void | chain () |
Apply the chain rule to this variable based on the variables on which it depends. More... | |
void | init_dependent () |
Initialize the adjoint for this (dependent) variable to 1. More... | |
void | set_zero_adjoint () |
Set the adjoint value of this variable to 0. More... | |
Static Public Member Functions | |
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 | |
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.
This class is complete (not abstract) and may be used for constants.
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().
|
inlineexplicit |
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. |
|
inlinevirtual |
|
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 in stan::math::multiply_mat_vari< TA, 1, CA, double, 1 >, stan::math::multiply_mat_vari< TA, RA, CA, double, CB >, stan::math::multiply_mat_vari< double, 1, CA, TB, 1 >, stan::math::multiply_mat_vari< double, RA, CA, TB, CB >, stan::math::cholesky_scalar, stan::math::cov_exp_quad_vari< T_x, double, T_l >, stan::math::multiply_mat_vari< TA, 1, CA, TB, 1 >, stan::math::cov_exp_quad_vari< T_x, T_sigma, T_l >, stan::math::multiply_mat_vari< TA, RA, CA, TB, CB >, stan::math::cholesky_block, stan::math::precomputed_gradients_vari, stan::math::stored_gradient_vari, stan::math::gevv_vvv_vari, stan::math::sum_v_vari, stan::math::scal_squared_distance_dv_vari, stan::math::scal_squared_distance_vd_vari, stan::math::precomp_vvv_vari, stan::math::precomp_vv_vari, stan::math::precomp_v_vari, and stan::math::scal_squared_distance_vv_vari.
|
inline |
|
inlinestatic |
Delete a pointer from the underlying memory pool.
This no-op implementation enables a subclass to throw exceptions in its constructor. An exception thrown in the constructor of a subclass will result in an error being raised, which is in turn caught and calls delete().
See the discussion of "plugging the memory leak" in: http://www.parashift.com/c++-faq/memory-pools.html
|
inlinestatic |
Allocate memory from the underlying memory pool.
This memory is is managed as a whole externally.
Warning: Classes should not be allocated with this operator if they have non-trivial destructors.
nbytes | Number of bytes to allocate. |
|
inline |
|
friend |
double stan::math::vari::adj_ |
const double stan::math::vari::val_ |