Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
stan::math::vari Class Reference

#include "stan/math/rev/core/vari.hpp"

Inheritance diagram for stan::math::vari:
stan::math::algebra_solver_vari< Fs, F, T, Fx > stan::math::cholesky_block stan::math::cholesky_scalar stan::math::cov_exp_quad_vari< T_x, T_sigma, T_l > stan::math::cov_exp_quad_vari< T_x, double, T_l > stan::math::gevv_vvv_vari stan::math::gp_periodic_cov_vari< T_x, T_sigma, T_l, T_p > stan::math::gp_periodic_cov_vari< T_x, double, T_l, T_p > stan::math::matrix_exp_action_vari< Ta, N, Tb, Cb > stan::math::matrix_exp_action_vari< double, N, Tb, Cb > stan::math::matrix_exp_action_vari< Ta, N, double, Cb > stan::math::multiply_mat_vari< Ta, Ra, Ca, Tb, Cb > stan::math::multiply_mat_vari< double, 1, Ca, Tb, 1 > stan::math::multiply_mat_vari< double, Ra, Ca, Tb, Cb > stan::math::multiply_mat_vari< Ta, 1, Ca, double, 1 > stan::math::multiply_mat_vari< Ta, 1, Ca, Tb, 1 > stan::math::multiply_mat_vari< Ta, Ra, Ca, double, Cb > stan::math::op_ddv_vari stan::math::op_dv_vari stan::math::op_dvd_vari stan::math::op_dvv_vari stan::math::op_matrix_vari stan::math::op_v_vari stan::math::op_vd_vari stan::math::op_vdd_vari stan::math::op_vdv_vari stan::math::op_vector_vari stan::math::op_vv_vari stan::math::op_vvd_vari stan::math::op_vvv_vari stan::math::precomputed_gradients_vari stan::math::stored_gradient_vari stan::math::sum_v_vari

Public Member Functions

 vari (double x)
 
 vari (double x, bool stacked)
 
virtual ~vari ()
 
virtual void chain ()
 
void init_dependent ()
 
void set_zero_adjoint ()
 

Static Public Member Functions

static voidoperator new (size_t nbytes)
 
static void operator delete (void *)
 

Public Attributes

const double val_
 
double adj_
 

Friends

class var
 
std::ostream & operator<< (std::ostream &os, const vari *v)
 

Detailed Description

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().

Definition at line 30 of file vari.hpp.

Constructor & Destructor Documentation

stan::math::vari::vari ( double  x)
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.

Parameters
xValue of the constructed variable.

Definition at line 58 of file vari.hpp.

References stan::math::AutodiffStackSingleton< ChainableT, ChainableAllocT >::instance(), and stan::math::AutodiffStackSingleton< ChainableT, ChainableAllocT >::AutodiffStackStorage::var_stack_.

Referenced by stan::math::algebra_solver_vari< Fs, F, T, Fx >::algebra_solver_vari(), stan::math::cholesky_block::cholesky_block(), stan::math::cholesky_decompose(), stan::math::cholesky_scalar::cholesky_scalar(), stan::math::cov_exp_quad_vari< T_x, T_sigma, T_l >::cov_exp_quad_vari(), stan::math::cov_exp_quad_vari< T_x, double, T_l >::cov_exp_quad_vari(), stan::math::gp_periodic_cov_vari< T_x, T_sigma, T_l, T_p >::gp_periodic_cov_vari(), stan::math::gp_periodic_cov_vari< T_x, double, T_l, T_p >::gp_periodic_cov_vari(), stan::math::matrix_exp_action_vari< Ta, N, Tb, Cb >::matrix_exp_action_vari(), stan::math::matrix_exp_action_vari< double, N, Tb, Cb >::matrix_exp_action_vari(), stan::math::matrix_exp_action_vari< Ta, N, double, Cb >::matrix_exp_action_vari(), stan::math::multiply_mat_vari< Ta, Ra, Ca, Tb, Cb >::multiply_mat_vari(), stan::math::multiply_mat_vari< Ta, 1, Ca, Tb, 1 >::multiply_mat_vari(), stan::math::multiply_mat_vari< double, Ra, Ca, Tb, Cb >::multiply_mat_vari(), stan::math::multiply_mat_vari< double, 1, Ca, Tb, 1 >::multiply_mat_vari(), stan::math::multiply_mat_vari< Ta, Ra, Ca, double, Cb >::multiply_mat_vari(), and stan::math::multiply_mat_vari< Ta, 1, Ca, double, 1 >::multiply_mat_vari().

58  : val_(x), adj_(0.0) {
59  ChainableStack::instance().var_stack_.push_back(this);
60  }
const double val_
Definition: vari.hpp:38
static AutodiffStackStorage & instance()
double adj_
Definition: vari.hpp:44
stan::math::vari::vari ( double  x,
bool  stacked 
)
inline
virtual stan::math::vari::~vari ( )
inlinevirtual

Throw an illegal argument exception.

Warning: Destructors should never called for var objects.

Exceptions
Logicexception always.

Definition at line 76 of file vari.hpp.

76  {
77  // this will never get called
78  }

Member Function Documentation

virtual void stan::math::vari::chain ( )
inlinevirtual
void stan::math::vari::init_dependent ( )
inline

Initialize the adjoint for this (dependent) variable to 1. This operation is applied to the dependent variable before propagating derivatives, setting the derivative of the result with respect to itself to be 1.

Definition at line 93 of file vari.hpp.

Referenced by stan::math::grad().

93 { adj_ = 1.0; }
double adj_
Definition: vari.hpp:44
static void stan::math::vari::operator delete ( void )
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

Definition at line 140 of file vari.hpp.

140  { /* no op */
141  }
static void* stan::math::vari::operator new ( size_t  nbytes)
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.

Parameters
nbytesNumber of bytes to allocate.
Returns
Pointer to allocated bytes.

Definition at line 125 of file vari.hpp.

References stan::math::stack_alloc::alloc(), stan::math::AutodiffStackSingleton< ChainableT, ChainableAllocT >::instance(), stan::math::AutodiffStackSingleton< ChainableT, ChainableAllocT >::AutodiffStackStorage::memalloc_, and nbytes.

125  {
127  }
Long64_t nbytes
static AutodiffStackStorage & instance()
void * alloc(size_t len)
void stan::math::vari::set_zero_adjoint ( )
inline

Set the adjoint value of this variable to 0. This is used to reset adjoints before propagating derivatives again (for example in a Jacobian calculation).

Definition at line 100 of file vari.hpp.

100 { adj_ = 0.0; }
double adj_
Definition: vari.hpp:44

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const vari v 
)
friend

Insertion operator for vari. Prints the current value and the adjoint value.

Parameters
os[in, out] ostream to modify
v[in] vari object to print.
Returns
The modified ostream.

Definition at line 111 of file vari.hpp.

111  {
112  return os << v->val_ << ":" << v->adj_;
113  }
friend class var
friend

Member Data Documentation

double stan::math::vari::adj_

The adjoint of this variable, which is the partial derivative of this variable with respect to the root variable.

Definition at line 44 of file vari.hpp.

Referenced by stan::math::var::adj(), stan::math::scal_squared_distance_vv_vari::chain(), stan::math::internal::rising_factorial_vd_vari::chain(), stan::math::internal::falling_factorial_vd_vari::chain(), stan::math::precomp_v_vari::chain(), stan::math::precomp_vv_vari::chain(), stan::math::precomp_vvv_vari::chain(), stan::math::scal_squared_distance_vd_vari::chain(), stan::math::scal_squared_distance_dv_vari::chain(), stan::math::sum_v_vari::chain(), stan::math::stored_gradient_vari::chain(), stan::math::gevv_vvv_vari::chain(), stan::math::precomputed_gradients_vari::chain(), stan::math::algebra_solver_vari< Fs, F, T, Fx >::chain(), stan::math::cholesky_block::chain(), stan::math::cov_exp_quad_vari< T_x, T_sigma, T_l >::chain(), stan::math::multiply_mat_vari< Ta, Ra, Ca, Tb, Cb >::chain(), stan::math::gp_periodic_cov_vari< T_x, T_sigma, T_l, T_p >::chain(), stan::math::matrix_exp_action_vari< Ta, N, Tb, Cb >::chain(), stan::math::multiply_mat_vari< Ta, 1, Ca, Tb, 1 >::chain(), stan::math::cov_exp_quad_vari< T_x, double, T_l >::chain(), stan::math::cholesky_scalar::chain(), stan::math::matrix_exp_action_vari< double, N, Tb, Cb >::chain(), stan::math::gp_periodic_cov_vari< T_x, double, T_l, T_p >::chain(), stan::math::multiply_mat_vari< double, Ra, Ca, Tb, Cb >::chain(), stan::math::multiply_mat_vari< double, 1, Ca, Tb, 1 >::chain(), stan::math::matrix_exp_action_vari< Ta, N, double, Cb >::chain(), stan::math::multiply_mat_vari< Ta, Ra, Ca, double, Cb >::chain(), stan::math::multiply_mat_vari< Ta, 1, Ca, double, 1 >::chain(), and stan::math::var::grad().

const double stan::math::vari::val_

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