Stan  1.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
Classes | Typedefs | Functions | Variables
stan::agrad Namespace Reference

Function gradients via reverse-mode automatic differentiation. More...

Classes

struct  var_to_vi
 
struct  var_to_vi< stan::agrad::var >
 
class  chainable
 Abstract base class for variable implementations that handles memory management and applying the chain rule. More...
 
class  vari
 The variable implementation base class. More...
 
class  var
 Independent (input) and dependent (output) variables for gradients. More...
 
class  gevv_vvv_vari
 
struct  needs_promotion
 
struct  assigner
 
struct  assigner< false, LHS, RHS >
 
struct  assigner< true, LHS, RHS >
 
class  partials_vari
 
struct  OperandsAndPartials
 A variable implementation that stores operands and derivatives with respect to the variable. More...
 

Typedefs

typedef stan::math::EigenType
< var >::matrix 
matrix_v
 The type of a matrix holding stan::agrad::var values.
 
typedef stan::math::EigenType
< var >::vector 
vector_v
 The type of a (column) vector holding stan::agrad::var values.
 
typedef stan::math::EigenType
< var >::row_vector 
row_vector_v
 The type of a row vector holding stan::agrad::var values.
 

Functions

static void recover_memory ()
 Recover memory used for all variables for reuse.
 
static void grad (chainable *vi)
 Compute the gradient for all variables starting from the specified root variable implementation.
 
size_t stack_size ()
 Returns the current size of the stack of vari instances.
 
void print_stack (std::ostream &o)
 Prints the auto-dif variable stack.
 
template<typename T >
double as_double (T x)
 Cast variable to double.
 
template<>
double as_double< agrad::var > (agrad::var x)
 Cast variable to double.
 
bool operator== (const var &a, const var &b)
 Equality operator comparing two variables' values (C++).
 
bool operator== (const var &a, const double b)
 Equality operator comparing a variable's value and a double (C++).
 
bool operator== (const double a, const var &b)
 Equality operator comparing a scalar and a variable's value (C++).
 
bool operator!= (const var &a, const var &b)
 Inequality operator comparing two variables' values (C++).
 
bool operator!= (const var &a, const double b)
 Inequality operator comparing a variable's value and a double (C++).
 
bool operator!= (const double a, const var &b)
 Inequality operator comparing a double and a variable's value (C++).
 
bool operator< (const var &a, const var &b)
 Less than operator comparing variables' values (C++).
 
bool operator< (const var &a, const double b)
 Less than operator comparing variable's value and a double (C++).
 
bool operator< (const double a, const var &b)
 Less than operator comparing a double and variable's value (C++).
 
bool operator> (const var &a, const var &b)
 Greater than operator comparing variables' values (C++).
 
bool operator> (const var &a, const double b)
 Greater than operator comparing variable's value and double (C++).
 
bool operator> (const double a, const var &b)
 Greater than operator comparing a double and a variable's value (C++).
 
bool operator<= (const var &a, const var &b)
 Less than or equal operator comparing two variables' values (C++).
 
bool operator<= (const var &a, const double b)
 Less than or equal operator comparing a variable's value and a scalar (C++).
 
bool operator<= (const double a, const var &b)
 Less than or equal operator comparing a double and variable's value (C++).
 
bool operator>= (const var &a, const var &b)
 Greater than or equal operator comparing two variables' values (C++).
 
bool operator>= (const var &a, const double b)
 Greater than or equal operator comparing variable's value and double (C++).
 
bool operator>= (const double a, const var &b)
 Greater than or equal operator comparing double and variable's value (C++).
 
bool operator! (const var &a)
 Prefix logical negation for the value of variables (C++).
 
var operator+ (const var &a)
 Unary plus operator for variables (C++).
 
var operator- (const var &a)
 Unary negation operator for variables (C++).
 
var operator+ (const var &a, const var &b)
 Addition operator for variables (C++).
 
var operator+ (const var &a, const double b)
 Addition operator for variable and scalar (C++).
 
var operator+ (const double a, const var &b)
 Addition operator for scalar and variable (C++).
 
var operator- (const var &a, const var &b)
 Subtraction operator for variables (C++).
 
var operator- (const var &a, const double b)
 Subtraction operator for variable and scalar (C++).
 
var operator- (const double a, const var &b)
 Subtraction operator for scalar and variable (C++).
 
var operator* (const var &a, const var &b)
 Multiplication operator for two variables (C++).
 
var operator* (const var &a, const double b)
 Multiplication operator for a variable and a scalar (C++).
 
var operator* (const double a, const var &b)
 Multiplication operator for a scalar and a variable (C++).
 
var operator/ (const var &a, const var &b)
 Division operator for two variables (C++).
 
var operator/ (const var &a, const double b)
 Division operator for dividing a variable by a scalar (C++).
 
var operator/ (const double a, const var &b)
 Division operator for dividing a scalar by a variable (C++).
 
var & operator++ (var &a)
 Prefix increment operator for variables (C++).
 
var operator++ (var &a, int dummy)
 Postfix increment operator for variables (C++).
 
var & operator-- (var &a)
 Prefix decrement operator for variables (C++).
 
var operator-- (var &a, int dummy)
 Postfix decrement operator for variables (C++).
 
var exp (const var &a)
 Return the exponentiation of the specified variable (cmath).
 
var log (const var &a)
 Return the natural log of the specified variable (cmath).
 
var log10 (const var &a)
 Return the base 10 log of the specified variable (cmath).
 
var sqrt (const var &a)
 Return the square root of the specified variable (cmath).
 
var pow (const var &base, const var &exponent)
 Return the base raised to the power of the exponent (cmath).
 
var pow (const var &base, const double exponent)
 Return the base variable raised to the power of the exponent scalar (cmath).
 
var pow (const double base, const var &exponent)
 Return the base scalar raised to the power of the exponent variable (cmath).
 
var cos (const var &a)
 Return the cosine of a radian-scaled variable (cmath).
 
var sin (const var &a)
 Return the sine of a radian-scaled variable (cmath).
 
var tan (const var &a)
 Return the tangent of a radian-scaled variable (cmath).
 
var acos (const var &a)
 Return the principal value of the arc cosine of a variable, in radians (cmath).
 
var asin (const var &a)
 Return the principal value of the arc sine, in radians, of the specified variable (cmath).
 
var atan (const var &a)
 Return the principal value of the arc tangent, in radians, of the specified variable (cmath).
 
var atan2 (const var &a, const var &b)
 Return the principal value of the arc tangent, in radians, of the first variable divided by the second (cmath).
 
var atan2 (const var &a, const double b)
 Return the principal value of the arc tangent, in radians, of the first variable divided by the second scalar (cmath).
 
var atan2 (const double a, const var &b)
 Return the principal value of the arc tangent, in radians, of the first scalar divided by the second variable (cmath).
 
var cosh (const var &a)
 Return the hyperbolic cosine of the specified variable (cmath).
 
var sinh (const var &a)
 Return the hyperbolic sine of the specified variable (cmath).
 
var tanh (const var &a)
 Return the hyperbolic tangent of the specified variable (cmath).
 
var fabs (const var &a)
 Return the absolute value of the variable (cmath).
 
var floor (const var &a)
 Return the floor of the specified variable (cmath).
 
var ceil (const var &a)
 Return the ceiling of the specified variable (cmath).
 
var fmod (const var &a, const var &b)
 Return the floating point remainder after dividing the first variable by the second (cmath).
 
var fmod (const var &a, const double b)
 Return the floating point remainder after dividing the the first variable by the second scalar (cmath).
 
var fmod (const double a, const var &b)
 Return the floating point remainder after dividing the first scalar by the second variable (cmath).
 
var abs (const var &a)
 Return the absolute value of the variable (std).
 
static void free_memory ()
 Return all memory used for gradients back to the system.
 
static void set_zero_all_adjoints ()
 Reset all adjoint values in the stack to zero.
 
void jacobian (std::vector< var > &dependents, std::vector< var > &independents, std::vector< std::vector< double > > &jacobian)
 Return the Jacobian of the function producing the specified dependent variables with respect to the specified independent variables.
 
bool operator== (const var &a, const double &b)
 Equality operator comparing a variable's value and a double (C++).
 
bool operator== (const double &a, const var &b)
 Equality operator comparing a scalar and a variable's value (C++).
 
bool operator!= (const var &a, const double &b)
 Inequality operator comparing a variable's value and a double (C++).
 
bool operator!= (const double &a, const var &b)
 Inequality operator comparing a double and a variable's value (C++).
 
bool operator< (const var &a, const double &b)
 Less than operator comparing variable's value and a double (C++).
 
bool operator< (const double &a, const var &b)
 Less than operator comparing a double and variable's value (C++).
 
bool operator> (const var &a, const double &b)
 Greater than operator comparing variable's value and double (C++).
 
bool operator> (const double &a, const var &b)
 Greater than operator comparing a double and a variable's value (C++).
 
bool operator<= (const var &a, const double &b)
 Less than or equal operator comparing a variable's value and a scalar (C++).
 
bool operator<= (const double &a, const var &b)
 Less than or equal operator comparing a double and variable's value (C++).
 
bool operator>= (const var &a, const double &b)
 Greater than or equal operator comparing variable's value and double (C++).
 
bool operator>= (const double &a, const var &b)
 Greater than or equal operator comparing double and variable's value (C++).
 
var operator+ (const var &a, const double &b)
 Addition operator for variable and scalar (C++).
 
var operator+ (const double &a, const var &b)
 Addition operator for scalar and variable (C++).
 
var operator- (const var &a, const double &b)
 Subtraction operator for variable and scalar (C++).
 
var operator- (const double &a, const var &b)
 Subtraction operator for scalar and variable (C++).
 
var operator* (const var &a, const double &b)
 Multiplication operator for a variable and a scalar (C++).
 
var operator* (const double &a, const var &b)
 Multiplication operator for a scalar and a variable (C++).
 
var operator/ (const var &a, const double &b)
 Division operator for dividing a variable by a scalar (C++).
 
var operator/ (const double &a, const var &b)
 Division operator for dividing a scalar by a variable (C++).
 
var pow (const var &base, const double &exponent)
 Return the base variable raised to the power of the exponent scalar (cmath).
 
var pow (const double &base, const var &exponent)
 Return the base scalar raised to the power of the exponent variable (cmath).
 
var atan2 (const var &a, const double &b)
 Return the principal value of the arc tangent, in radians, of the first variable divided by the second scalar (cmath).
 
var atan2 (const double &a, const var &b)
 Return the principal value of the arc tangent, in radians, of the first scalar divided by the second variable (cmath).
 
var fmod (const var &a, const double &b)
 Return the floating point remainder after dividing the the first variable by the second scalar (cmath).
 
var fmod (const double &a, const var &b)
 Return the floating point remainder after dividing the first scalar by the second variable (cmath).
 
var determinant (const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &m)
 Determinant of the matrix.
 
row_vector_v row (const matrix_v &m, size_t i)
 Return the specified row minus 1 of the specified matrix.
 
vector_v col (const matrix_v &m, size_t j)
 Return the specified column minus 1 of the specified matrix.
 
vector_v diagonal (const matrix_v &m)
 Return a column vector of the diagonal elements of the specified matrix.
 
matrix_v diag_matrix (const vector_v &v)
 Return a square diagonal matrix with the specified vector of coefficients as the diagonal values.
 
row_vector_v transpose (const vector_v &v)
 Return the transposition of the specified column vector.
 
vector_v transpose (const row_vector_v &rv)
 Return the transposition of the specified row vector.
 
matrix_v transpose (const matrix_v &m)
 Return the transposition of the specified matrix.
 
matrix_v inverse (const matrix_v &m)
 Returns the inverse of the specified matrix.
 
vector_v softmax (const vector_v &v)
 Return the softmax of the specified vector.
 
vector_v eigenvalues (const matrix_v &m)
 Return the real component of the eigenvalues of the specified matrix in descending order of magnitude.
 
matrix_v eigenvectors (const matrix_v &m)
 Return a matrix whose columns are the real components of the eigenvectors of the specified matrix.
 
void eigen_decompose (const matrix_v &m, vector_v &eigenvalues, matrix_v &eigenvectors)
 Assign the real components of the eigenvalues and eigenvectors of the specified matrix to the specified references.
 
vector_v eigenvalues_sym (const matrix_v &m)
 Return the eigenvalues of the specified symmetric matrix in descending order of magnitude.
 
matrix_v eigenvectors_sym (const matrix_v &m)
 Return a matrix whose rows are the real components of the eigenvectors of the specified symmetric matrix.
 
void eigen_decompose_sym (const matrix_v &m, vector_v &eigenvalues, matrix_v &eigenvectors)
 Assign the real components of the eigenvalues and eigenvectors of the specified symmetric matrix to the specified references.
 
matrix_v cholesky_decompose (const matrix_v &m)
 Return the lower-triangular Cholesky factor (i.e., matrix square root) of the specified square, symmetric matrix.
 
vector_v singular_values (const matrix_v &m)
 Return the vector of the singular values of the specified matrix in decreasing order of magnitude.
 
void svd (const matrix_v &m, matrix_v &u, matrix_v &v, vector_v &s)
 Assign the real components of a singular value decomposition of the specified matrix to the specified references.
 
void stan_print (std::ostream *o, const var &x)
 
void initialize_variable (var &variable, const var &value)
 Initialize variable to value.
 
template<int R, int C>
void initialize_variable (Eigen::Matrix< var, R, C > &matrix, const var &value)
 Initialize every cell in the matrix to the specified value.
 
template<typename T >
void initialize_variable (std::vector< T > &variables, const var &value)
 Initialize the variables in the standard vector recursively.
 
var to_var (const double &x)
 Converts argument to an automatic differentiation variable.
 
void to_var (const double &x, var &var_x)
 Converts argument to an automatic differentiation variable.
 
var to_var (const var &x)
 Converts argument to an automatic differentiation variable.
 
void to_var (const var &var_in, var &var_out)
 Converts argument to an automatic differentiation variable.
 
matrix_v to_var (const stan::math::matrix_d &m)
 Converts argument to an automatic differentiation variable.
 
void to_var (const stan::math::matrix_d &m, matrix_v &m_v)
 Converts argument to an automatic differentiation variable.
 
matrix_v to_var (const matrix_v &m)
 Converts argument to an automatic differentiation variable.
 
void to_var (const matrix_v &m_in, matrix_v &m_out)
 Converts argument to an automatic differentiation variable.
 
vector_v to_var (const stan::math::vector_d &v)
 Converts argument to an automatic differentiation variable.
 
void to_var (const stan::math::vector_d &v, vector_v &v_v)
 Converts argument to an automatic differentiation variable.
 
vector_v to_var (const vector_v &v)
 Converts argument to an automatic differentiation variable.
 
void to_var (const vector_v &v_in, vector_v &v_out)
 Converts argument to an automatic differentiation variable.
 
row_vector_v to_var (const stan::math::row_vector_d &rv)
 Converts argument to an automatic differentiation variable.
 
void to_var (const stan::math::row_vector_d &rv, row_vector_v &rv_v)
 Converts argument to an automatic differentiation variable.
 
row_vector_v to_var (const row_vector_v &rv)
 Converts argument to an automatic differentiation variable.
 
void to_var (const row_vector_v &rv_in, row_vector_v &rv_out)
 Converts argument to an automatic differentiation variable.
 
size_t rows (const vector_v &v)
 Return number of rows.
 
size_t rows (const row_vector_v &rv)
 Return number of rows.
 
size_t rows (const matrix_v &m)
 Return number of rows.
 
size_t cols (const vector_v &v)
 Return number of columns.
 
size_t cols (const row_vector_v &rv)
 Return number of columns.
 
size_t cols (const matrix_v &m)
 Return number of columns.
 
template<int R, int C>
var dot_self (const Eigen::Matrix< var, R, C > &v)
 Returns the dot product of a vector with itself.
 
template<int R1, int C1, int R2, int C2>
var dot_product (const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< var, R2, C2 > &v2)
 Returns the dot product.
 
template<int R1, int C1, int R2, int C2>
var dot_product (const Eigen::Matrix< var, R1, C1 > &v1, const Eigen::Matrix< double, R2, C2 > &v2)
 Returns the dot product.
 
template<int R1, int C1, int R2, int C2>
var dot_product (const Eigen::Matrix< double, R1, C1 > &v1, const Eigen::Matrix< var, R2, C2 > &v2)
 Returns the dot product.
 
var dot_product (const var *v1, const var *v2, size_t length)
 Returns the dot product.
 
var dot_product (const var *v1, const double *v2, size_t length)
 Returns the dot product.
 
var dot_product (const double *v1, const var *v2, size_t length)
 Returns the dot product.
 
var dot_product (const std::vector< var > &v1, const std::vector< var > &v2)
 Returns the dot product.
 
var dot_product (const std::vector< var > &v1, const std::vector< double > &v2)
 Returns the dot product.
 
var dot_product (const std::vector< double > &v1, const std::vector< var > &v2)
 Returns the dot product.
 
template<int R, int C>
var sum (const Eigen::Matrix< var, R, C > &m)
 Returns the sum of the coefficients of the specified matrix, column vector or row vector.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
add (const Eigen::Matrix< T1, R, C > &v1, const Eigen::Matrix< T2, R, C > &v2)
 Return the sum of the specified column vectors.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
add (const Eigen::Matrix< T1, R, C > &m, const T2 &c)
 Return the sum of a matrix or vector and a scalar.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
add (const T1 &c, const Eigen::Matrix< T2, R, C > &m)
 Return the sum of a scalar and a matrix or vector.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
subtract (const Eigen::Matrix< T1, R, C > &v1, const Eigen::Matrix< T2, R, C > &v2)
 Return the difference between the first specified column vector and the second.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
subtract (const Eigen::Matrix< T1, R, C > &m, const T2 &c)
 Return the difference between a matrix or vector and a scalar.
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R, C > 
subtract (const T1 &c, const Eigen::Matrix< T2, R, C > &m)
 Return the difference between a scalar and a matrix or vector.
 
template<typename T >
T minus (const T &v)
 Return the negation of the specified variable.
 
template<typename T , int R, int C>
Eigen::Matrix< T, R, C > minus (const Eigen::Matrix< T, R, C > &v)
 Return the negation of the specified column vector.
 
double divide (double x, double y)
 Return the division of the first scalar by the second scalar.
 
template<typename T1 , typename T2 >
var divide (const T1 &v, const T2 &c)
 
template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix< var, R, C > divide (const Eigen::Matrix< T1, R, C > &v, const T2 &c)
 Return the division of the specified column vector by the specified scalar.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
Eigen::Dynamic, Eigen::Dynamic > 
elt_multiply (const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &m1, const Eigen::Matrix< T2, Eigen::Dynamic, Eigen::Dynamic > &m2)
 Return the elementwise product of the specified matrices.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
Eigen::Dynamic, 1 > 
elt_multiply (const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &v1, const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &v2)
 Return the elementwise product of the specified vectors.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
1, Eigen::Dynamic > 
elt_multiply (const Eigen::Matrix< T1, 1, Eigen::Dynamic > &v1, const Eigen::Matrix< T2, 1, Eigen::Dynamic > &v2)
 Return the elementwise product of the specified row vectors.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
Eigen::Dynamic, Eigen::Dynamic > 
elt_divide (const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &m1, const Eigen::Matrix< T2, Eigen::Dynamic, Eigen::Dynamic > &m2)
 Return the elementwise division of the specified matrices.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
Eigen::Dynamic, 1 > 
elt_divide (const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &v1, const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &v2)
 Return the elementwise division of the specified vectors.
 
template<typename T1 , typename T2 >
Eigen::Matrix
< stan::agrad::var,
1, Eigen::Dynamic > 
elt_divide (const Eigen::Matrix< T1, 1, Eigen::Dynamic > &v1, const Eigen::Matrix< T2, 1, Eigen::Dynamic > &v2)
 Return the elementwise division of the specified row vectors.
 
template<typename T1 , typename T2 >
boost::math::tools::promote_args
< T1, T2 >::type 
multiply (const T1 &v, const T2 &c)
 Return the product of two scalars.
 
template<typename T1 , typename T2 , int R2, int C2>
Eigen::Matrix< var, R2, C2 > multiply (const T1 &c, const Eigen::Matrix< T2, R2, C2 > &m)
 Return the product of scalar and matrix.
 
template<typename T1 , int R1, int C1, typename T2 >
Eigen::Matrix< var, R1, C1 > multiply (const Eigen::Matrix< T1, R1, C1 > &m, const T2 &c)
 Return the product of scalar and matrix.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > multiply (const Eigen::Matrix< var, R1, C1 > &m1, const Eigen::Matrix< var, R2, C2 > &m2)
 Return the product of the specified matrices.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > multiply (const Eigen::Matrix< double, R1, C1 > &m1, const Eigen::Matrix< var, R2, C2 > &m2)
 Return the product of the specified matrices.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > multiply (const Eigen::Matrix< var, R1, C1 > &m1, const Eigen::Matrix< double, R2, C2 > &m2)
 Return the product of the specified matrices.
 
template<int C1, int R2>
var multiply (const Eigen::Matrix< var, 1, C1 > &rv, const Eigen::Matrix< var, R2, 1 > &v)
 Return the scalar product of the specified row vector and specified column vector.
 
template<int C1, int R2>
var multiply (const Eigen::Matrix< double, 1, C1 > &rv, const Eigen::Matrix< var, R2, 1 > &v)
 Return the scalar product of the specified row vector and specified column vector.
 
template<int C1, int R2>
var multiply (const Eigen::Matrix< var, 1, C1 > &rv, const Eigen::Matrix< double, R2, 1 > &v)
 Return the scalar product of the specified row vector and specified column vector.
 
matrix_v multiply_lower_tri_self_transpose (const matrix_v &L)
 
matrix_v tcrossprod (const matrix_v &M)
 Returns the result of post-multiplying a matrix by its own transpose.
 
matrix_v crossprod (const matrix_v &M)
 Returns the result of pre-multiplying a matrix by its own transpose.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri_low (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri_low (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< double, R2, C2 > &b)
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri_low (const Eigen::Matrix< double, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 
Eigen::Matrix< var,
Eigen::Dynamic, Eigen::Dynamic > 
mdivide_left_tri_low (const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &A)
 
template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 Returns the solution of the system Ax=b when A is triangular.
 
template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< double, R2, C2 > &b)
 Returns the solution of the system Ax=b when A is triangular.
 
template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left_tri (const Eigen::Matrix< double, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 Returns the solution of the system Ax=b when A is triangular.
 
template<int TriView>
Eigen::Matrix< var,
Eigen::Dynamic, Eigen::Dynamic > 
mdivide_left_tri (const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &A)
 Returns the solution of the system Ax=b when A is triangular and b = I.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 Returns the solution of the system Ax=b.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left (const Eigen::Matrix< double, R1, C1 > &A, const Eigen::Matrix< var, R2, C2 > &b)
 Returns the solution of the system Ax=b.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_left (const Eigen::Matrix< var, R1, C1 > &A, const Eigen::Matrix< double, R2, C2 > &b)
 Returns the solution of the system Ax=b.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_right (const Eigen::Matrix< var, R1, C1 > &b, const Eigen::Matrix< var, R2, C2 > &A)
 Returns the solution x of the system xA = b.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_right (const Eigen::Matrix< double, R1, C1 > &b, const Eigen::Matrix< var, R2, C2 > &A)
 Returns the solution x of the system xA = b.
 
template<int R1, int C1, int R2, int C2>
Eigen::Matrix< var, R1, C2 > mdivide_right (const Eigen::Matrix< var, R1, C1 > &b, const Eigen::Matrix< double, R2, C2 > &A)
 Returns the solution x of the system xA = b.
 
template<int TriView, typename T1 , typename T2 , int R1, int C1, int R2, int C2>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R1, C2 > 
mdivide_right_tri (const Eigen::Matrix< T1, R1, C1 > &b, const Eigen::Matrix< T2, R2, C2 > &A)
 Returns the solution of the system Ax=b when A is triangular.
 
template<typename T1 , typename T2 , int R1, int C1, int R2, int C2>
Eigen::Matrix< typename
boost::math::tools::promote_args
< T1, T2 >::type, R1, C2 > 
mdivide_right_tri_low (const Eigen::Matrix< T1, R1, C1 > &b, const Eigen::Matrix< T2, R2, C2 > &A)
 Returns the solution of the system tri(A)x=b when tri(A) is a triangular view of A.
 
void assign_to_var (stan::agrad::var &var, const double &val)
 
void assign_to_var (stan::agrad::var &var, const stan::agrad::var &val)
 
void assign_to_var (int &n_lhs, const int &n_rhs)
 
void assign_to_var (double &n_lhs, const double &n_rhs)
 
template<typename T_result , class Policy >
bool check_pos_definite (const char *function, const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name, T_result *result, const Policy &)
 
template<typename LHS , typename RHS >
void assign_to_var (std::vector< LHS > &x, const std::vector< RHS > &y)
 
template<typename LHS , typename RHS >
void assign_to_var (Eigen::Matrix< LHS, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< RHS, Eigen::Dynamic, 1 > &y)
 
template<typename LHS , typename RHS >
void assign_to_var (Eigen::Matrix< LHS, 1, Eigen::Dynamic > &x, const Eigen::Matrix< RHS, 1, Eigen::Dynamic > &y)
 
template<typename LHS , typename RHS >
void assign_to_var (Eigen::Matrix< LHS, Eigen::Dynamic, Eigen::Dynamic > &x, const Eigen::Matrix< RHS, Eigen::Dynamic, Eigen::Dynamic > &y)
 
template<typename LHS , typename RHS >
void assign (LHS &var, const RHS &val)
 
var acosh (const stan::agrad::var &a)
 The inverse hyperbolic cosine function for variables (C99).
 
var asinh (const stan::agrad::var &a)
 The inverse hyperbolic sine function for variables (C99).
 
var atanh (const stan::agrad::var &a)
 The inverse hyperbolic tangent function for variables (C99).
 
var erf (const stan::agrad::var &a)
 The error function for variables (C99).
 
var erfc (const stan::agrad::var &a)
 The complementary error function for variables (C99).
 
var exp2 (const stan::agrad::var &a)
 Exponentiation base 2 function for variables (C99).
 
var expm1 (const stan::agrad::var &a)
 The exponentiation of the specified variable minus 1 (C99).
 
var lgamma (const stan::agrad::var &a)
 The log gamma function for variables (C99).
 
var log1p (const stan::agrad::var &a)
 The log (1 + x) function for variables (C99).
 
var log1m (const stan::agrad::var &a)
 The log (1 - x) function for variables.
 
var fma (const stan::agrad::var &a, const stan::agrad::var &b, const stan::agrad::var &c)
 The fused multiply-add function for three variables (C99).
 
var fma (const stan::agrad::var &a, const stan::agrad::var &b, const double &c)
 The fused multiply-add function for two variables and a value (C99).
 
var fma (const stan::agrad::var &a, const double &b, const stan::agrad::var &c)
 The fused multiply-add function for a variable, value, and variable (C99).
 
var fma (const stan::agrad::var &a, const double &b, const double &c)
 The fused multiply-add function for a variable and two values (C99).
 
var fma (const double &a, const stan::agrad::var &b, const double &c)
 The fused multiply-add function for a value, variable, and value (C99).
 
var fma (const double &a, const double &b, const stan::agrad::var &c)
 The fused multiply-add function for two values and a variable, and value (C99).
 
var fma (const double &a, const stan::agrad::var &b, const stan::agrad::var &c)
 The fused multiply-add function for a value and two variables (C99).
 
var fmax (const stan::agrad::var &a, const stan::agrad::var &b)
 Returns the maximum of the two variable arguments (C99).
 
var fmax (const stan::agrad::var &a, const double &b)
 Returns the maximum of the variable and scalar, promoting the scalar to a variable if it is larger (C99).
 
var fmax (const double &a, const stan::agrad::var &b)
 Returns the maximum of a scalar and variable, promoting the scalar to a variable if it is larger (C99).
 
var fmin (const stan::agrad::var &a, const stan::agrad::var &b)
 Returns the minimum of the two variable arguments (C99).
 
var fmin (const stan::agrad::var &a, const double &b)
 Returns the minimum of the variable and scalar, promoting the scalar to a variable if it is larger (C99).
 
var fmin (const double &a, const stan::agrad::var &b)
 Returns the minimum of a scalar and variable, promoting the scalar to a variable if it is larger (C99).
 
var hypot (const stan::agrad::var &a, const stan::agrad::var &b)
 Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).
 
var hypot (const stan::agrad::var &a, const double &b)
 Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).
 
var hypot (const double &a, const stan::agrad::var &b)
 Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).
 
var log2 (const stan::agrad::var &a)
 Returns the base 2 logarithm of the specified variable (C99).
 
var cbrt (const stan::agrad::var &a)
 Returns the cube root of the specified variable (C99).
 
var round (const stan::agrad::var &a)
 Returns the rounded form of the specified variable (C99).
 
var trunc (const stan::agrad::var &a)
 Returns the truncatation of the specified variable (C99).
 
var fdim (const stan::agrad::var &a, const stan::agrad::var &b)
 Return the positive difference between the first variable's the value and the second's (C99).
 
var fdim (const double &a, const stan::agrad::var &b)
 Return the positive difference between the first value and the value of the second variable (C99).
 
var fdim (const stan::agrad::var &a, const double &b)
 Return the positive difference between the first variable's value and the second value (C99).
 
var tgamma (const stan::agrad::var &a)
 Return the Gamma function applied to the specified variable (C99).
 
var step (const stan::agrad::var &a)
 Return the step, or heaviside, function applied to the specified variable (stan).
 
var inv_cloglog (const stan::agrad::var &a)
 Return the inverse complementary log-log function applied specified variable (stan).
 
var Phi (const stan::agrad::var &a)
 The unit normal cumulative density function for variables (stan).
 
var inv_logit (const stan::agrad::var &a)
 The inverse logit function for variables (stan).
 
var log_loss (const int &y, const stan::agrad::var &y_hat)
 The log loss function for variables (stan).
 
var log1p_exp (const stan::agrad::var &a)
 Return the log of 1 plus the exponential of the specified variable.
 
var log_sum_exp (const stan::agrad::var &a, const stan::agrad::var &b)
 Returns the log sum of exponentials.
 
var log_sum_exp (const stan::agrad::var &a, const double &b)
 Returns the log sum of exponentials.
 
var log_sum_exp (const double &a, const stan::agrad::var &b)
 Returns the log sum of exponentials.
 
var log_sum_exp (const std::vector< var > &x)
 Returns the log sum of exponentials.
 
var square (const var &x)
 Return the square of the input variable.
 
var multiply_log (const var &a, const var &b)
 Return the value of a*log(b).
 
var multiply_log (const var &a, const double b)
 Return the value of a*log(b).
 
var multiply_log (const double a, const var &b)
 Return the value of a*log(b).
 
var if_else (bool c, const var &y_true, const var &y_false)
 If the specified condition is true, return the first variable, otherwise return the second variable.
 
var if_else (bool c, double y_true, const var &y_false)
 If the specified condition is true, return a new variable constructed from the first scalar, otherwise return the second variable.
 
var if_else (bool c, const var &y_true, const double y_false)
 If the specified condition is true, return the first variable, otherwise return a new variable constructed from the second scalar.
 
var ibeta (const var &a, const var &b, const var &x)
 The normalized incomplete beta function of a, b, and x.
 
double value_of (const agrad::var &v)
 Return the value of the specified variable.
 

Variables

std::vector< chainable * > var_stack_
 
memory::stack_alloc memalloc_
 

Detailed Description

Function gradients via reverse-mode automatic differentiation.

Typedef Documentation

The type of a matrix holding stan::agrad::var values.

Definition at line 246 of file matrix.hpp.

The type of a row vector holding stan::agrad::var values.

Definition at line 258 of file matrix.hpp.

The type of a (column) vector holding stan::agrad::var values.

Definition at line 252 of file matrix.hpp.

Function Documentation

var stan::agrad::abs ( const var &  a)
inline

Return the absolute value of the variable (std).

The value at the undifferentiable point 0 is conveniently set 0, so that

$\frac{d}{dx}|x| = \mbox{sgn}(x)$.

The function fabs() provides identical behavior, with abs() defined in stdlib.h and fabs() defined in cmath.

Parameters
aVariable input.
Returns
Absolute value of variable.

Definition at line 2193 of file agrad.hpp.

var stan::agrad::acos ( const var &  a)
inline

Return the principal value of the arc cosine of a variable, in radians (cmath).

The derivative is defined by

$\frac{d}{dx} \arccos x = \frac{-1}{\sqrt{1 - x^2}}$.

Parameters
aVariable in range [-1,1].
Returns
Arc cosine of variable, in radians.

Definition at line 1920 of file agrad.hpp.

var stan::agrad::acosh ( const stan::agrad::var &  a)
inline

The inverse hyperbolic cosine function for variables (C99).

For non-variable function, see boost::math::acosh().

The derivative is defined by

$\frac{d}{dx} \mbox{acosh}(x) = \frac{x}{x^2 - 1}$.

Parameters
aThe variable.
Returns
Inverse hyperbolic cosine of the variable.

Definition at line 659 of file special_functions.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::add ( const Eigen::Matrix< T1, R, C > &  v1,
const Eigen::Matrix< T2, R, C > &  v2 
)
inline

Return the sum of the specified column vectors.

The two vectors must have the same size.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Sum of the two vectors.
Exceptions
std::domain_errorif size of v1 is not equal to size of v2.

Definition at line 1033 of file matrix.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::add ( const Eigen::Matrix< T1, R, C > &  m,
const T2 &  c 
)
inline

Return the sum of a matrix or vector and a scalar.

Parameters
[in]mMatrix or vector.
[in]cScalar.
Returns
Matrix or Vector plus the scalar.

Definition at line 1046 of file matrix.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::add ( const T1 &  c,
const Eigen::Matrix< T2, R, C > &  m 
)
inline

Return the sum of a scalar and a matrix or vector.

Parameters
[in]cScalar.
[in]mMatrix or vector.
Returns
Scalar plus vector.

Definition at line 1058 of file matrix.hpp.

template<typename T >
double stan::agrad::as_double ( T  x)
inline

Cast variable to double.

Useful for templated functions where a variable may be a var or a double and we want to be able to use things like printf().

Parameters
xVariable to cast.
Template Parameters
TType of variable.

Definition at line 1186 of file agrad.hpp.

template<>
double stan::agrad::as_double< agrad::var > ( agrad::var  x)
inline

Cast variable to double.

Useful for templated functions where a variable may be a var or a double and we want to be able to use things like printf(). This specialization makes it possible to say as_double(x) where x is a var, not a double or int or something for which casts already exist.

Parameters
xVariable to cast.
Template Parameters
TType of variable.

Definition at line 1199 of file agrad.hpp.

var stan::agrad::asin ( const var &  a)
inline

Return the principal value of the arc sine, in radians, of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \arcsin x = \frac{1}{\sqrt{1 - x^2}}$.

Parameters
aVariable in range [-1,1].
Returns
Arc sine of variable, in radians.

Definition at line 1935 of file agrad.hpp.

var stan::agrad::asinh ( const stan::agrad::var &  a)
inline

The inverse hyperbolic sine function for variables (C99).

For non-variable function, see boost::math::asinh().

The derivative is defined by

$\frac{d}{dx} \mbox{asinh}(x) = \frac{x}{x^2 + 1}$.

Parameters
aThe variable.
Returns
Inverse hyperbolic sine of the variable.

Definition at line 675 of file special_functions.hpp.

template<typename LHS , typename RHS >
void stan::agrad::assign ( LHS &  var,
const RHS &  val 
)
inline

Definition at line 2062 of file matrix.hpp.

void stan::agrad::assign_to_var ( stan::agrad::var &  var,
const double &  val 
)
inline

Definition at line 1964 of file matrix.hpp.

void stan::agrad::assign_to_var ( stan::agrad::var &  var,
const stan::agrad::var &  val 
)
inline

Definition at line 1967 of file matrix.hpp.

void stan::agrad::assign_to_var ( int &  n_lhs,
const int &  n_rhs 
)
inline

Definition at line 1971 of file matrix.hpp.

void stan::agrad::assign_to_var ( double &  n_lhs,
const double &  n_rhs 
)
inline

Definition at line 1975 of file matrix.hpp.

template<typename LHS , typename RHS >
void stan::agrad::assign_to_var ( std::vector< LHS > &  x,
const std::vector< RHS > &  y 
)
inline

Definition at line 1996 of file matrix.hpp.

template<typename LHS , typename RHS >
void stan::agrad::assign_to_var ( Eigen::Matrix< LHS, Eigen::Dynamic, 1 > &  x,
const Eigen::Matrix< RHS, Eigen::Dynamic, 1 > &  y 
)
inline

Definition at line 2001 of file matrix.hpp.

template<typename LHS , typename RHS >
void stan::agrad::assign_to_var ( Eigen::Matrix< LHS, 1, Eigen::Dynamic > &  x,
const Eigen::Matrix< RHS, 1, Eigen::Dynamic > &  y 
)
inline

Definition at line 2010 of file matrix.hpp.

template<typename LHS , typename RHS >
void stan::agrad::assign_to_var ( Eigen::Matrix< LHS, Eigen::Dynamic, Eigen::Dynamic > &  x,
const Eigen::Matrix< RHS, Eigen::Dynamic, Eigen::Dynamic > &  y 
)
inline

Definition at line 2019 of file matrix.hpp.

var stan::agrad::atan ( const var &  a)
inline

Return the principal value of the arc tangent, in radians, of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \arctan x = \frac{1}{1 + x^2}$.

Parameters
aVariable in range [-1,1].
Returns
Arc tangent of variable, in radians.

Definition at line 1950 of file agrad.hpp.

var stan::agrad::atan2 ( const var &  a,
const double &  b 
)
inline

Return the principal value of the arc tangent, in radians, of the first variable divided by the second scalar (cmath).

The derivative with respect to the variable is

$ $ \frac{d}{d x} \arctan \frac{x}{c} = \frac{c}{x^2 + c^2}$.

Parameters
aNumerator variable.
bDenominator scalar.
Returns
The arc tangent of the fraction, in radians.

Definition at line 1788 of file agrad_thread_safe.hpp.

var stan::agrad::atan2 ( const double &  a,
const var &  b 
)
inline

Return the principal value of the arc tangent, in radians, of the first scalar divided by the second variable (cmath).

The derivative with respect to the variable is

$ $ \frac{\partial}{\partial y} \arctan \frac{c}{y} = \frac{-c}{c^2 + y^2}$.

Parameters
aNumerator scalar.
bDenominator variable.
Returns
The arc tangent of the fraction, in radians.

Definition at line 1804 of file agrad_thread_safe.hpp.

var stan::agrad::atan2 ( const var &  a,
const var &  b 
)
inline

Return the principal value of the arc tangent, in radians, of the first variable divided by the second (cmath).

The partial derivatives are defined by

$ $ \frac{\partial}{\partial x} \arctan \frac{x}{y} = \frac{y}{x^2 + y^2}$, and

$ $ \frac{\partial}{\partial y} \arctan \frac{x}{y} = \frac{-x}{x^2 + y^2}$.

Parameters
aNumerator variable.
bDenominator variable.
Returns
The arc tangent of the fraction, in radians.

Definition at line 1968 of file agrad.hpp.

var stan::agrad::atan2 ( const var &  a,
const double  b 
)
inline

Return the principal value of the arc tangent, in radians, of the first variable divided by the second scalar (cmath).

The derivative with respect to the variable is

$ $ \frac{d}{d x} \arctan \frac{x}{c} = \frac{c}{x^2 + c^2}$.

Parameters
aNumerator variable.
bDenominator scalar.
Returns
The arc tangent of the fraction, in radians.

Definition at line 1984 of file agrad.hpp.

var stan::agrad::atan2 ( const double  a,
const var &  b 
)
inline

Return the principal value of the arc tangent, in radians, of the first scalar divided by the second variable (cmath).

The derivative with respect to the variable is

$ $ \frac{\partial}{\partial y} \arctan \frac{c}{y} = \frac{-c}{c^2 + y^2}$.

Parameters
aNumerator scalar.
bDenominator variable.
Returns
The arc tangent of the fraction, in radians.

Definition at line 2000 of file agrad.hpp.

var stan::agrad::atanh ( const stan::agrad::var &  a)
inline

The inverse hyperbolic tangent function for variables (C99).

For non-variable function, see boost::math::atanh().

The derivative is defined by

$\frac{d}{dx} \mbox{atanh}(x) = \frac{1}{1 - x^2}$.

Parameters
aThe variable.
Returns
Inverse hyperbolic tangent of the variable.

Definition at line 691 of file special_functions.hpp.

var stan::agrad::cbrt ( const stan::agrad::var &  a)
inline

Returns the cube root of the specified variable (C99).

See boost::math::cbrt() for the double-based version.

The derivative is

$\frac{d}{dx} x^{1/3} = \frac{1}{3 x^{2/3}}$.

Parameters
aSpecified variable.
Returns
Cube root of the variable.

Definition at line 1176 of file special_functions.hpp.

var stan::agrad::ceil ( const var &  a)
inline

Return the ceiling of the specified variable (cmath).

The derivative of the ceiling function is defined and zero everywhere but at integers, and we set them to zero for convenience,

$\frac{d}{dx} {\lceil x \rceil} = 0$.

The ceiling function rounds up. For double values, this is the smallest integral value that is not less than the specified value. Although this function is not differentiable because it is discontinuous at integral values, its gradient is returned as zero everywhere.

Parameters
aInput variable.
Returns
Ceiling of the variable.

Definition at line 2117 of file agrad.hpp.

template<typename T_result , class Policy >
bool stan::agrad::check_pos_definite ( const char *  function,
const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &  y,
const char *  name,
T_result *  result,
const Policy &   
)
inline

Definition at line 1980 of file matrix.hpp.

matrix_v stan::agrad::cholesky_decompose ( const matrix_v &  m)

Return the lower-triangular Cholesky factor (i.e., matrix square root) of the specified square, symmetric matrix.

The return value $L$ will be a lower-traingular matrix such that the original matrix $A$ is given by

$A = L \times L^T$.

Parameters
[in]mSymmetrix matrix.
Returns
Square root of matrix.
Exceptions
std::domain_errorif m is not a square matrix

Definition at line 103 of file matrix.cpp.

vector_v stan::agrad::col ( const matrix_v &  m,
size_t  j 
)

Return the specified column minus 1 of the specified matrix.

Thus indexing is from 1, not 0, and this method returns the equivalent of the Eigen matrix call m.col(j - 1).

Parameters
[in]mMatrix.
[in]jColumn index (plus 1); between 1 and the number of columns of m inclusive.
Returns
Specified column of the matrix.
Exceptions
std::domain_errorif the index is 0 or greater than the number of columns.

Definition at line 21 of file matrix.cpp.

size_t stan::agrad::cols ( const vector_v &  v)
inline

Return number of columns.

Returns the number of columns in the specified column vector. The return value is always 1.

Parameters
vSpecified vector.
Returns
Number of columns in the vector.

Definition at line 545 of file matrix.hpp.

size_t stan::agrad::cols ( const row_vector_v &  rv)
inline

Return number of columns.

Returns the number of columns in the specified row vector.

Parameters
rvSpecified vector.
Returns
Number of columns in the vector.

Definition at line 557 of file matrix.hpp.

size_t stan::agrad::cols ( const matrix_v &  m)
inline

Return number of columns.

Return the number of columns in the specified matrix.

Parameters
mSpecified matrix.
Returns
Number of columns in the matrix.

Definition at line 568 of file matrix.hpp.

var stan::agrad::cos ( const var &  a)
inline

Return the cosine of a radian-scaled variable (cmath).

The derivative is defined by

$\frac{d}{dx} \cos x = - \sin x$.

Parameters
aVariable for radians of angle.
Returns
Cosine of variable.

Definition at line 1877 of file agrad.hpp.

var stan::agrad::cosh ( const var &  a)
inline

Return the hyperbolic cosine of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \cosh x = \sinh x$.

Parameters
aVariable.
Returns
Hyperbolic cosine of variable.

Definition at line 2016 of file agrad.hpp.

matrix_v stan::agrad::crossprod ( const matrix_v &  M)
inline

Returns the result of pre-multiplying a matrix by its own transpose.

Parameters
MMatrix to multiply.
Returns
Transpose of M times M

Definition at line 1527 of file matrix.hpp.

var stan::agrad::determinant ( const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &  m)

Determinant of the matrix.

Returns the determinant of the specified square matrix.

Parameters
mSpecified matrix.
Returns
Determinant of the matrix.
Exceptions
std::domain_errorif m is not a square matrix

Definition at line 10 of file matrix.cpp.

matrix_v stan::agrad::diag_matrix ( const vector_v &  v)

Return a square diagonal matrix with the specified vector of coefficients as the diagonal values.

Parameters
[in]vSpecified vector.
Returns
Diagonal matrix with vector as diagonal values.

Definition at line 30 of file matrix.cpp.

vector_v stan::agrad::diagonal ( const matrix_v &  m)

Return a column vector of the diagonal elements of the specified matrix.

The matrix is not required to be square.

Parameters
[in]mSpecified matrix.
Returns
Diagonal of the matrix.

Definition at line 26 of file matrix.cpp.

double stan::agrad::divide ( double  x,
double  y 
)
inline

Return the division of the first scalar by the second scalar.

Parameters
[in]vSpecified vector.
[in]cSpecified scalar.
Returns
Vector divided by the scalar.

Definition at line 1133 of file matrix.hpp.

template<typename T1 , typename T2 >
var stan::agrad::divide ( const T1 &  v,
const T2 &  c 
)
inline

Definition at line 1138 of file matrix.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<var,R,C> stan::agrad::divide ( const Eigen::Matrix< T1, R, C > &  v,
const T2 &  c 
)
inline

Return the division of the specified column vector by the specified scalar.

Parameters
[in]vSpecified vector.
[in]cSpecified scalar.
Returns
Vector divided by the scalar.

Definition at line 1150 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
var stan::agrad::dot_product ( const Eigen::Matrix< var, R1, C1 > &  v1,
const Eigen::Matrix< var, R2, C2 > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First column vector.
[in]v2Second column vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif length of v1 is not equal to length of v2.

Definition at line 893 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
var stan::agrad::dot_product ( const Eigen::Matrix< var, R1, C1 > &  v1,
const Eigen::Matrix< double, R2, C2 > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First column vector.
[in]v2Second column vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif length of v1 is not equal to length of v2 or either v1 or v2 are not vectors.

Definition at line 910 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
var stan::agrad::dot_product ( const Eigen::Matrix< double, R1, C1 > &  v1,
const Eigen::Matrix< var, R2, C2 > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First column vector.
[in]v2Second column vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif length of v1 is not equal to length of v2 or either v1 or v2 are not vectors.

Definition at line 927 of file matrix.hpp.

var stan::agrad::dot_product ( const var *  v1,
const var *  v2,
size_t  length 
)
inline

Returns the dot product.

Parameters
[in]v1First array.
[in]v2Second array.
[in]lengthLength of both arrays.
Returns
Dot product of the arrays.

Definition at line 942 of file matrix.hpp.

var stan::agrad::dot_product ( const var *  v1,
const double *  v2,
size_t  length 
)
inline

Returns the dot product.

Parameters
[in]v1First array.
[in]v2Second array.
[in]lengthLength of both arrays.
Returns
Dot product of the arrays.

Definition at line 953 of file matrix.hpp.

var stan::agrad::dot_product ( const double *  v1,
const var *  v2,
size_t  length 
)
inline

Returns the dot product.

Parameters
[in]v1First array.
[in]v2Second array.
[in]lengthLength of both arrays.
Returns
Dot product of the arrays.

Definition at line 964 of file matrix.hpp.

var stan::agrad::dot_product ( const std::vector< var > &  v1,
const std::vector< var > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif sizes of v1 and v2 do not match.

Definition at line 975 of file matrix.hpp.

var stan::agrad::dot_product ( const std::vector< var > &  v1,
const std::vector< double > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif sizes of v1 and v2 do not match.

Definition at line 988 of file matrix.hpp.

var stan::agrad::dot_product ( const std::vector< double > &  v1,
const std::vector< var > &  v2 
)
inline

Returns the dot product.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Dot product of the vectors.
Exceptions
std::domain_errorif sizes of v1 and v2 do not match.

Definition at line 1001 of file matrix.hpp.

template<int R, int C>
var stan::agrad::dot_self ( const Eigen::Matrix< var, R, C > &  v)
inline

Returns the dot product of a vector with itself.

Parameters
[in]vVector.
Returns
Dot product of the vector with itself.
Template Parameters
Rnumber of rows or Eigen::Dynamic for dynamic; one of R or C must be 1
Cnumber of rows or Eigen::Dyanmic for dynamic; one of R or C must be 1

Definition at line 879 of file matrix.hpp.

void stan::agrad::eigen_decompose ( const matrix_v &  m,
vector_v &  eigenvalues,
matrix_v &  eigenvectors 
)

Assign the real components of the eigenvalues and eigenvectors of the specified matrix to the specified references.

Given an input matrix $A$, the eigenvalues will be found in $D$ in descending order of magnitude. The eigenvectors will be written into the columns of $V$. If $A$ is invertible, then

$A = V \times \mbox{\rm diag}(D) \times V^{-1}$, where $ $\mbox{\rm diag}(D)$ is the square diagonal matrix with diagonal elements $D$ and $V^{-1}$ is the inverse of $V$.

Parameters
[in]mSpecified matrix.
[out]eigenvaluesColumn vector reference into which eigenvalues are written.
[out]eigenvectorsMatrix reference into which eigenvectors are written.

Definition at line 73 of file matrix.cpp.

void stan::agrad::eigen_decompose_sym ( const matrix_v &  m,
vector_v &  eigenvalues,
matrix_v &  eigenvectors 
)

Assign the real components of the eigenvalues and eigenvectors of the specified symmetric matrix to the specified references.

See eigen_decompose() for more information on the values.

Parameters
[in]mSymmetric matrix. This function is more efficient than the general decomposition method for symmetric matrices.
[out]eigenvaluesColumn vector reference into which eigenvalues are written.
[out]eigenvectorsMatrix reference into which eigenvectors are written.

Definition at line 95 of file matrix.cpp.

vector_v stan::agrad::eigenvalues ( const matrix_v &  m)

Return the real component of the eigenvalues of the specified matrix in descending order of magnitude.

See eigen_decompose() for more information.

Parameters
[in]mSpecified matrix.
Returns
Eigenvalues of matrix.

Definition at line 58 of file matrix.cpp.

vector_v stan::agrad::eigenvalues_sym ( const matrix_v &  m)

Return the eigenvalues of the specified symmetric matrix in descending order of magnitude.

This function is more efficient than the general eigenvalues function for symmetric matrices.

See eigen_decompose() for more information.

Parameters
[in]mSpecified matrix.
Returns
Eigenvalues of matrix.

Definition at line 81 of file matrix.cpp.

matrix_v stan::agrad::eigenvectors ( const matrix_v &  m)

Return a matrix whose columns are the real components of the eigenvectors of the specified matrix.

See eigen_decompose() for more information.

Parameters
[in]mSpecified matrix.
Returns
Eigenvectors of matrix.

Definition at line 66 of file matrix.cpp.

matrix_v stan::agrad::eigenvectors_sym ( const matrix_v &  m)

Return a matrix whose rows are the real components of the eigenvectors of the specified symmetric matrix.

This function is more efficient than the general eigenvectors function for symmetric matrices.

See eigen_decompose() for more information.

Parameters
[in]mSymmetric matrix.
Returns
Eigenvectors of matrix.

Definition at line 88 of file matrix.cpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,Eigen::Dynamic,Eigen::Dynamic> stan::agrad::elt_divide ( const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &  m1,
const Eigen::Matrix< T2, Eigen::Dynamic, Eigen::Dynamic > &  m2 
)
inline

Return the elementwise division of the specified matrices.

Parameters
[in]m1First matrix.
[in]m2Second matrix.
Returns
Elementwise division of the matrices.

Definition at line 1214 of file matrix.hpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,Eigen::Dynamic,1> stan::agrad::elt_divide ( const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &  v1,
const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &  v2 
)
inline

Return the elementwise division of the specified vectors.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Elementwise division of the vectors.

Definition at line 1232 of file matrix.hpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,1,Eigen::Dynamic> stan::agrad::elt_divide ( const Eigen::Matrix< T1, 1, Eigen::Dynamic > &  v1,
const Eigen::Matrix< T2, 1, Eigen::Dynamic > &  v2 
)
inline

Return the elementwise division of the specified row vectors.

Parameters
[in]v1First row vector.
[in]v2Second row vector.
Returns
Elementwise division of the row vectors.

Definition at line 1248 of file matrix.hpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,Eigen::Dynamic,Eigen::Dynamic> stan::agrad::elt_multiply ( const Eigen::Matrix< T1, Eigen::Dynamic, Eigen::Dynamic > &  m1,
const Eigen::Matrix< T2, Eigen::Dynamic, Eigen::Dynamic > &  m2 
)
inline

Return the elementwise product of the specified matrices.

Parameters
[in]m1First matrix.
[in]m2Second matrix.
Returns
Elementwise product of the matrices.

Definition at line 1162 of file matrix.hpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,Eigen::Dynamic,1> stan::agrad::elt_multiply ( const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &  v1,
const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &  v2 
)
inline

Return the elementwise product of the specified vectors.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
Elementwise product of the vectors.

Definition at line 1180 of file matrix.hpp.

template<typename T1 , typename T2 >
Eigen::Matrix<stan::agrad::var,1,Eigen::Dynamic> stan::agrad::elt_multiply ( const Eigen::Matrix< T1, 1, Eigen::Dynamic > &  v1,
const Eigen::Matrix< T2, 1, Eigen::Dynamic > &  v2 
)
inline

Return the elementwise product of the specified row vectors.

Parameters
[in]v1First row vector.
[in]v2Second row vector.
Returns
Elementwise product of the row vectors.

Definition at line 1196 of file matrix.hpp.

var stan::agrad::erf ( const stan::agrad::var &  a)
inline

The error function for variables (C99).

For non-variable function, see boost::math::erf()

The derivative is

$\frac{d}{dx} \mbox{erf}(x) = \frac{2}{\sqrt{\pi}} \exp(-x^2)$.

Parameters
aThe variable.
Returns
Error function applied to the variable.

Definition at line 707 of file special_functions.hpp.

var stan::agrad::erfc ( const stan::agrad::var &  a)
inline

The complementary error function for variables (C99).

For non-variable function, see boost::math::erfc().

The derivative is

$\frac{d}{dx} \mbox{erfc}(x) = - \frac{2}{\sqrt{\pi}} \exp(-x^2)$.

Parameters
aThe variable.
Returns
Complementary error function applied to the variable.

Definition at line 723 of file special_functions.hpp.

var stan::agrad::exp ( const var &  a)
inline

Return the exponentiation of the specified variable (cmath).

Parameters
aVariable to exponentiate.
Returns
Exponentiated variable.

Definition at line 1760 of file agrad.hpp.

var stan::agrad::exp2 ( const stan::agrad::var &  a)
inline

Exponentiation base 2 function for variables (C99).

For non-variable function, see boost::math::exp2().

The derivatie is

$\frac{d}{dx} 2^x = (\log 2) 2^x$.

Parameters
aThe variable.
Returns
Two to the power of the specified variable.

Definition at line 739 of file special_functions.hpp.

var stan::agrad::expm1 ( const stan::agrad::var &  a)
inline

The exponentiation of the specified variable minus 1 (C99).

For non-variable function, see boost::math::expm1().

The derivative is given by

$\frac{d}{dx} \exp(a) - 1 = \exp(a)$.

Parameters
aThe variable.
Returns
Two to the power of the specified variable.

Definition at line 755 of file special_functions.hpp.

var stan::agrad::fabs ( const var &  a)
inline

Return the absolute value of the variable (cmath).

Choosing an arbitrary value at the non-differentiable point 0,

$\frac{d}{dx}|x| = \mbox{sgn}(x)$.

where $\mbox{sgn}(x)$ is the signum function, taking values -1 if $x < 0$, 0 if $x == 0$, and 1 if $x == 1$.

The function abs() provides the same behavior, with abs() defined in stdlib.h and fabs() defined in cmath.

Parameters
aInput variable.
Returns
Absolute value of variable.

Definition at line 2067 of file agrad.hpp.

var stan::agrad::fdim ( const stan::agrad::var &  a,
const stan::agrad::var &  b 
)
inline

Return the positive difference between the first variable's the value and the second's (C99).

See stan::math::fdim() for the double-based version.

The partial derivative with respect to the first argument is

$\frac{\partial}{\partial x} \mbox{fdim}(x,y) = 0.0$ if $x < y$, and

$\frac{\partial}{\partial x} \mbox{fdim}(x,y) = 1.0$ if $x \geq y$.

With respect to the second argument, the partial is

$\frac{\partial}{\partial y} \mbox{fdim}(x,y) = 0.0$ if $x < y$, and

$\frac{\partial}{\partial y} \mbox{fdim}(x,y) = -\lfloor\frac{x}{y}\rfloor$ if $x \geq y$.

Parameters
aFirst variable.
bSecond variable.
Returns
The positive difference between the first and second variable.

Definition at line 1239 of file special_functions.hpp.

var stan::agrad::fdim ( const double &  a,
const stan::agrad::var &  b 
)
inline

Return the positive difference between the first value and the value of the second variable (C99).

See fdim(var,var) for definitions of values and derivatives.

The derivative with respect to the variable is

$\frac{d}{d y} \mbox{fdim}(c,y) = 0.0$ if $c < y$, and

$\frac{d}{d y} \mbox{fdim}(c,y) = -\lfloor\frac{c}{y}\rfloor$ if $c \geq y$.

Parameters
aFirst value.
bSecond variable.
Returns
The positive difference between the first and second arguments.

Definition at line 1264 of file special_functions.hpp.

var stan::agrad::fdim ( const stan::agrad::var &  a,
const double &  b 
)
inline

Return the positive difference between the first variable's value and the second value (C99).

See fdim(var,var) for definitions of values and derivatives.

The derivative with respect to the variable is

$\frac{d}{d x} \mbox{fdim}(x,c) = 0.0$ if $x < c$, and

$\frac{d}{d x} \mbox{fdim}(x,c) = 1.0$ if $x \geq yc$.

Parameters
aFirst value.
bSecond variable.
Returns
The positive difference between the first and second arguments.

Definition at line 1287 of file special_functions.hpp.

var stan::agrad::floor ( const var &  a)
inline

Return the floor of the specified variable (cmath).

The derivative of the fllor function is defined and zero everywhere but at integers, so we set these derivatives to zero for convenience,

$\frac{d}{dx} {\lfloor x \rfloor} = 0$.

The floor function rounds down. For double values, this is the largest integral value that is not greater than the specified value. Although this function is not differentiable because it is discontinuous at integral values, its gradient is returned as zero everywhere.

Parameters
aInput variable.
Returns
Floor of the variable.

Definition at line 2095 of file agrad.hpp.

var stan::agrad::fma ( const stan::agrad::var &  a,
const stan::agrad::var &  b,
const stan::agrad::var &  c 
)
inline

The fused multiply-add function for three variables (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The partial derivatives are

$\frac{\partial}{\partial x} (x * y) + z = y$, and

$\frac{\partial}{\partial y} (x * y) + z = x$, and

$\frac{\partial}{\partial z} (x * y) + z = 1$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 822 of file special_functions.hpp.

var stan::agrad::fma ( const stan::agrad::var &  a,
const stan::agrad::var &  b,
const double &  c 
)
inline

The fused multiply-add function for two variables and a value (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The partial derivatives are

$\frac{\partial}{\partial x} (x * y) + c = y$, and

$\frac{\partial}{\partial y} (x * y) + c = x$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 846 of file special_functions.hpp.

var stan::agrad::fma ( const stan::agrad::var &  a,
const double &  b,
const stan::agrad::var &  c 
)
inline

The fused multiply-add function for a variable, value, and variable (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The partial derivatives are

$\frac{\partial}{\partial x} (x * c) + z = c$, and

$\frac{\partial}{\partial z} (x * c) + z = 1$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 870 of file special_functions.hpp.

var stan::agrad::fma ( const stan::agrad::var &  a,
const double &  b,
const double &  c 
)
inline

The fused multiply-add function for a variable and two values (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The derivative is

$\frac{d}{d x} (x * c) + d = c$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 892 of file special_functions.hpp.

var stan::agrad::fma ( const double &  a,
const stan::agrad::var &  b,
const double &  c 
)
inline

The fused multiply-add function for a value, variable, and value (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The derivative is

$\frac{d}{d y} (c * y) + d = c$, and

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 914 of file special_functions.hpp.

var stan::agrad::fma ( const double &  a,
const double &  b,
const stan::agrad::var &  c 
)
inline

The fused multiply-add function for two values and a variable, and value (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The derivative is

$\frac{\partial}{\partial z} (c * d) + z = 1$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 936 of file special_functions.hpp.

var stan::agrad::fma ( const double &  a,
const stan::agrad::var &  b,
const stan::agrad::var &  c 
)
inline

The fused multiply-add function for a value and two variables (C99).

This function returns the product of the first two arguments plus the third argument.

See boost::math::fma() for the double-based version.

The partial derivaties are

$\frac{\partial}{\partial y} (c * y) + z = c$, and

$\frac{\partial}{\partial z} (c * y) + z = 1$.

Parameters
aFirst multiplicand.
bSecond multiplicand.
cSummand.
Returns
Product of the multiplicands plus the summand, ($a * $b) + $c.

Definition at line 960 of file special_functions.hpp.

var stan::agrad::fmax ( const stan::agrad::var &  a,
const stan::agrad::var &  b 
)
inline

Returns the maximum of the two variable arguments (C99).

See boost::math::fmax() for the double-based version.

No new variable implementations are created, with this function defined as if by

fmax(a,b) = a if a's value is greater than b's, and .

fmax(a,b) = b if b's value is greater than or equal to a's.

Parameters
aFirst variable.
bSecond variable.
Returns
If the first variable's value is larger than the second's, the first variable, otherwise the second variable.

Definition at line 984 of file special_functions.hpp.

var stan::agrad::fmax ( const stan::agrad::var &  a,
const double &  b 
)
inline

Returns the maximum of the variable and scalar, promoting the scalar to a variable if it is larger (C99).

See boost::math::fmax() for the double-based version.

For fmax(a,b), if a's value is greater than b, then a is returned, otherwise a fesh variable implementation wrapping the value b is returned.

Parameters
aFirst variable.
bSecond value
Returns
If the first variable's value is larger than or equal to the second value, the first variable, otherwise the second value promoted to a fresh variable.

Definition at line 1005 of file special_functions.hpp.

var stan::agrad::fmax ( const double &  a,
const stan::agrad::var &  b 
)
inline

Returns the maximum of a scalar and variable, promoting the scalar to a variable if it is larger (C99).

See boost::math::fmax() for the double-based version.

For fmax(a,b), if a is greater than b's value, then a fresh variable implementation wrapping a is returned, otherwise b is returned.

Parameters
aFirst value.
bSecond variable.
Returns
If the first value is larger than the second variable's value, return the first value promoted to a variable, otherwise return the second variable.

Definition at line 1026 of file special_functions.hpp.

var stan::agrad::fmin ( const stan::agrad::var &  a,
const stan::agrad::var &  b 
)
inline

Returns the minimum of the two variable arguments (C99).

See boost::math::fmin() for the double-based version.

For fmin(a,b), if a's value is less than b's, then a is returned, otherwise b is returned.

Parameters
aFirst variable.
bSecond variable.
Returns
If the first variable's value is smaller than the second's, the first variable, otherwise the second variable.

Definition at line 1044 of file special_functions.hpp.

var stan::agrad::fmin ( const stan::agrad::var &  a,
const double &  b 
)
inline

Returns the minimum of the variable and scalar, promoting the scalar to a variable if it is larger (C99).

See boost::math::fmin() for the double-based version.

For fmin(a,b), if a's value is less than b, then a is returned, otherwise a fresh variable wrapping b is returned.

Parameters
aFirst variable.
bSecond value
Returns
If the first variable's value is less than or equal to the second value, the first variable, otherwise the second value promoted to a fresh variable.

Definition at line 1063 of file special_functions.hpp.

var stan::agrad::fmin ( const double &  a,
const stan::agrad::var &  b 
)
inline

Returns the minimum of a scalar and variable, promoting the scalar to a variable if it is larger (C99).

See boost::math::fmin() for the double-based version.

For fmin(a,b), if a is less than b's value, then a fresh variable implementation wrapping a is returned, otherwise b is returned.

Parameters
aFirst value.
bSecond variable.
Returns
If the first value is smaller than the second variable's value, return the first value promoted to a variable, otherwise return the second variable.

Definition at line 1084 of file special_functions.hpp.

var stan::agrad::fmod ( const var &  a,
const double &  b 
)
inline

Return the floating point remainder after dividing the the first variable by the second scalar (cmath).

The derivative with respect to the variable is

$\frac{d}{d x} \mbox{fmod}(x,c) = \frac{1}{c}$.

Parameters
aFirst variable.
bSecond scalar.
Returns
Floating pointer remainder of dividing the first variable by the second scalar.

Definition at line 1958 of file agrad_thread_safe.hpp.

var stan::agrad::fmod ( const double &  a,
const var &  b 
)
inline

Return the floating point remainder after dividing the first scalar by the second variable (cmath).

The derivative with respect to the variable is

$\frac{d}{d y} \mbox{fmod}(c,y) = -\lfloor \frac{c}{y} \rfloor$.

Parameters
aFirst scalar.
bSecond variable.
Returns
Floating pointer remainder of dividing first scalar by the second variable.

Definition at line 1975 of file agrad_thread_safe.hpp.

var stan::agrad::fmod ( const var &  a,
const var &  b 
)
inline

Return the floating point remainder after dividing the first variable by the second (cmath).

The partial derivatives with respect to the variables are defined everywhere but where $x = y$, but we set these to match other values, with

$\frac{\partial}{\partial x} \mbox{fmod}(x,y) = 1$, and

$\frac{\partial}{\partial y} \mbox{fmod}(x,y) = -\lfloor \frac{x}{y} \rfloor$.

Parameters
aFirst variable.
bSecond variable.
Returns
Floating pointer remainder of dividing the first variable by the second.

Definition at line 2138 of file agrad.hpp.

var stan::agrad::fmod ( const var &  a,
const double  b 
)
inline

Return the floating point remainder after dividing the the first variable by the second scalar (cmath).

The derivative with respect to the variable is

$\frac{d}{d x} \mbox{fmod}(x,c) = \frac{1}{c}$.

Parameters
aFirst variable.
bSecond scalar.
Returns
Floating pointer remainder of dividing the first variable by the second scalar.

Definition at line 2155 of file agrad.hpp.

var stan::agrad::fmod ( const double  a,
const var &  b 
)
inline

Return the floating point remainder after dividing the first scalar by the second variable (cmath).

The derivative with respect to the variable is

$\frac{d}{d y} \mbox{fmod}(c,y) = -\lfloor \frac{c}{y} \rfloor$.

Parameters
aFirst scalar.
bSecond variable.
Returns
Floating pointer remainder of dividing first scalar by the second variable.

Definition at line 2172 of file agrad.hpp.

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

Return all memory used for gradients back to the system.

Definition at line 2215 of file agrad.hpp.

static void stan::agrad::grad ( chainable *  vi)
static

Compute the gradient for all variables starting from the specified root variable implementation.

Does not recover memory. This chainable variable's adjoint is initialized using the method init_dependent() and then the chain rule is applied working down the stack from this chainable and calling each chainable's chain() method in turn.

Parameters
viVariable implementation for root of partial derivative propagation.

Definition at line 2231 of file agrad.hpp.

var stan::agrad::hypot ( const stan::agrad::var &  a,
const stan::agrad::var &  b 
)
inline

Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).

See boost::math::hypot() for double-based function.

The partial derivatives are given by

$\frac{\partial}{\partial x} \sqrt{x^2 + y^2} = \frac{x}{\sqrt{x^2 + y^2}}$, and

$\frac{\partial}{\partial y} \sqrt{x^2 + y^2} = \frac{y}{\sqrt{x^2 + y^2}}$.

Parameters
aLength of first side.
bLength of second side.
Returns
Length of hypoteneuse.

Definition at line 1105 of file special_functions.hpp.

var stan::agrad::hypot ( const stan::agrad::var &  a,
const double &  b 
)
inline

Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).

See boost::math::hypot() for double-based function.

The derivative is

$\frac{d}{d x} \sqrt{x^2 + c^2} = \frac{x}{\sqrt{x^2 + c^2}}$.

Parameters
aLength of first side.
bLength of second side.
Returns
Length of hypoteneuse.

Definition at line 1124 of file special_functions.hpp.

var stan::agrad::hypot ( const double &  a,
const stan::agrad::var &  b 
)
inline

Returns the length of the hypoteneuse of a right triangle with sides of the specified lengths (C99).

See boost::math::hypot() for double-based function.

The derivative is

$\frac{d}{d y} \sqrt{c^2 + y^2} = \frac{y}{\sqrt{c^2 + y^2}}$.

Parameters
aLength of first side.
bLength of second side.
Returns
Length of hypoteneuse.

Definition at line 1143 of file special_functions.hpp.

var stan::agrad::ibeta ( const var &  a,
const var &  b,
const var &  x 
)
inline

The normalized incomplete beta function of a, b, and x.

Used to compute the cumulative density function for the beta distribution.

Partial derivatives are those specified by wolfram alpha. The values were checked using both finite differences and by independent code for calculating the derivatives found in JSS (paper by Boik and Robison-Cox).

Parameters
aShape parameter.
bShape parameter.
xRandom variate.
Returns
The normalized incomplete beta function.

Definition at line 1561 of file special_functions.hpp.

var stan::agrad::if_else ( bool  c,
const var &  y_true,
const var &  y_false 
)
inline

If the specified condition is true, return the first variable, otherwise return the second variable.

Parameters
cBoolean condition.
y_trueVariable to return if condition is true.
y_falseVariable to return if condition is false.

Definition at line 1510 of file special_functions.hpp.

var stan::agrad::if_else ( bool  c,
double  y_true,
const var &  y_false 
)
inline

If the specified condition is true, return a new variable constructed from the first scalar, otherwise return the second variable.

Parameters
cBoolean condition.
y_trueValue to promote to variable and return if condition is true.
y_falseVariable to return if condition is false.

Definition at line 1522 of file special_functions.hpp.

var stan::agrad::if_else ( bool  c,
const var &  y_true,
const double  y_false 
)
inline

If the specified condition is true, return the first variable, otherwise return a new variable constructed from the second scalar.

Parameters
cBoolean condition.
y_trueVariable to return if condition is true.
y_falseValue to promote to variable and return if condition is false.

Definition at line 1537 of file special_functions.hpp.

void stan::agrad::initialize_variable ( var &  variable,
const var &  value 
)
inline

Initialize variable to value.

(Function may look pointless, but its needed to bottom out recursion.)

Definition at line 264 of file matrix.hpp.

template<int R, int C>
void stan::agrad::initialize_variable ( Eigen::Matrix< var, R, C > &  matrix,
const var &  value 
)
inline

Initialize every cell in the matrix to the specified value.

Definition at line 273 of file matrix.hpp.

template<typename T >
void stan::agrad::initialize_variable ( std::vector< T > &  variables,
const var &  value 
)
inline

Initialize the variables in the standard vector recursively.

Definition at line 282 of file matrix.hpp.

var stan::agrad::inv_cloglog ( const stan::agrad::var &  a)
inline

Return the inverse complementary log-log function applied specified variable (stan).

See stan::math::inv_cloglog() for the double-based version.

The derivative is given by

$\frac{d}{dx} \mbox{cloglog}^{-1}(x) = \exp (x - \exp (x))$.

Parameters
aVariable argument.
Returns
The inverse complementary log-log of the specified argument.

Definition at line 1348 of file special_functions.hpp.

var stan::agrad::inv_logit ( const stan::agrad::var &  a)
inline

The inverse logit function for variables (stan).

See stan::math::inv_logit() for the double-based version.

The derivative of inverse logit is

$\frac{d}{dx} \mbox{logit}^{-1}(x) = \mbox{logit}^{-1}(x) (1 - \mbox{logit}^{-1}(x))$.

Parameters
aArgument variable.
Returns
Inverse logit of argument.

Definition at line 1380 of file special_functions.hpp.

matrix_v stan::agrad::inverse ( const matrix_v &  m)

Returns the inverse of the specified matrix.

Parameters
[in]mSpecified matrix.
Returns
Inverse of the matrix.

Definition at line 46 of file matrix.cpp.

void stan::agrad::jacobian ( std::vector< var > &  dependents,
std::vector< var > &  independents,
std::vector< std::vector< double > > &  jacobian 
)
inline

Return the Jacobian of the function producing the specified dependent variables with respect to the specified independent variables.

A typical use case would be to take the Jacobian of a function from independent variables to dependentant variables. For instance,

std::vector<var> f(std::vector<var>& x) { ... }
std::vector<var> x = ...;
std::vector<var> y = f(x);
std::vector<std::vector<double> > J;
jacobian(y,x,J);

After executing this code, J will contain the Jacobian, stored as a standard vector of gradients. Specifically, J[m] will be the gradient of y[m] with respect to x, and thus J[m][n] will be dy[m]/dx[n].

Parameters
[in]dependentsDependent (output) variables.
[in]independentsIndepent (input) variables.
[out]jacobianJacobian of the transform.

Definition at line 2282 of file agrad.hpp.

var stan::agrad::lgamma ( const stan::agrad::var &  a)
inline

The log gamma function for variables (C99).

The derivatie is the digamma function,

$\frac{d}{dx} \Gamma(x) = \psi^{(0)}(x)$.

Parameters
aThe variable.
Returns
Log gamma of the variable.

Definition at line 769 of file special_functions.hpp.

var stan::agrad::log ( const var &  a)
inline

Return the natural log of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \log x = \frac{1}{x}$.

Parameters
aVariable whose log is taken.
Returns
Natural log of variable.

Definition at line 1774 of file agrad.hpp.

var stan::agrad::log10 ( const var &  a)
inline

Return the base 10 log of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \log_{10} x = \frac{1}{x \log 10}$.

Parameters
aVariable whose log is taken.
Returns
Base 10 log of variable.

Definition at line 1788 of file agrad.hpp.

var stan::agrad::log1m ( const stan::agrad::var &  a)
inline

The log (1 - x) function for variables.

The derivative is given by

$\frac{d}{dx} \log (1 - x) = -\frac{1}{1 - x}$.

Parameters
aThe variable.
Returns
The variable representing log of 1 minus the variable.

Definition at line 798 of file special_functions.hpp.

var stan::agrad::log1p ( const stan::agrad::var &  a)
inline

The log (1 + x) function for variables (C99).

The derivative is given by

$\frac{d}{dx} \log (1 + x) = \frac{1}{1 + x}$.

Parameters
aThe variable.
Returns
The log of 1 plus the variable.

Definition at line 784 of file special_functions.hpp.

var stan::agrad::log1p_exp ( const stan::agrad::var &  a)
inline

Return the log of 1 plus the exponential of the specified variable.

Definition at line 1410 of file special_functions.hpp.

var stan::agrad::log2 ( const stan::agrad::var &  a)
inline

Returns the base 2 logarithm of the specified variable (C99).

See stan::math::log2() for the double-based version.

The derivative is

$\frac{d}{dx} \log_2 x = \frac{1}{x \log 2}$.

Parameters
aSpecified variable.
Returns
Base 2 logarithm of the variable.

Definition at line 1160 of file special_functions.hpp.

var stan::agrad::log_loss ( const int &  y,
const stan::agrad::var &  y_hat 
)
inline

The log loss function for variables (stan).

See stan::math::log_loss() for the double-based version.

The derivative with respect to the variable $\hat{y}$ is

$\frac{d}{d\hat{y}} \mbox{logloss}(1,\hat{y}) = - \frac{1}{\hat{y}}$, and

$\frac{d}{d\hat{y}} \mbox{logloss}(0,\hat{y}) = \frac{1}{1 - \hat{y}}$.

Parameters
yReference value.
y_hatResponse variable.
Returns
Log loss of response versus reference value.

Definition at line 1399 of file special_functions.hpp.

var stan::agrad::log_sum_exp ( const stan::agrad::var &  a,
const stan::agrad::var &  b 
)
inline

Returns the log sum of exponentials.

Definition at line 1417 of file special_functions.hpp.

var stan::agrad::log_sum_exp ( const stan::agrad::var &  a,
const double &  b 
)
inline

Returns the log sum of exponentials.

Definition at line 1424 of file special_functions.hpp.

var stan::agrad::log_sum_exp ( const double &  a,
const stan::agrad::var &  b 
)
inline

Returns the log sum of exponentials.

Definition at line 1431 of file special_functions.hpp.

var stan::agrad::log_sum_exp ( const std::vector< var > &  x)
inline

Returns the log sum of exponentials.

Definition at line 1438 of file special_functions.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b.

Parameters
[in]AMatrix.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1718 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left ( const Eigen::Matrix< double, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b.

Parameters
[in]AMatrix.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1733 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< double, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b.

Parameters
[in]AMatrix.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1749 of file matrix.hpp.

template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b when A is triangular.

Parameters
[in]ATriangular matrix. Upper or lower is defined by TriView being either Eigen::Upper or Eigen::Lower.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1652 of file matrix.hpp.

template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< double, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b when A is triangular.

Parameters
[in]ATriangular matrix. Upper or lower is defined by TriView being either Eigen::Upper or Eigen::Lower.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1668 of file matrix.hpp.

template<int TriView, int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri ( const Eigen::Matrix< double, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Returns the solution of the system Ax=b when A is triangular.

Parameters
[in]ATriangular matrix. Upper or lower is defined by TriView being either Eigen::Upper or Eigen::Lower.
[in]bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1684 of file matrix.hpp.

template<int TriView>
Eigen::Matrix<var,Eigen::Dynamic,Eigen::Dynamic> stan::agrad::mdivide_left_tri ( const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &  A)
inline

Returns the solution of the system Ax=b when A is triangular and b = I.

Parameters
[in]ATriangular matrix. Upper or lower is defined by TriView being either Eigen::Upper or Eigen::Lower.
Returns
x = A^-1 .
Exceptions
std::domain_errorif A is not square

Definition at line 1700 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri_low ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Definition at line 1609 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri_low ( const Eigen::Matrix< var, R1, C1 > &  A,
const Eigen::Matrix< double, R2, C2 > &  b 
)
inline

Definition at line 1618 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_left_tri_low ( const Eigen::Matrix< double, R1, C1 > &  A,
const Eigen::Matrix< var, R2, C2 > &  b 
)
inline

Definition at line 1625 of file matrix.hpp.

Eigen::Matrix<var,Eigen::Dynamic,Eigen::Dynamic> stan::agrad::mdivide_left_tri_low ( const Eigen::Matrix< var, Eigen::Dynamic, Eigen::Dynamic > &  A)
inline

Definition at line 1633 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_right ( const Eigen::Matrix< var, R1, C1 > &  b,
const Eigen::Matrix< var, R2, C2 > &  A 
)
inline

Returns the solution x of the system xA = b.

Parameters
[in]bRight hand side matrix or vector.
[in]AMatrix.
Returns
x = b A^-1, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the cols of b don't match the size of A.

Definition at line 1765 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_right ( const Eigen::Matrix< double, R1, C1 > &  b,
const Eigen::Matrix< var, R2, C2 > &  A 
)
inline

Returns the solution x of the system xA = b.

Parameters
[in]bRight hand side matrix or vector.
[in]AMatrix.
Returns
x = b A^-1, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the cols of b don't match the size of A.

Definition at line 1780 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::mdivide_right ( const Eigen::Matrix< var, R1, C1 > &  b,
const Eigen::Matrix< double, R2, C2 > &  A 
)
inline

Returns the solution x of the system xA = b.

Parameters
[in]bRight hand side matrix or vector.
[in]AMatrix.
Returns
x = b A^-1, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the cols of b don't match the size of A.

Definition at line 1795 of file matrix.hpp.

template<int TriView, typename T1 , typename T2 , int R1, int C1, int R2, int C2>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R1,C2> stan::agrad::mdivide_right_tri ( const Eigen::Matrix< T1, R1, C1 > &  b,
const Eigen::Matrix< T2, R2, C2 > &  A 
)
inline

Returns the solution of the system Ax=b when A is triangular.

Parameters
Amatrix.
bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Template Parameters
TriViewtriangular view of data, Eigen::Upper or Eigen::Lower
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1813 of file matrix.hpp.

template<typename T1 , typename T2 , int R1, int C1, int R2, int C2>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type,R1,C2> stan::agrad::mdivide_right_tri_low ( const Eigen::Matrix< T1, R1, C1 > &  b,
const Eigen::Matrix< T2, R2, C2 > &  A 
)
inline

Returns the solution of the system tri(A)x=b when tri(A) is a triangular view of A.

Parameters
AMatrix. Specify upper or lower with TriView being Eigen::Upper or Eigen::Lower.
bRight hand side matrix or vector.
Returns
x = A^-1 b, solution of the linear system.
Exceptions
std::domain_errorif A is not square or the rows of b don't match the size of A.

Definition at line 1835 of file matrix.hpp.

template<typename T >
T stan::agrad::minus ( const T &  v)
inline

Return the negation of the specified variable.

The result is the same as multiplying by the scalar -1.

Parameters
[in]vSpecified variable.
Returns
The negation of the variable.

Definition at line 1111 of file matrix.hpp.

template<typename T , int R, int C>
Eigen::Matrix<T,R,C> stan::agrad::minus ( const Eigen::Matrix< T, R, C > &  v)
inline

Return the negation of the specified column vector.

The result is the same as multiplying by the scalar -1.

Parameters
[in]vSpecified vector.
Returns
The negation of the vector.

Definition at line 1121 of file matrix.hpp.

template<typename T1 , typename T2 >
boost::math::tools::promote_args<T1,T2>::type stan::agrad::multiply ( const T1 &  v,
const T2 &  c 
)
inline

Return the product of two scalars.

Parameters
[in]vFirst scalar.
[in]cSpecified scalar.
Returns
Product of scalars.

Definition at line 1266 of file matrix.hpp.

template<typename T1 , typename T2 , int R2, int C2>
Eigen::Matrix<var,R2,C2> stan::agrad::multiply ( const T1 &  c,
const Eigen::Matrix< T2, R2, C2 > &  m 
)
inline

Return the product of scalar and matrix.

Parameters
[in]cSpecified scalar.
[in]mMatrix.
Returns
Product of scalar and matrix.

Definition at line 1277 of file matrix.hpp.

template<typename T1 , int R1, int C1, typename T2 >
Eigen::Matrix<var,R1,C1> stan::agrad::multiply ( const Eigen::Matrix< T1, R1, C1 > &  m,
const T2 &  c 
)
inline

Return the product of scalar and matrix.

Parameters
[in]mMatrix.
[in]cSpecified scalar.
Returns
Product of scalar and matrix.

Definition at line 1291 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::multiply ( const Eigen::Matrix< var, R1, C1 > &  m1,
const Eigen::Matrix< var, R2, C2 > &  m2 
)
inline

Return the product of the specified matrices.

The number of columns in the first matrix must be the same as the number of rows in the second matrix.

Parameters
[in]m1First matrix.
[in]m2Second matrix.
Returns
The product of the first and second matrices.
Exceptions
std::domain_errorif the number of columns of m1 does not match the number of rows of m2.

Definition at line 1307 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::multiply ( const Eigen::Matrix< double, R1, C1 > &  m1,
const Eigen::Matrix< var, R2, C2 > &  m2 
)
inline

Return the product of the specified matrices.

The number of columns in the first matrix must be the same as the number of rows in the second matrix.

Parameters
[in]m1First matrix.
[in]m2Second matrix.
Returns
The product of the first and second matrices.
Exceptions
std::domain_errorif the number of columns of m1 does not match the number of rows of m2.

Definition at line 1351 of file matrix.hpp.

template<int R1, int C1, int R2, int C2>
Eigen::Matrix<var,R1,C2> stan::agrad::multiply ( const Eigen::Matrix< var, R1, C1 > &  m1,
const Eigen::Matrix< double, R2, C2 > &  m2 
)
inline

Return the product of the specified matrices.

The number of columns in the first matrix must be the same as the number of rows in the second matrix.

Parameters
[in]m1First matrix.
[in]m2Second matrix.
Returns
The product of the first and second matrices.
Exceptions
std::domain_errorif the number of columns of m1 does not match the number of rows of m2.

Definition at line 1396 of file matrix.hpp.

template<int C1, int R2>
var stan::agrad::multiply ( const Eigen::Matrix< var, 1, C1 > &  rv,
const Eigen::Matrix< var, R2, 1 > &  v 
)
inline

Return the scalar product of the specified row vector and specified column vector.

The return is the same as the dot product. The two vectors must be the same size.

Parameters
[in]rvRow vector.
[in]vColumn vector.
Returns
Scalar result of multiplying row vector by column vector.
Exceptions
std::domain_errorif rv and v are not the same size

Definition at line 1440 of file matrix.hpp.

template<int C1, int R2>
var stan::agrad::multiply ( const Eigen::Matrix< double, 1, C1 > &  rv,
const Eigen::Matrix< var, R2, 1 > &  v 
)
inline

Return the scalar product of the specified row vector and specified column vector.

The return is the same as the dot product. The two vectors must be the same size.

Parameters
[in]rvRow vector.
[in]vColumn vector.
Returns
Scalar result of multiplying row vector by column vector.
Exceptions
std::domain_errorif rv and v are not the same size

Definition at line 1456 of file matrix.hpp.

template<int C1, int R2>
var stan::agrad::multiply ( const Eigen::Matrix< var, 1, C1 > &  rv,
const Eigen::Matrix< double, R2, 1 > &  v 
)
inline

Return the scalar product of the specified row vector and specified column vector.

The return is the same as the dot product. The two vectors must be the same size.

Parameters
[in]rvRow vector.
[in]vColumn vector.
Returns
Scalar result of multiplying row vector by column vector.
Exceptions
std::domain_errorif rv and v are not the same size

Definition at line 1471 of file matrix.hpp.

var stan::agrad::multiply_log ( const var &  a,
const var &  b 
)
inline

Return the value of a*log(b).

When both a and b are 0, the value returned is 0. The partial deriviative with respect to a is log(b). The partial deriviative with respect to b is a/b. When a and b are both 0, this is set to Inf.

Parameters
aFirst variable.
bSecond variable.
Returns
Value of a*log(b)

Definition at line 1468 of file special_functions.hpp.

var stan::agrad::multiply_log ( const var &  a,
const double  b 
)
inline

Return the value of a*log(b).

When both a and b are 0, the value returned is 0. The partial deriviative with respect to a is log(b).

Parameters
aFirst variable.
bSecond scalar.
Returns
Value of a*log(b)

Definition at line 1481 of file special_functions.hpp.

var stan::agrad::multiply_log ( const double  a,
const var &  b 
)
inline

Return the value of a*log(b).

When both a and b are 0, the value returned is 0. The partial deriviative with respect to b is a/b. When a and b are both 0, this is set to Inf.

Parameters
aFirst scalar.
bSecond variable.
Returns
Value of a*log(b)

Definition at line 1495 of file special_functions.hpp.

matrix_v stan::agrad::multiply_lower_tri_self_transpose ( const matrix_v &  L)
inline

Definition at line 1478 of file matrix.hpp.

bool stan::agrad::operator! ( const var &  a)
inline

Prefix logical negation for the value of variables (C++).

The expression (!a) is equivalent to negating the scalar value of the variable a.

Note that this is the only logical operator defined for variables. Overridden logical conjunction (&&) and disjunction (||) operators do not apply the same "short circuit" rules as the built-in logical operators.

Parameters
aVariable to negate.
Returns
True if variable is non-zero.

Definition at line 1441 of file agrad.hpp.

bool stan::agrad::operator!= ( const var &  a,
const double &  b 
)
inline

Inequality operator comparing a variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if the first variable's value is not the same as the second value.

Definition at line 1083 of file agrad_thread_safe.hpp.

bool stan::agrad::operator!= ( const double &  a,
const var &  b 
)
inline

Inequality operator comparing a double and a variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if the first value is not the same as the second variable's value.

Definition at line 1096 of file agrad_thread_safe.hpp.

bool stan::agrad::operator!= ( const var &  a,
const var &  b 
)
inline

Inequality operator comparing two variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if the first variable's value is not the same as the second's.

Definition at line 1248 of file agrad.hpp.

bool stan::agrad::operator!= ( const var &  a,
const double  b 
)
inline

Inequality operator comparing a variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if the first variable's value is not the same as the second value.

Definition at line 1261 of file agrad.hpp.

bool stan::agrad::operator!= ( const double  a,
const var &  b 
)
inline

Inequality operator comparing a double and a variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if the first value is not the same as the second variable's value.

Definition at line 1274 of file agrad.hpp.

var stan::agrad::operator* ( const var &  a,
const double &  b 
)
inline

Multiplication operator for a variable and a scalar (C++).

The partial derivative for the variable is

$\frac{\partial}{\partial x} (x * c) = c$, and

Parameters
aVariable operand.
bScalar operand.
Returns
Variable result of multiplying operands.

Definition at line 1424 of file agrad_thread_safe.hpp.

var stan::agrad::operator* ( const double &  a,
const var &  b 
)
inline

Multiplication operator for a scalar and a variable (C++).

The partial derivative for the variable is

$\frac{\partial}{\partial y} (c * y) = c$.

Parameters
aScalar operand.
bVariable operand.
Returns
Variable result of multiplying the operands.

Definition at line 1439 of file agrad_thread_safe.hpp.

var stan::agrad::operator* ( const var &  a,
const var &  b 
)
inline

Multiplication operator for two variables (C++).

The partial derivatives are

$\frac{\partial}{\partial x} (x * y) = y$, and

$\frac{\partial}{\partial y} (x * y) = x$.

Parameters
aFirst variable operand.
bSecond variable operand.
Returns
Variable result of multiplying operands.

Definition at line 1594 of file agrad.hpp.

var stan::agrad::operator* ( const var &  a,
const double  b 
)
inline

Multiplication operator for a variable and a scalar (C++).

The partial derivative for the variable is

$\frac{\partial}{\partial x} (x * c) = c$, and

Parameters
aVariable operand.
bScalar operand.
Returns
Variable result of multiplying operands.

Definition at line 1609 of file agrad.hpp.

var stan::agrad::operator* ( const double  a,
const var &  b 
)
inline

Multiplication operator for a scalar and a variable (C++).

The partial derivative for the variable is

$\frac{\partial}{\partial y} (c * y) = c$.

Parameters
aScalar operand.
bVariable operand.
Returns
Variable result of multiplying the operands.

Definition at line 1626 of file agrad.hpp.

var stan::agrad::operator+ ( const var &  a,
const double &  b 
)
inline

Addition operator for variable and scalar (C++).

The derivative with respect to the variable is

$\frac{d}{dx} (x + c) = 1$.

Parameters
aFirst variable operand.
bSecond scalar operand.
Returns
Result of adding variable and scalar.

Definition at line 1329 of file agrad_thread_safe.hpp.

var stan::agrad::operator+ ( const double &  a,
const var &  b 
)
inline

Addition operator for scalar and variable (C++).

The derivative with respect to the variable is

$\frac{d}{dy} (c + y) = 1$.

Parameters
aFirst scalar operand.
bSecond variable operand.
Returns
Result of adding variable and scalar.

Definition at line 1344 of file agrad_thread_safe.hpp.

var stan::agrad::operator+ ( const var &  a)
inline

Unary plus operator for variables (C++).

The function simply returns its input, because

$\frac{d}{dx} +x = \frac{d}{dx} x = 1$.

The effect of unary plus on a built-in C++ scalar type is integer promotion. Because variables are all double-precision floating point already, promotion is not necessary.

Parameters
aArgument variable.
Returns
The input reference.

Definition at line 1463 of file agrad.hpp.

var stan::agrad::operator+ ( const var &  a,
const var &  b 
)
inline

Addition operator for variables (C++).

The partial derivatives are defined by

$\frac{\partial}{\partial x} (x+y) = 1$, and

$\frac{\partial}{\partial y} (x+y) = 1$.

Parameters
aFirst variable operand.
bSecond variable operand.
Returns
Variable result of adding two variables.

Definition at line 1492 of file agrad.hpp.

var stan::agrad::operator+ ( const var &  a,
const double  b 
)
inline

Addition operator for variable and scalar (C++).

The derivative with respect to the variable is

$\frac{d}{dx} (x + c) = 1$.

Parameters
aFirst variable operand.
bSecond scalar operand.
Returns
Result of adding variable and scalar.

Definition at line 1508 of file agrad.hpp.

var stan::agrad::operator+ ( const double  a,
const var &  b 
)
inline

Addition operator for scalar and variable (C++).

The derivative with respect to the variable is

$\frac{d}{dy} (c + y) = 1$.

Parameters
aFirst scalar operand.
bSecond variable operand.
Returns
Result of adding variable and scalar.

Definition at line 1525 of file agrad.hpp.

var & stan::agrad::operator++ ( var &  a)
inline

Prefix increment operator for variables (C++).

Following C++, (++a) is defined to behave exactly as (a = a + 1.0) does, but is faster and uses less memory. In particular, the result is an assignable lvalue.

Parameters
aVariable to increment.
Returns
Reference the result of incrementing this input variable.

Definition at line 1691 of file agrad.hpp.

var stan::agrad::operator++ ( var &  a,
int  dummy 
)
inline

Postfix increment operator for variables (C++).

Following C++, the expression (a++) is defined to behave like the sequence of operations

var temp = a; a = a + 1.0; return temp;

Parameters
aVariable to increment.
dummyUnused dummy variable used to distinguish postfix operator from prefix operator.
Returns
Input variable.

Following C++, the expression (a++) i s defined to behave like the sequence of operations

var temp = a; a = a + 1.0; return temp;

Parameters
aVariable to increment.
dummyUnused dummy variable used to distinguish postfix operator from prefix operator.
Returns
Input variable.

Definition at line 1709 of file agrad.hpp.

var stan::agrad::operator- ( const var &  a,
const double &  b 
)
inline

Subtraction operator for variable and scalar (C++).

The derivative for the variable is

$\frac{\partial}{\partial x} (x-c) = 1$, and

Parameters
aFirst variable operand.
bSecond scalar operand.
Returns
Result of subtracting the scalar from the variable.

Definition at line 1377 of file agrad_thread_safe.hpp.

var stan::agrad::operator- ( const double &  a,
const var &  b 
)
inline

Subtraction operator for scalar and variable (C++).

The derivative for the variable is

$\frac{\partial}{\partial y} (c-y) = -1$, and

Parameters
aFirst scalar operand.
bSecond variable operand.
Returns
Result of sutracting a variable from a scalar.

Definition at line 1392 of file agrad_thread_safe.hpp.

var stan::agrad::operator- ( const var &  a)
inline

Unary negation operator for variables (C++).

$\frac{d}{dx} -x = -1$.

Parameters
aArgument variable.
Returns
Negation of variable.

Definition at line 1475 of file agrad.hpp.

var stan::agrad::operator- ( const var &  a,
const var &  b 
)
inline

Subtraction operator for variables (C++).

The partial derivatives are defined by

$\frac{\partial}{\partial x} (x-y) = 1$, and

$\frac{\partial}{\partial y} (x-y) = -1$.

Parameters
aFirst variable operand.
bSecond variable operand.
Returns
Variable result of subtracting the second variable from the first.

Definition at line 1545 of file agrad.hpp.

var stan::agrad::operator- ( const var &  a,
const double  b 
)
inline

Subtraction operator for variable and scalar (C++).

The derivative for the variable is

$\frac{\partial}{\partial x} (x-c) = 1$, and

Parameters
aFirst variable operand.
bSecond scalar operand.
Returns
Result of subtracting the scalar from the variable.

Definition at line 1560 of file agrad.hpp.

var stan::agrad::operator- ( const double  a,
const var &  b 
)
inline

Subtraction operator for scalar and variable (C++).

The derivative for the variable is

$\frac{\partial}{\partial y} (c-y) = -1$, and

Parameters
aFirst scalar operand.
bSecond variable operand.
Returns
Result of sutracting a variable from a scalar.

Definition at line 1577 of file agrad.hpp.

var & stan::agrad::operator-- ( var &  a)
inline

Prefix decrement operator for variables (C++).

Following C++, (–a) is defined to behave exactly as

a = a - 1.0)

does, but is faster and uses less memory. In particular, the result is an assignable lvalue.

Parameters
aVariable to decrement.
Returns
Reference the result of decrementing this input variable.

Definition at line 1728 of file agrad.hpp.

var stan::agrad::operator-- ( var &  a,
int  dummy 
)
inline

Postfix decrement operator for variables (C++).

Following C++, the expression (a–) is defined to behave like the sequence of operations

var temp = a; a = a - 1.0; return temp;

Parameters
aVariable to decrement.
dummyUnused dummy variable used to distinguish suffix operator from prefix operator.
Returns
Input variable.

Definition at line 1746 of file agrad.hpp.

var stan::agrad::operator/ ( const var &  a,
const double &  b 
)
inline

Division operator for dividing a variable by a scalar (C++).

The derivative with respect to the variable is

$\frac{\partial}{\partial x} (x/c) = 1/c$.

Parameters
aVariable operand.
bScalar operand.
Returns
Variable result of dividing the variable by the scalar.

Definition at line 1472 of file agrad_thread_safe.hpp.

var stan::agrad::operator/ ( const double &  a,
const var &  b 
)
inline

Division operator for dividing a scalar by a variable (C++).

The derivative with respect to the variable is

$\frac{d}{d y} (c/y) = -c / y^2$.

Parameters
aScalar operand.
bVariable operand.
Returns
Variable result of dividing the scalar by the variable.

Definition at line 1487 of file agrad_thread_safe.hpp.

var stan::agrad::operator/ ( const var &  a,
const var &  b 
)
inline

Division operator for two variables (C++).

The partial derivatives for the variables are

$\frac{\partial}{\partial x} (x/y) = 1/y$, and

$\frac{\partial}{\partial y} (x/y) = -x / y^2$.

Parameters
aFirst variable operand.
bSecond variable operand.
Returns
Variable result of dividing the first variable by the second.

Definition at line 1646 of file agrad.hpp.

var stan::agrad::operator/ ( const var &  a,
const double  b 
)
inline

Division operator for dividing a variable by a scalar (C++).

The derivative with respect to the variable is

$\frac{\partial}{\partial x} (x/c) = 1/c$.

Parameters
aVariable operand.
bScalar operand.
Returns
Variable result of dividing the variable by the scalar.

Definition at line 1661 of file agrad.hpp.

var stan::agrad::operator/ ( const double  a,
const var &  b 
)
inline

Division operator for dividing a scalar by a variable (C++).

The derivative with respect to the variable is

$\frac{d}{d y} (c/y) = -c / y^2$.

Parameters
aScalar operand.
bVariable operand.
Returns
Variable result of dividing the scalar by the variable.

Definition at line 1678 of file agrad.hpp.

bool stan::agrad::operator< ( const var &  a,
const double &  b 
)
inline

Less than operator comparing variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is less than second value.

Definition at line 1119 of file agrad_thread_safe.hpp.

bool stan::agrad::operator< ( const double &  a,
const var &  b 
)
inline

Less than operator comparing a double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is less than second variable's value.

Definition at line 1131 of file agrad_thread_safe.hpp.

bool stan::agrad::operator< ( const var &  a,
const var &  b 
)
inline

Less than operator comparing variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if first variable's value is less than second's.

Definition at line 1285 of file agrad.hpp.

bool stan::agrad::operator< ( const var &  a,
const double  b 
)
inline

Less than operator comparing variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is less than second value.

Definition at line 1297 of file agrad.hpp.

bool stan::agrad::operator< ( const double  a,
const var &  b 
)
inline

Less than operator comparing a double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is less than second variable's value.

Definition at line 1309 of file agrad.hpp.

bool stan::agrad::operator<= ( const var &  a,
const double &  b 
)
inline

Less than or equal operator comparing a variable's value and a scalar (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is less than or equal to the second value.

Definition at line 1192 of file agrad_thread_safe.hpp.

bool stan::agrad::operator<= ( const double &  a,
const var &  b 
)
inline

Less than or equal operator comparing a double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is less than or equal to the second variable's value.

Definition at line 1205 of file agrad_thread_safe.hpp.

bool stan::agrad::operator<= ( const var &  a,
const var &  b 
)
inline

Less than or equal operator comparing two variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if first variable's value is less than or equal to the second's.

Definition at line 1357 of file agrad.hpp.

bool stan::agrad::operator<= ( const var &  a,
const double  b 
)
inline

Less than or equal operator comparing a variable's value and a scalar (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is less than or equal to the second value.

Definition at line 1370 of file agrad.hpp.

bool stan::agrad::operator<= ( const double  a,
const var &  b 
)
inline

Less than or equal operator comparing a double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is less than or equal to the second variable's value.

Definition at line 1383 of file agrad.hpp.

bool stan::agrad::operator== ( const var &  a,
const double &  b 
)
inline

Equality operator comparing a variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if the first variable's value is the same as the second value.

Definition at line 1046 of file agrad_thread_safe.hpp.

bool stan::agrad::operator== ( const double &  a,
const var &  b 
)
inline

Equality operator comparing a scalar and a variable's value (C++).

Parameters
aFirst scalar.
bSecond variable.
Returns
True if the variable's value is equal to the scalar.

Definition at line 1058 of file agrad_thread_safe.hpp.

bool stan::agrad::operator== ( const var &  a,
const var &  b 
)
inline

Equality operator comparing two variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if the first variable's value is the same as the second's.

Definition at line 1211 of file agrad.hpp.

bool stan::agrad::operator== ( const var &  a,
const double  b 
)
inline

Equality operator comparing a variable's value and a double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if the first variable's value is the same as the second value.

Definition at line 1224 of file agrad.hpp.

bool stan::agrad::operator== ( const double  a,
const var &  b 
)
inline

Equality operator comparing a scalar and a variable's value (C++).

Parameters
aFirst scalar.
bSecond variable.
Returns
True if the variable's value is equal to the scalar.

Definition at line 1236 of file agrad.hpp.

bool stan::agrad::operator> ( const var &  a,
const double &  b 
)
inline

Greater than operator comparing variable's value and double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is greater than second value.

Definition at line 1154 of file agrad_thread_safe.hpp.

bool stan::agrad::operator> ( const double &  a,
const var &  b 
)
inline

Greater than operator comparing a double and a variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is greater than second variable's value.

Definition at line 1166 of file agrad_thread_safe.hpp.

bool stan::agrad::operator> ( const var &  a,
const var &  b 
)
inline

Greater than operator comparing variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if first variable's value is greater than second's.

Definition at line 1320 of file agrad.hpp.

bool stan::agrad::operator> ( const var &  a,
const double  b 
)
inline

Greater than operator comparing variable's value and double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is greater than second value.

Definition at line 1332 of file agrad.hpp.

bool stan::agrad::operator> ( const double  a,
const var &  b 
)
inline

Greater than operator comparing a double and a variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if first value is greater than second variable's value.

Definition at line 1344 of file agrad.hpp.

bool stan::agrad::operator>= ( const var &  a,
const double &  b 
)
inline

Greater than or equal operator comparing variable's value and double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is greater than or equal to second value.

Definition at line 1231 of file agrad_thread_safe.hpp.

bool stan::agrad::operator>= ( const double &  a,
const var &  b 
)
inline

Greater than or equal operator comparing double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if the first value is greater than or equal to the second variable's value.

Definition at line 1244 of file agrad_thread_safe.hpp.

bool stan::agrad::operator>= ( const var &  a,
const var &  b 
)
inline

Greater than or equal operator comparing two variables' values (C++).

Parameters
aFirst variable.
bSecond variable.
Returns
True if first variable's value is greater than or equal to the second's.

Definition at line 1396 of file agrad.hpp.

bool stan::agrad::operator>= ( const var &  a,
const double  b 
)
inline

Greater than or equal operator comparing variable's value and double (C++).

Parameters
aFirst variable.
bSecond value.
Returns
True if first variable's value is greater than or equal to second value.

Definition at line 1409 of file agrad.hpp.

bool stan::agrad::operator>= ( const double  a,
const var &  b 
)
inline

Greater than or equal operator comparing double and variable's value (C++).

Parameters
aFirst value.
bSecond variable.
Returns
True if the first value is greater than or equal to the second variable's value.

Definition at line 1422 of file agrad.hpp.

var stan::agrad::Phi ( const stan::agrad::var &  a)
inline

The unit normal cumulative density function for variables (stan).

See stan::math::Phi() for the double-based version.

The derivative is the unit normal density function,

$\frac{d}{dx} \Phi(x) = \mbox{\sf Norm}(x|0,1) = \frac{1}{\sqrt{2\pi}} \exp(-\frac{1}{2} x^2)$.

Parameters
aVariable argument.
Returns
The unit normal cdf evaluated at the specified argument.

Definition at line 1364 of file special_functions.hpp.

var stan::agrad::pow ( const var &  base,
const double &  exponent 
)
inline

Return the base variable raised to the power of the exponent scalar (cmath).

The derivative for the variable is

$\frac{d}{dx} \mbox{pow}(x,c) = c x^{c-1}$.

Parameters
baseBase variable.
exponentExponent scalar.
Returns
Base raised to the exponent.

Definition at line 1647 of file agrad_thread_safe.hpp.

var stan::agrad::pow ( const double &  base,
const var &  exponent 
)
inline

Return the base scalar raised to the power of the exponent variable (cmath).

The derivative for the variable is

$\frac{d}{d y} \mbox{pow}(c,y) = c^y \log c $.

Parameters
baseBase scalar.
exponentExponent variable.
Returns
Base raised to the exponent.

Definition at line 1663 of file agrad_thread_safe.hpp.

var stan::agrad::pow ( const var &  base,
const var &  exponent 
)
inline

Return the base raised to the power of the exponent (cmath).

The partial derivatives are

$\frac{\partial}{\partial x} \mbox{pow}(x,y) = y x^{y-1}$, and

$\frac{\partial}{\partial y} \mbox{pow}(x,y) = x^y \ \log x$.

Parameters
baseBase variable.
exponentExponent variable.
Returns
Base raised to the exponent.

Definition at line 1822 of file agrad.hpp.

var stan::agrad::pow ( const var &  base,
const double  exponent 
)
inline

Return the base variable raised to the power of the exponent scalar (cmath).

The derivative for the variable is

$\frac{d}{dx} \mbox{pow}(x,c) = c x^{c-1}$.

Parameters
baseBase variable.
exponentExponent scalar.
Returns
Base raised to the exponent.

Definition at line 1838 of file agrad.hpp.

var stan::agrad::pow ( const double  base,
const var &  exponent 
)
inline

Return the base scalar raised to the power of the exponent variable (cmath).

The derivative for the variable is

$\frac{d}{d y} \mbox{pow}(c,y) = c^y \log c $.

Parameters
baseBase scalar.
exponentExponent variable.
Returns
Base raised to the exponent.

Definition at line 1860 of file agrad.hpp.

void stan::agrad::print_stack ( std::ostream &  o)
inline

Prints the auto-dif variable stack.

This function is used for debugging purposes.

Parameters
oostream to modify

Definition at line 208 of file agrad.hpp.

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

Recover memory used for all variables for reuse.

Definition at line 2207 of file agrad.hpp.

var stan::agrad::round ( const stan::agrad::var &  a)
inline

Returns the rounded form of the specified variable (C99).

See boost::math::round() for the double-based version.

The derivative is zero everywhere but numbers half way between whole numbers, so for convenience the derivative is defined to be everywhere zero,

$\frac{d}{dx} \mbox{round}(x) = 0$.

Parameters
aSpecified variable.
Returns
Rounded variable.

Definition at line 1194 of file special_functions.hpp.

row_vector_v stan::agrad::row ( const matrix_v &  m,
size_t  i 
)

Return the specified row minus 1 of the specified matrix.

That is, indexing is from 1, not 0, so this function returns the same value as the Eigen matrix call m.row(i - 1).

Parameters
[in]mMatrix.
[in]iRow index (plus 1).
Returns
Specified row of the matrix; between 1 and the number of rows of m inclusive.
Exceptions
std::domain_errorIf the index is 0 or greater than the number of columns.

Definition at line 16 of file matrix.cpp.

size_t stan::agrad::rows ( const vector_v &  v)
inline

Return number of rows.

Returns the number of rows in the specified column vector.

Parameters
vSpecified vector.
Returns
Number of rows in the vector.

Definition at line 509 of file matrix.hpp.

size_t stan::agrad::rows ( const row_vector_v &  rv)
inline

Return number of rows.

Returns the number of rows in the specified row vector. The return value is always 1.

Parameters
rvSpecified vector.
Returns
Number of rows in the vector.

Definition at line 521 of file matrix.hpp.

size_t stan::agrad::rows ( const matrix_v &  m)
inline

Return number of rows.

Returns the number of rows in the specified matrix.

Parameters
mSpecified matrix.
Returns
Number of rows in the vector.

Definition at line 532 of file matrix.hpp.

static void stan::agrad::set_zero_all_adjoints ( )
static

Reset all adjoint values in the stack to zero.

Definition at line 2251 of file agrad.hpp.

var stan::agrad::sin ( const var &  a)
inline

Return the sine of a radian-scaled variable (cmath).

The derivative is defined by

$\frac{d}{dx} \sin x = \cos x$.

Parameters
aVariable for radians of angle.
Returns
Sine of variable.

Definition at line 1891 of file agrad.hpp.

vector_v stan::agrad::singular_values ( const matrix_v &  m)

Return the vector of the singular values of the specified matrix in decreasing order of magnitude.

See the documentation for svd() for information on the signular values.

Parameters
[in]mSpecified matrix.
Returns
Singular values of the matrix.

Definition at line 110 of file matrix.cpp.

var stan::agrad::sinh ( const var &  a)
inline

Return the hyperbolic sine of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \sinh x = \cosh x$.

Parameters
aVariable.
Returns
Hyperbolic sine of variable.

Definition at line 2030 of file agrad.hpp.

vector_v stan::agrad::softmax ( const vector_v &  v)

Return the softmax of the specified vector.

Parameters
vVector to transform
Returns
Unit simplex result of the softmax transform of the vector.

Definition at line 51 of file matrix.cpp.

var stan::agrad::sqrt ( const var &  a)
inline

Return the square root of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \sqrt{x} = \frac{1}{2 \sqrt{x}}$.

Parameters
aVariable whose square root is taken.
Returns
Square root of variable.

Definition at line 1805 of file agrad.hpp.

var stan::agrad::square ( const var &  x)
inline

Return the square of the input variable.

Using square(x) is more efficient than using x * x.

Parameters
xVariable to square.
Returns
Square of variable.

Definition at line 1451 of file special_functions.hpp.

size_t stan::agrad::stack_size ( )
inline

Returns the current size of the stack of vari instances.

Returns
Size of vari stack.

Definition at line 197 of file agrad.hpp.

void stan::agrad::stan_print ( std::ostream *  o,
const var &  x 
)

Definition at line 127 of file matrix.cpp.

var stan::agrad::step ( const stan::agrad::var &  a)
inline

Return the step, or heaviside, function applied to the specified variable (stan).

See stan::math::step() for the double-based version.

The derivative of the step function is zero everywhere but at 0, so for convenience, it is taken to be everywhere zero,

$\mbox{step}(x) = 0$.

Parameters
aVariable argument.
Returns
The constant variable with value 1.0 if the argument's value is greater than or equal to 0.0, and value 0.0 otherwise.

Definition at line 1330 of file special_functions.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::subtract ( const Eigen::Matrix< T1, R, C > &  v1,
const Eigen::Matrix< T2, R, C > &  v2 
)
inline

Return the difference between the first specified column vector and the second.

The two vectors must have the same size.

Parameters
[in]v1First vector.
[in]v2Second vector.
Returns
First vector minus the second vector.
Exceptions
std::domain_errorif size of v1 does not match size of v2.

Definition at line 1074 of file matrix.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::subtract ( const Eigen::Matrix< T1, R, C > &  m,
const T2 &  c 
)
inline

Return the difference between a matrix or vector and a scalar.

Parameters
[in]mMatrix or vector.
[in]cScalar.
Returns
Vector minus the scalar.

Definition at line 1087 of file matrix.hpp.

template<typename T1 , typename T2 , int R, int C>
Eigen::Matrix<typename boost::math::tools::promote_args<T1,T2>::type, R, C> stan::agrad::subtract ( const T1 &  c,
const Eigen::Matrix< T2, R, C > &  m 
)
inline

Return the difference between a scalar and a matrix or vector.

Parameters
[in]cScalar.
[in]mMatrix or vector.
Returns
Scalar minus vector.

Definition at line 1099 of file matrix.hpp.

template<int R, int C>
var stan::agrad::sum ( const Eigen::Matrix< var, R, C > &  m)
inline

Returns the sum of the coefficients of the specified matrix, column vector or row vector.

Parameters
mSpecified matrix or vector.
Returns
Sum of coefficients of matrix.

Definition at line 1014 of file matrix.hpp.

void stan::agrad::svd ( const matrix_v &  m,
matrix_v &  u,
matrix_v &  v,
vector_v &  s 
)

Assign the real components of a singular value decomposition of the specified matrix to the specified references.

Thesingular values $S$ are assigned to a vector in decreasing order of magnitude. The left singular vectors are found in the columns of $U$ and the right singular vectors in the columns of $V$.

The original matrix is recoverable as

$A = U \times \mbox{\rm diag}(S) \times V^T$, where $\mbox{\rm diag}(S)$ is the square diagonal matrix with diagonal elements $S$.

If $A$ is an $M \times N$ matrix and $K = \mbox{\rm min}(M,N)$, then $U$ is an $M \times K$ matrix, $S$ is a length $K$ column vector, and $V$ is an $N \times K$ matrix.

Parameters
[in]mMatrix to decompose.
[out]uLeft singular vectors.
[out]vRight singular vectors.
[out]sSingular values.

Definition at line 115 of file matrix.cpp.

var stan::agrad::tan ( const var &  a)
inline

Return the tangent of a radian-scaled variable (cmath).

The derivative is defined by

$\frac{d}{dx} \tan x = \sec^2 x$.

Parameters
aVariable for radians of angle.
Returns
Tangent of variable.

Definition at line 1905 of file agrad.hpp.

var stan::agrad::tanh ( const var &  a)
inline

Return the hyperbolic tangent of the specified variable (cmath).

The derivative is defined by

$\frac{d}{dx} \tanh x = \frac{1}{\cosh^2 x}$.

Parameters
aVariable.
Returns
Hyperbolic tangent of variable.

Definition at line 2044 of file agrad.hpp.

matrix_v stan::agrad::tcrossprod ( const matrix_v &  M)
inline

Returns the result of post-multiplying a matrix by its own transpose.

Parameters
MMatrix to multiply.
Returns
M times its transpose.

Definition at line 1510 of file matrix.hpp.

var stan::agrad::tgamma ( const stan::agrad::var &  a)
inline

Return the Gamma function applied to the specified variable (C99).

See boost::math::tgamma() for the double-based version.

The derivative with respect to the argument is

$\frac{d}{dx} \Gamma(x) = \Gamma(x) \Psi^{(0)}(x)$

where $\Psi^{(0)}(x)$ is the digamma function.

See boost::math::digamma() for the double-based version.

Parameters
aArgument to function.
Returns
The Gamma function applied to the specified argument.

Definition at line 1310 of file special_functions.hpp.

var stan::agrad::to_var ( const double &  x)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]xA scalar value
Returns
An automatic differentiation variable with the input value.

Definition at line 296 of file matrix.hpp.

void stan::agrad::to_var ( const double &  x,
var &  var_x 
)
inline

Converts argument to an automatic differentiation variable.

Sets an automatic differentiation variable with the input value.

Parameters
[in]xA scalar value
[out]var_xA reference to an automatic differentiation variable which will have the value of x.

Definition at line 308 of file matrix.hpp.

var stan::agrad::to_var ( const var &  x)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]xAn automatic differentiation variable.
Returns
An automatic differentiation variable with the input value.

Definition at line 319 of file matrix.hpp.

void stan::agrad::to_var ( const var &  var_in,
var &  var_out 
)
inline

Converts argument to an automatic differentiation variable.

Sets an automatic differentiation variable with the input value.

Parameters
[in]var_inAn automatic differentiation variable.
[out]var_outA reference to an automatic differentiation variable which will be set to the input value.

Definition at line 331 of file matrix.hpp.

matrix_v stan::agrad::to_var ( const stan::math::matrix_d &  m)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]mA Matrix with scalars
Returns
A Matrix with automatic differentiation variables

Definition at line 342 of file matrix.hpp.

void stan::agrad::to_var ( const stan::math::matrix_d &  m,
matrix_v &  m_v 
)
inline

Converts argument to an automatic differentiation variable.

Sets a Matrix with automatic differentiation variables.

Parameters
[in]mA Matrix of scalars.
[out]m_vA Matrix with automatic differentiation variables assigned with values of m.

Definition at line 359 of file matrix.hpp.

matrix_v stan::agrad::to_var ( const matrix_v &  m)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]mA Matrix with automatic differentiation variables.
Returns
A Matrix with automatic differentiation variables.

Definition at line 373 of file matrix.hpp.

void stan::agrad::to_var ( const matrix_v &  m_in,
matrix_v &  m_out 
)
inline

Converts argument to an automatic differentiation variable.

Sets a Matrix with automatic differentiation variables.

Parameters
[in]m_inA Matrix of automatic differentiation variables.
[out]m_outA Matrix of automatic differentiation variables assigned with values of m_in.

Definition at line 385 of file matrix.hpp.

vector_v stan::agrad::to_var ( const stan::math::vector_d &  v)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]vA Vector of scalars
Returns
A Vector of automatic differentiation variables with values of v

Definition at line 398 of file matrix.hpp.

void stan::agrad::to_var ( const stan::math::vector_d &  v,
vector_v &  v_v 
)
inline

Converts argument to an automatic differentiation variable.

Sets a Vector with automatic differentation variables.

Parameters
[in]vA Vector of scalars.
[out]v_vA Vector of automatic differentation variables with values of v.

Definition at line 413 of file matrix.hpp.

vector_v stan::agrad::to_var ( const vector_v &  v)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]vA Vector of automatic differentiation variables
Returns
A Vector of automatic differentiation variables with values of v

Definition at line 428 of file matrix.hpp.

void stan::agrad::to_var ( const vector_v &  v_in,
vector_v &  v_out 
)
inline

Converts argument to an automatic differentiation variable.

Sets a Vector with automatic differentiation variables

Parameters
[in]v_inA Vector of automatic differentiation variables
[out]v_outA Vector of automatic differentiation variables with values of v_in

Definition at line 440 of file matrix.hpp.

row_vector_v stan::agrad::to_var ( const stan::math::row_vector_d &  rv)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]rvA row vector of scalars
Returns
A row vector of automatic differentation variables with values of rv.

Definition at line 453 of file matrix.hpp.

void stan::agrad::to_var ( const stan::math::row_vector_d &  rv,
row_vector_v &  rv_v 
)
inline

Converts argument to an automatic differentiation variable.

Sets a row vector with automatic differentiation variables

Parameters
[in]rvA row vector of scalars
[out]rv_vA row vector of automatic differentiation variables with values set to rv.

Definition at line 468 of file matrix.hpp.

row_vector_v stan::agrad::to_var ( const row_vector_v &  rv)
inline

Converts argument to an automatic differentiation variable.

Returns a stan::agrad::var variable with the input value.

Parameters
[in]rvA row vector with automatic differentiation variables
Returns
A row vector with automatic differentiation variables with values of rv.

Definition at line 483 of file matrix.hpp.

void stan::agrad::to_var ( const row_vector_v &  rv_in,
row_vector_v &  rv_out 
)
inline

Converts argument to an automatic differentiation variable.

Sets a row vector with automatic differentiation variables

Parameters
[in]rv_inA row vector with automatic differentiation variables
[out]rv_outA row vector with automatic differentiation variables with values of rv_in

Definition at line 495 of file matrix.hpp.

row_vector_v stan::agrad::transpose ( const vector_v &  v)

Return the transposition of the specified column vector.

Parameters
[in]vSpecified vector.
Returns
Transpose of the vector.

Definition at line 34 of file matrix.cpp.

vector_v stan::agrad::transpose ( const row_vector_v &  rv)

Return the transposition of the specified row vector.

Parameters
[in]rvSpecified vector.
Returns
Transpose of the vector.

Definition at line 38 of file matrix.cpp.

matrix_v stan::agrad::transpose ( const matrix_v &  m)

Return the transposition of the specified matrix.

Parameters
[in]mSpecified matrix.
Returns
Transpose of the matrix.

Definition at line 42 of file matrix.cpp.

var stan::agrad::trunc ( const stan::agrad::var &  a)
inline

Returns the truncatation of the specified variable (C99).

See boost::math::trunc() for the double-based version.

The derivative is zero everywhere but at integer values, so for convenience the derivative is defined to be everywhere zero,

$\frac{d}{dx} \mbox{trunc}(x) = 0$.

Parameters
aSpecified variable.
Returns
Truncation of the variable.

Definition at line 1211 of file special_functions.hpp.

double stan::agrad::value_of ( const agrad::var &  v)
inline

Return the value of the specified variable.

This function is used internally by auto-dif functions along with stan::math::value_of(T x) to extract the double value of either a scalar or an auto-dif variable. This function will be called when the argument is a stan::agrad::var even if the function is not referred to by namespace because of argument-dependent lookup.

Parameters
vVariable.
Returns
Value of variable.

Definition at line 1580 of file special_functions.hpp.

Variable Documentation

memory::stack_alloc stan::agrad::memalloc_

Definition at line 11 of file agrad.cpp.

std::vector< chainable * > stan::agrad::var_stack_

Definition at line 10 of file agrad.cpp.


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