Stan  1.3
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
stan::agrad::vari Class Reference

The variable implementation base class. More...

#include <agrad_thread_safe.hpp>

Inheritance diagram for stan::agrad::vari:
stan::agrad::chainable stan::agrad::op_ddv_vari stan::agrad::op_ddv_vari stan::agrad::op_dv_vari stan::agrad::op_dv_vari stan::agrad::op_dvd_vari stan::agrad::op_dvd_vari stan::agrad::op_dvv_vari stan::agrad::op_dvv_vari stan::agrad::op_v_vari stan::agrad::op_v_vari stan::agrad::op_vd_vari stan::agrad::op_vd_vari stan::agrad::op_vdd_vari stan::agrad::op_vdd_vari stan::agrad::op_vdv_vari stan::agrad::op_vdv_vari stan::agrad::op_vector_vari stan::agrad::op_vv_vari stan::agrad::op_vv_vari stan::agrad::op_vvd_vari stan::agrad::op_vvd_vari stan::agrad::op_vvv_vari stan::agrad::op_vvv_vari stan::agrad::partials_vari

Public Member Functions

 vari (const double x)
 Construct a variable implementation from a value.
 
virtual void chain ()
 Apply the chain rule to this variable based on the variables on which it depends.
 
 vari (const double x)
 Construct a variable implementation from a value.
 
 vari (const double x, bool stacked)
 
 ~vari ()
 Throw an illegal argument exception.
 
virtual void init_dependent ()
 Initialize the adjoint for this (dependent) variable to 1.
 
virtual void set_zero_adjoint ()
 Set the adjoint value of this variable to 0.
 
- Public Member Functions inherited from stan::agrad::chainable
 chainable ()
 Construct a chainable object.
 
 ~chainable ()
 Chainables are not destructible and should go on the function call stack or be allocated with operator new.
 

Static Public Member Functions

static void * operator new (size_t nbytes)
 Allocate memory from the underlying memory pool.
 
static void recover_memory ()
 Recover memory used for all variables for reuse.
 
static void free_memory ()
 Return all memory used for gradients back to the system.
 
- Static Public Member Functions inherited from stan::agrad::chainable
static void * operator new (size_t nbytes)
 Allocate memory from the underlying memory pool.
 

Public Attributes

const double val_
 The value of this variable.
 
double adj_
 The adjoint of this variable, which is the partial derivative of this variable with respect to the root variable.
 

Friends

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

Detailed Description

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

Definition at line 53 of file agrad_thread_safe.hpp.

Constructor & Destructor Documentation

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

Parameters
xValue of the constructed variable.

Definition at line 82 of file agrad_thread_safe.hpp.

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

Parameters
xValue of the constructed variable.

Definition at line 57 of file vari.hpp.

stan::agrad::vari::vari ( const double  x,
bool  stacked 
)
inline

Definition at line 63 of file vari.hpp.

stan::agrad::vari::~vari ( )
inline

Throw an illegal argument exception.

Warning: Destructors should never called for agrad objects.

Exceptions
Logicexception always.

Definition at line 79 of file vari.hpp.

Member Function Documentation

virtual void stan::agrad::vari::chain ( )
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.

Definition at line 93 of file agrad_thread_safe.hpp.

static void stan::agrad::vari::free_memory ( )
inlinestatic

Return all memory used for gradients back to the system.

Definition at line 123 of file agrad_thread_safe.hpp.

virtual void stan::agrad::vari::init_dependent ( )
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.

Definition at line 88 of file vari.hpp.

static void* stan::agrad::vari::operator new ( size_t  nbytes)
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.

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

Definition at line 105 of file agrad_thread_safe.hpp.

static void stan::agrad::vari::recover_memory ( )
inlinestatic

Recover memory used for all variables for reuse.

Definition at line 114 of file agrad_thread_safe.hpp.

virtual void stan::agrad::vari::set_zero_adjoint ( )
inlinevirtual

Set the adjoint value of this variable to 0.

Reimplemented from stan::agrad::chainable.

Definition at line 95 of file vari.hpp.

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 108 of file vari.hpp.

var
friend

Definition at line 55 of file agrad_thread_safe.hpp.

Member Data Documentation

double stan::agrad::vari::adj_

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

Definition at line 68 of file agrad_thread_safe.hpp.

const double stan::agrad::vari::val_

The value of this variable.

Definition at line 62 of file agrad_thread_safe.hpp.


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

     [ Stan Home Page ] © 2011–2013, Stan Development Team.