![]() |
Stan
2.10.0
probability, sampling & optimization
|
For compiling models. More...
Classes | |
struct | cons_index_list |
Template structure for an index list consisting of a head and tail index. More... | |
struct | index_max |
Structure for an indexing from the start of a container to a specified maximum index (inclusive). More... | |
struct | index_min |
Structure for an indexing from a minimum index (inclusive) to the end of a container. More... | |
struct | index_min_max |
Structure for an indexing from a minimum index (inclusive) to a maximum index (inclusive). More... | |
struct | index_multi |
Structure for an indexing consisting of multiple indexes. More... | |
struct | index_omni |
Structure for an indexing that consists of all indexes for a container. More... | |
struct | index_uni |
Structure for an indexing consisting of a single index. More... | |
struct | model_functional |
struct | nil_index_list |
Structure for an empty (size zero) index list. More... | |
class | prob_grad |
The prob_grad class represents the basic parameter holders for a model. More... | |
struct | rvalue_return |
Primary template class for metaprogram to calculate return value for model::rvalue() for the container or scalar type and index list type specified in the template parameters. More... | |
struct | rvalue_return< C, nil_index_list > |
Template class specialization for nil indexes, which provide the container type as the return type. More... | |
struct | rvalue_return< Eigen::Matrix< T, 1, Eigen::Dynamic >, cons_index_list< index_uni, nil_index_list > > |
Template class specialization for an Eigen row vector and one single index. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, 1 >, cons_index_list< index_uni, nil_index_list > > |
Template class specialization for an Eigen vector and one single index. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< I, cons_index_list< index_uni, nil_index_list > > > |
Template specialization for an Eigen matrix with one multiple index followed by one single index. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< I1, cons_index_list< I2, nil_index_list > > > |
Template specialization for an Eigen matrix and two multiple indexes. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, cons_index_list< I, nil_index_list > > > |
Template specialization for an Eigen matrix with one single index followed by one multiple index. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, cons_index_list< index_uni, nil_index_list > > > |
Template specialization for an Eigen matrix with two single indexes. More... | |
struct | rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, nil_index_list > > |
Template class specialization for an Eigen matrix and one single index. More... | |
struct | rvalue_return< Eigen::Matrix< T, R, C >, cons_index_list< I, nil_index_list > > |
Template class specialization for an Eigen matrix, vector or rwo vector and one multiple index. More... | |
struct | rvalue_return< std::vector< C >, cons_index_list< I, L > > |
Template specialization for a standard vector whose index list starts with a multiple index. More... | |
struct | rvalue_return< std::vector< C >, cons_index_list< index_uni, L > > |
Template specialization for a standard vector whose index list starts with a single index. More... | |
Functions | |
template<typename T > | |
const T & | deep_copy (const T &x) |
Return the specified argument as a constant reference. More... | |
template<typename T , int R, int C> | |
Eigen::Matrix< T, R, C > | deep_copy (const Eigen::Matrix< T, R, C > &a) |
Return a copy of the specified matrix, vector, or row vector. More... | |
template<typename T > | |
std::vector< T > | deep_copy (const std::vector< T > &v) |
Return a deep copy of the specified standard vector. More... | |
template<typename I , typename T > | |
cons_index_list< I, T > | cons_list (const I &idx1, const T &t) |
nil_index_list | index_list () |
template<typename I > | |
cons_index_list< I, nil_index_list > | index_list (const I &idx) |
template<typename I1 , typename I2 > | |
cons_index_list< I1, cons_index_list< I2, nil_index_list > > | index_list (const I1 &idx1, const I2 &idx2) |
template<typename I1 , typename I2 , typename I3 > | |
cons_index_list< I1, cons_index_list< I2, cons_index_list< I3, nil_index_list > > > | index_list (const I1 &idx1, const I2 &idx2, const I3 &idx3) |
template<typename T , typename U > | |
void | assign (T &x, const nil_index_list &, const U &y, const char *name="ANON", int depth=0) |
Assign the specified scalar reference under the specified indexing to the specified scalar value. More... | |
template<typename T , typename U , int R, int C> | |
void | assign (Eigen::Matrix< T, R, C > &x, const nil_index_list &, const Eigen::Matrix< U, R, C > &y, const char *name="ANON", int depth=0) |
template<typename T , typename U > | |
void | assign (std::vector< T > &x, const nil_index_list &, const std::vector< U > &y, const char *name="ANON", int depth=0) |
template<typename T , typename U > | |
void | assign (Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, const cons_index_list< index_uni, nil_index_list > &idxs, const U &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen vector at the specified single index to the specified value. More... | |
template<typename T , typename U > | |
void | assign (Eigen::Matrix< T, 1, Eigen::Dynamic > &x, const cons_index_list< index_uni, nil_index_list > &idxs, const U &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen vector at the specified single index to the specified value. More... | |
template<typename T , typename I , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, const cons_index_list< I, nil_index_list > &idxs, const Eigen::Matrix< U, Eigen::Dynamic, 1 > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen vector at the specified multiple index to the specified value. More... | |
template<typename T , typename I , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (Eigen::Matrix< T, 1, Eigen::Dynamic > &x, const cons_index_list< I, nil_index_list > &idxs, const Eigen::Matrix< U, 1, Eigen::Dynamic > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen row vector at the specified multiple index to the specified value. More... | |
template<typename T , typename U > | |
void | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< index_uni, nil_index_list > &idxs, const Eigen::Matrix< U, 1, Eigen::Dynamic > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified single index to the specified row vector value. More... | |
template<typename T , typename I , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< I, nil_index_list > &idxs, const Eigen::Matrix< U, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified multiple index to the specified matrix value. More... | |
template<typename T , typename U > | |
void | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< index_uni, cons_index_list< index_uni, nil_index_list > > &idxs, const U &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified pair of single indexes to the specified scalar value. More... | |
template<typename T , typename I , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< index_uni, cons_index_list< I, nil_index_list > > &idxs, const Eigen::Matrix< U, 1, Eigen::Dynamic > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified single and multiple index to the specified row vector. More... | |
template<typename T , typename I , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< I, cons_index_list< index_uni, nil_index_list > > &idxs, const Eigen::Matrix< U, Eigen::Dynamic, 1 > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified multiple and single index to the specified vector. More... | |
template<typename T , typename I1 , typename I2 , typename U > | |
boost::disable_if_c< boost::is_same< I1, index_uni >::value||boost::is_same< I2, index_uni >::value, void >::type | assign (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x, const cons_index_list< I1, cons_index_list< I2, nil_index_list > > &idxs, const Eigen::Matrix< U, Eigen::Dynamic, Eigen::Dynamic > &y, const char *name="ANON", int depth=0) |
Assign the specified Eigen matrix at the specified pair of multiple indexes to the specified matrix. More... | |
template<typename T , typename L , typename U > | |
void | assign (std::vector< T > &x, const cons_index_list< index_uni, L > &idxs, const U &y, const char *name="ANON", int depth=0) |
Assign the specified array (standard vector) at the specified index list beginning with a single index to the specified value. More... | |
template<typename T , typename I , typename L , typename U > | |
boost::disable_if< boost::is_same< I, index_uni >, void >::type | assign (std::vector< T > &x, const cons_index_list< I, L > &idxs, const std::vector< U > &y, const char *name="ANON", int depth=0) |
Assign the specified array (standard vector) at the specified index list beginning with a multiple index to the specified value. More... | |
template<typename T > | |
T | rvalue (const T &c, const nil_index_list &, const char *="", int=0) |
Return the result of indexing a specified value with a nil index list, which just returns the value. More... | |
template<typename T > | |
T | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, const cons_index_list< index_uni, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen vector with a sequence containing one single index, returning a scalar. More... | |
template<typename T > | |
T | rvalue (const Eigen::Matrix< T, 1, Eigen::Dynamic > &rv, const cons_index_list< index_uni, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen row vector with a sequence containing one single index, returning a scalar. More... | |
template<typename T , typename I > | |
boost::disable_if< boost::is_same< I, index_uni >, Eigen::Matrix< T, Eigen::Dynamic, 1 > >::type | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &v, const cons_index_list< I, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen vector with a sequence containing one multiple index, returning a vector. More... | |
template<typename T , typename I > | |
boost::disable_if< boost::is_same< I, index_uni >, Eigen::Matrix< T, 1, Eigen::Dynamic > >::type | rvalue (const Eigen::Matrix< T, 1, Eigen::Dynamic > &rv, const cons_index_list< I, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen row vector with a sequence containing one multiple index, returning a row vector. More... | |
template<typename T > | |
Eigen::Matrix< T, 1, Eigen::Dynamic > | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< index_uni, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of one single index, returning a row vector. More... | |
template<typename T , typename I > | |
boost::disable_if< boost::is_same< I, index_uni >, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > >::type | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< I, nil_index_list > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a one multiple index, returning a matrix. More... | |
template<typename T > | |
T | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< index_uni, cons_index_list< index_uni, nil_index_list > > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of two single indexes, returning a scalar. More... | |
template<typename T , typename I > | |
boost::disable_if< boost::is_same< I, index_uni >, Eigen::Matrix< T, 1, Eigen::Dynamic > >::type | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< index_uni, cons_index_list< I, nil_index_list > > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a single index and multiple index, returning a row vector. More... | |
template<typename T , typename I > | |
boost::disable_if< boost::is_same< I, index_uni >, Eigen::Matrix< T, Eigen::Dynamic, 1 > >::type | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< I, cons_index_list< index_uni, nil_index_list > > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a multiple index and a single index, returning a vector. More... | |
template<typename T , typename I1 , typename I2 > | |
boost::disable_if_c< boost::is_same< I1, index_uni >::value||boost::is_same< I2, index_uni >::value, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > >::type | rvalue (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &a, const cons_index_list< I1, cons_index_list< I2, nil_index_list > > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a pair o multiple indexes, returning a a matrix. More... | |
template<typename T , typename L > | |
rvalue_return< std::vector< T >, cons_index_list< index_uni, L > >::type | rvalue (const std::vector< T > &c, const cons_index_list< index_uni, L > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified array with a list of indexes beginning with a single index; the result is determined recursively. More... | |
template<typename T , typename I , typename L > | |
rvalue_return< std::vector< T >, cons_index_list< I, L > >::type | rvalue (const std::vector< T > &c, const cons_index_list< I, L > &idx, const char *name="ANON", int depth=0) |
Return the result of indexing the specified array with a list of indexes beginning with a multiple index; the result is determined recursively. More... | |
int | rvalue_at (int n, const index_multi &idx) |
Return the index in the underlying array corresponding to the specified position in the specified multi-index. More... | |
int | rvalue_at (int n, const index_omni &idx) |
Return the index in the underlying array corresponding to the specified position in the specified omni-index. More... | |
int | rvalue_at (int n, const index_min &idx) |
Return the index in the underlying array corresponding to the specified position in the specified min-index. More... | |
int | rvalue_at (int n, const index_max &idx) |
Return the index in the underlying array corresponding to the specified position in the specified max-index. More... | |
int | rvalue_at (int n, const index_min_max &idx) |
Return the index in the underlying array corresponding to the specified position in the specified min-max-index. More... | |
int | rvalue_index_size (const index_multi &idx, int size) |
Return size of specified multi-index. More... | |
int | rvalue_index_size (const index_omni &idx, int size) |
Return size of specified omni-index for specified size of input. More... | |
int | rvalue_index_size (const index_min &idx, int size) |
Return size of specified min index for specified size of input. More... | |
int | rvalue_index_size (const index_max &idx, int size) |
Return size of specified max index. More... | |
int | rvalue_index_size (const index_min_max &idx, int size) |
Return size of specified min-max index. More... | |
template<bool jacobian_adjust_transform, class M > | |
double | log_prob_propto (const M &model, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::ostream *msgs=0) |
Helper function to calculate log probability for double scalars up to a proportion. More... | |
template<bool propto, bool jacobian_adjust_transform, class M > | |
double | log_prob_grad (const M &model, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::vector< double > &gradient, std::ostream *msgs=0) |
Compute the gradient using reverse-mode automatic differentiation, writing the result into the specified gradient, using the specified perturbation. More... | |
template<bool jacobian_adjust_transform, class M > | |
double | log_prob_propto (const M &model, Eigen::VectorXd ¶ms_r, std::ostream *msgs=0) |
Helper function to calculate log probability for double scalars up to a proportion. More... | |
template<bool propto, bool jacobian_adjust_transform, class M > | |
double | log_prob_grad (const M &model, Eigen::VectorXd ¶ms_r, Eigen::VectorXd &gradient, std::ostream *msgs=0) |
Compute the gradient using reverse-mode automatic differentiation, writing the result into the specified gradient, using the specified perturbation. More... | |
template<bool propto, bool jacobian_adjust_transform, class M > | |
void | finite_diff_grad (const M &model, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::vector< double > &grad, double epsilon=1e-6, std::ostream *msgs=0) |
Compute the gradient using finite differences for the specified parameters, writing the result into the specified gradient, using the specified perturbation. More... | |
template<bool propto, bool jacobian_adjust_transform, class M > | |
int | test_gradients (const M &model, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, double epsilon, double error, stan::interface_callbacks::writer::base_writer &writer) |
Test the log_prob_grad() function's ability to produce accurate gradients using finite differences. More... | |
template<bool propto, bool jacobian_adjust_transform, class M > | |
double | grad_hess_log_prob (const M &model, std::vector< double > ¶ms_r, std::vector< int > ¶ms_i, std::vector< double > &gradient, std::vector< double > &hessian, std::ostream *msgs=0) |
Evaluate the log-probability, its gradient, and its Hessian at params_r. More... | |
template<class M > | |
void | gradient (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_f, std::ostream *msgs=0) |
template<class M > | |
void | gradient (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_f, stan::interface_callbacks::writer::base_writer &writer) |
template<class M > | |
void | hessian (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_f, Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &hess_f, std::ostream *msgs=0) |
template<class M > | |
void | gradient_dot_vector (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &v, double &f, double &grad_f_dot_v, std::ostream *msgs=0) |
template<class M > | |
void | hessian_times_vector (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &v, double &f, Eigen::Matrix< double, Eigen::Dynamic, 1 > &hess_f_dot_v, std::ostream *msgs=0) |
template<class M > | |
void | grad_tr_mat_times_hessian (const M &model, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &X, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_tr_X_hess_f, std::ostream *msgs=0) |
For compiling models.
|
inline |
Assign the specified scalar reference under the specified indexing to the specified scalar value.
Types: x[] <- y
T | Assigned variable type. |
U | Value type (must be assignable to T). |
[in] | x | Variable to be assigned. |
[in] | y | Value. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
Definition at line 33 of file lvalue.hpp.
|
inline |
Definition at line 39 of file lvalue.hpp.
|
inline |
Definition at line 51 of file lvalue.hpp.
|
inline |
Assign the specified Eigen vector at the specified single index to the specified value.
Types: vec[uni] <- scalar
T | Type of assigned vector scalar. |
U | Type of value (must be assignable to T). |
[in] | x | Vector variable to be assigned. |
[in] | idxs | Sequence of one single index (from 1). |
[in] | y | Value scalar. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If the index is out of bounds. |
Definition at line 76 of file lvalue.hpp.
|
inline |
Assign the specified Eigen vector at the specified single index to the specified value.
Types: row_vec[uni] <- scalar
T | Type of assigned row vector scalar. |
U | Type of value (must be assignable to T). |
[in] | x | Row vector variable to be assigned. |
[in] | idxs | Sequence of one single index (from 1). |
[in] | y | Value scalar. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | Index is out of bounds. |
Definition at line 101 of file lvalue.hpp.
|
inline |
Assign the specified Eigen vector at the specified multiple index to the specified value.
Types: vec[multi] <- vec
T | Type of assigned vector scalar. |
I | Type of multiple index. |
U | Type of vector value scalar (must be assignable to T). |
[in] | x | Row vector variable to be assigned. |
[in] | idxs | Sequence of one single index (from 1). |
[in] | y | Value vector. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the value size isn't the same as the indexed size. |
Definition at line 130 of file lvalue.hpp.
|
inline |
Assign the specified Eigen row vector at the specified multiple index to the specified value.
Types: row_vec[multi] <- row_vec
T | Scalar type for assigned row vector. |
I | Type of multiple index. |
U | Type of value row vector scalar (must be assignable to T). |
[in] | x | Row vector variable to be assigned. |
[in] | idxs | Sequence of one multiple index (from 1). |
[in] | y | Value vector. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the value size isn't the same as the indexed size. |
Definition at line 164 of file lvalue.hpp.
void stan::model::assign | ( | Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & | x, |
const cons_index_list< index_uni, nil_index_list > & | idxs, | ||
const Eigen::Matrix< U, 1, Eigen::Dynamic > & | y, | ||
const char * | name = "ANON" , |
||
int | depth = 0 |
||
) |
Assign the specified Eigen matrix at the specified single index to the specified row vector value.
Types: mat[uni] = rowvec
T | Assigned matrix scalar type. |
U | Type of value scalar for row vector (must be assignable to T). |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Sequence of one single index (from 1). |
[in] | y | Value row vector. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the number of columns in the row vector and matrix do not match. |
Definition at line 197 of file lvalue.hpp.
|
inline |
Assign the specified Eigen matrix at the specified multiple index to the specified matrix value.
Types: mat[multi] = mat
T | Assigned matrix scalar type. |
I | Multiple index type. |
U | Value matrix scalar type (must be assignable to T). |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Sequence of one multiple index (from 1). |
[in] | y | Value matrix. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the dimensions of the indexed matrix and right-hand side matrix do not match. |
Definition at line 228 of file lvalue.hpp.
void stan::model::assign | ( | Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > & | x, |
const cons_index_list< index_uni, cons_index_list< index_uni, nil_index_list > > & | idxs, | ||
const U & | y, | ||
const char * | name = "ANON" , |
||
int | depth = 0 |
||
) |
Assign the specified Eigen matrix at the specified pair of single indexes to the specified scalar value.
Types: mat[single, single] = scalar
T | Matrix scalar type. |
U | Scalar type. |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Sequence of two single indexes (from 1). |
[in] | y | Value scalar. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If either of the indices are out of bounds. |
Definition at line 262 of file lvalue.hpp.
|
inline |
Assign the specified Eigen matrix at the specified single and multiple index to the specified row vector.
Types: mat[uni, multi] = rowvec
T | Assigned matrix scalar type. |
I | Multi-index type. |
U | Value row vector scalar type (must be assignable to T). |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Sequence of single and multiple index (from 1). |
[in] | y | Value row vector. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the dimensions of the indexed matrix and right-hand side row vector do not match. |
Definition at line 296 of file lvalue.hpp.
|
inline |
Assign the specified Eigen matrix at the specified multiple and single index to the specified vector.
Types: mat[multi, uni] = vec
T | Assigned matrix scalar type. |
I | Multi-index type. |
U | Value vector scalar type (must be assignable to T). |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Sequence of multiple and single index (from 1). |
[in] | y | Value vector. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the dimensions of the indexed matrix and right-hand side vector do not match. |
Definition at line 333 of file lvalue.hpp.
|
inline |
Assign the specified Eigen matrix at the specified pair of multiple indexes to the specified matrix.
Types: mat[multi, multi] = mat
T | Assigned matrix scalar type. |
I1 | First multiple index type. |
I2 | Second multiple index type. |
U | Value matrix scalar type (must be assignable to T). |
[in] | x | Matrix variable to be assigned. |
[in] | idxs | Pair of multiple indexes (from 1). |
[in] | y | Value matrix. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the dimensions of the indexed matrix and value matrix do not match. |
Definition at line 374 of file lvalue.hpp.
|
inline |
Assign the specified array (standard vector) at the specified index list beginning with a single index to the specified value.
This function operates recursively to carry out the tail indexing.
Types: x[uni | L] = y
T | Assigned vector member type. |
L | Type of tail of index list. |
U | Value scalar type (must be assignable to indexed variable). |
[in] | x | Array variable to be assigned. |
[in] | idxs | List of indexes beginning with single index (from 1). |
[in] | y | Value. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the dimensions do not match in the tail assignment. |
Definition at line 422 of file lvalue.hpp.
|
inline |
Assign the specified array (standard vector) at the specified index list beginning with a multiple index to the specified value.
This function operates recursively to carry out the tail indexing.
Types: x[multi | L] = y
T | Assigned vector member type. |
I | Type of multiple index heading index list. |
L | Type of tail of index list. |
U | Value scalar type (must be assignable to indexed variable). |
[in] | x | Array variable to be assigned. |
[in] | idxs | List of indexes beginning with multiple index (from 1). |
[in] | y | Value. |
[in] | name | Name of variable (default "ANON"). |
[in] | depth | Indexing depth (default 0). |
std::out_of_range | If any of the indices are out of bounds. |
std::domain_error | If the size of the multiple indexing and size of first dimension of value do not match, or any of the recursive tail assignment dimensions do not match. |
Definition at line 457 of file lvalue.hpp.
|
inline |
Definition at line 43 of file index_list.hpp.
|
inline |
Return the specified argument as a constant reference.
Warning: because of the usage pattern of this class, this function only needs to return value references, not actual copies. The functions that call this overload recursively will be doing the actual copies with assignment.
T | Type of scalar. |
x | Input value. |
Definition at line 24 of file deep_copy.hpp.
|
inline |
Return a copy of the specified matrix, vector, or row vector.
The return value is a copy in the sense that modifying its contents will not affect the original matrix.
Warning: This function assumes that the elements of the matrix deep copy under assignment.
T | Scalar type. |
R | Row type specificiation. |
C | Column type specificiation. |
a | Input matrix, vector, or row vector. |
Definition at line 43 of file deep_copy.hpp.
|
inline |
Return a deep copy of the specified standard vector.
The return value is a copy in the sense that modifying its contents will not affect the original vector.
Warning: This function assumes that the elements of the vector deep copy under assignment.
T | Scalar type. |
v | Input vector. |
Definition at line 61 of file deep_copy.hpp.
void stan::model::finite_diff_grad | ( | const M & | model, |
std::vector< double > & | params_r, | ||
std::vector< int > & | params_i, | ||
std::vector< double > & | grad, | ||
double | epsilon = 1e-6 , |
||
std::ostream * | msgs = 0 |
||
) |
Compute the gradient using finite differences for the specified parameters, writing the result into the specified gradient, using the specified perturbation.
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
model | Model. | |
params_r | Real-valued parameters. | |
params_i | Integer-valued parameters. | |
[out] | grad | Vector into which gradient is written. |
epsilon | ||
[in,out] | msgs |
double stan::model::grad_hess_log_prob | ( | const M & | model, |
std::vector< double > & | params_r, | ||
std::vector< int > & | params_i, | ||
std::vector< double > & | gradient, | ||
std::vector< double > & | hessian, | ||
std::ostream * | msgs = 0 |
||
) |
Evaluate the log-probability, its gradient, and its Hessian at params_r.
This default version computes the Hessian numerically by finite-differencing the gradient, at a cost of O(params_r.size()^2).
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
model | Model. |
params_r | Real-valued parameter vector. |
params_i | Integer-valued parameter vector. |
gradient | Vector to write gradient to. |
hessian | Vector to write gradient to. hessian[i*D + j] gives the element at the ith row and jth column of the Hessian (where D=params_r.size()). |
msgs | Stream to which print statements in Stan programs are written, default is 0 |
void stan::model::grad_tr_mat_times_hessian | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > & | X, | ||
Eigen::Matrix< double, Eigen::Dynamic, 1 > & | grad_tr_X_hess_f, | ||
std::ostream * | msgs = 0 |
||
) |
void stan::model::gradient | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
double & | f, | ||
Eigen::Matrix< double, Eigen::Dynamic, 1 > & | grad_f, | ||
std::ostream * | msgs = 0 |
||
) |
void stan::model::gradient | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
double & | f, | ||
Eigen::Matrix< double, Eigen::Dynamic, 1 > & | grad_f, | ||
stan::interface_callbacks::writer::base_writer & | writer | ||
) |
void stan::model::gradient_dot_vector | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | v, | ||
double & | f, | ||
double & | grad_f_dot_v, | ||
std::ostream * | msgs = 0 |
||
) |
void stan::model::hessian | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
double & | f, | ||
Eigen::Matrix< double, Eigen::Dynamic, 1 > & | grad_f, | ||
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > & | hess_f, | ||
std::ostream * | msgs = 0 |
||
) |
void stan::model::hessian_times_vector | ( | const M & | model, |
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | x, | ||
const Eigen::Matrix< double, Eigen::Dynamic, 1 > & | v, | ||
double & | f, | ||
Eigen::Matrix< double, Eigen::Dynamic, 1 > & | hess_f_dot_v, | ||
std::ostream * | msgs = 0 |
||
) |
|
inline |
Definition at line 48 of file index_list.hpp.
|
inline |
Definition at line 54 of file index_list.hpp.
|
inline |
Definition at line 60 of file index_list.hpp.
|
inline |
Definition at line 70 of file index_list.hpp.
double stan::model::log_prob_grad | ( | const M & | model, |
std::vector< double > & | params_r, | ||
std::vector< int > & | params_i, | ||
std::vector< double > & | gradient, | ||
std::ostream * | msgs = 0 |
||
) |
Compute the gradient using reverse-mode automatic differentiation, writing the result into the specified gradient, using the specified perturbation.
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
[in] | model | Model. |
[in] | params_r | Real-valued parameters. |
[in] | params_i | Integer-valued parameters. |
[out] | gradient | Vector into which gradient is written. |
[in,out] | msgs |
double stan::model::log_prob_grad | ( | const M & | model, |
Eigen::VectorXd & | params_r, | ||
Eigen::VectorXd & | gradient, | ||
std::ostream * | msgs = 0 |
||
) |
Compute the gradient using reverse-mode automatic differentiation, writing the result into the specified gradient, using the specified perturbation.
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
[in] | model | Model. |
[in] | params_r | Real-valued parameters. |
[out] | gradient | Vector into which gradient is written. |
[in,out] | msgs |
double stan::model::log_prob_propto | ( | const M & | model, |
std::vector< double > & | params_r, | ||
std::vector< int > & | params_i, | ||
std::ostream * | msgs = 0 |
||
) |
Helper function to calculate log probability for double
scalars up to a proportion.
This implementation wraps the double
values in stan::math::var
and calls the model's log_prob()
function with propto=true
and the specified parameter for applying the Jacobian adjustment for transformed parameters.
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
[in] | model | Model. |
[in] | params_r | Real-valued parameters. |
[in] | params_i | Integer-valued parameters. |
[in,out] | msgs |
double stan::model::log_prob_propto | ( | const M & | model, |
Eigen::VectorXd & | params_r, | ||
std::ostream * | msgs = 0 |
||
) |
Helper function to calculate log probability for double
scalars up to a proportion.
This implementation wraps the double
values in stan::math::var
and calls the model's log_prob()
function with propto=true
and the specified parameter for applying the Jacobian adjustment for transformed parameters.
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
[in] | model | Model. |
[in] | params_r | Real-valued parameters. |
[in,out] | msgs |
|
inline |
Return the result of indexing a specified value with a nil index list, which just returns the value.
Types: T[] : T
T | Scalar type. |
[in] | c | Value to index. |
Definition at line 32 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen vector with a sequence containing one single index, returning a scalar.
Types: vec[single] : scal
T | Scalar type. |
[in] | v | Vector being indexed. |
[in] | idx | One single index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 51 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen row vector with a sequence containing one single index, returning a scalar.
Types: rowvec[single] : scal
T | Scalar type. |
[in] | rv | Row vector being indexed. |
[in] | idx | One single index in list. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 74 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen vector with a sequence containing one multiple index, returning a vector.
Types: vec[multiple] : vec
T | Scalar type. |
I | Multi-index type. |
[in] | v | Eigen vector. |
[in] | idx | Index consisting of one multi-index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 101 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen row vector with a sequence containing one multiple index, returning a row vector.
Types: row_vec[multiple] : rowvec
T | Scalar type. |
I | Multi-index type. |
[in] | rv | Eigen row vector. |
[in] | idx | Index consisting of one multi-index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 133 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of one single index, returning a row vector.
Types: mat[single] : rowvec
T | Scalar type. |
[in] | a | Eigen matrix. |
[in] | idx | Index consisting of one uni-index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 161 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a one multiple index, returning a matrix.
Types: mat[multiple] : mat
T | Scalar type. |
I | Type of multiple index. |
[in] | a | Matrix to index. |
[in] | idx | Index consisting of single multiple index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 187 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of two single indexes, returning a scalar.
Types: mat[single,single] : scalar
T | Scalar type. |
[in] | a | Matrix to index. |
[in] | idx | Pair of single indexes. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 215 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a single index and multiple index, returning a row vector.
Types: mat[single,multiple] : row vector
T | Scalar type. |
I | Type of multiple index. |
[in] | a | Matrix to index. |
[in] | idx | Pair of single index and multiple index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 246 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a multiple index and a single index, returning a vector.
Types: mat[multiple,single] : vector
T | Scalar type. |
I | Type of multiple index. |
[in] | a | Matrix to index. |
[in] | idx | Pair multiple index and single index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 275 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified Eigen matrix with a sequence consisting of a pair o multiple indexes, returning a a matrix.
Types: mat[multiple,multiple] : mat
T | Scalar type. |
I | Type of multiple index. |
[in] | a | Matrix to index. |
[in] | idx | Pair of multiple indexes. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 312 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified array with a list of indexes beginning with a single index; the result is determined recursively.
Note that arrays are represented as standard library vectors.
Types: std::vector<T>[single | L] : T[L]
T | Type of list elements. |
L | Index list type for indexes after first index. |
[in] | c | Container of list elements. |
[in] | idx | Index list beginning with single index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 352 of file rvalue.hpp.
|
inline |
Return the result of indexing the specified array with a list of indexes beginning with a multiple index; the result is determined recursively.
Note that arrays are represented as standard library vectors.
Types: std::vector<T>[multiple | L] : std::vector<T[L]>
T | Type of list elements. |
L | Index list type for indexes after first index. |
[in] | c | Container of list elements. |
[in] | idx | Index list beginning with multiple index. |
[in] | name | String form of expression being evaluated. |
[in] | depth | Depth of indexing dimension. |
Definition at line 377 of file rvalue.hpp.
|
inline |
Return the index in the underlying array corresponding to the specified position in the specified multi-index.
[in] | n | Relative index position (from 0). |
[in] | idx | Index (from 1). |
Definition at line 21 of file rvalue_at.hpp.
|
inline |
Return the index in the underlying array corresponding to the specified position in the specified omni-index.
[in] | n | Relative index position (from 0). |
[in] | idx | Index (from 1). |
Definition at line 33 of file rvalue_at.hpp.
|
inline |
Return the index in the underlying array corresponding to the specified position in the specified min-index.
All indexing begins from 1.
[in] | n | Relative index position (from 0). |
[in] | idx | Index (from 1) |
Definition at line 47 of file rvalue_at.hpp.
|
inline |
Return the index in the underlying array corresponding to the specified position in the specified max-index.
All indexing begins from 1.
[in] | n | Relative index position (from 0). |
[in] | idx | Index (from 1). |
Definition at line 61 of file rvalue_at.hpp.
|
inline |
Return the index in the underlying array corresponding to the specified position in the specified min-max-index.
All indexing begins from 1.
[in] | n | Relative index position (from 0). |
[in] | idx | Index (from 1). |
Definition at line 75 of file rvalue_at.hpp.
|
inline |
Return size of specified multi-index.
[in] | idx | Input index (from 1). |
[in] | size | Size of container (ignored here). |
Definition at line 19 of file rvalue_index_size.hpp.
|
inline |
Return size of specified omni-index for specified size of input.
[in] | idx | Input index (from 1). |
[in] | size | Size of container. |
Definition at line 31 of file rvalue_index_size.hpp.
|
inline |
Return size of specified min index for specified size of input.
[in] | idx | Input index (from 1). |
[in] | size | Size of container. |
Definition at line 43 of file rvalue_index_size.hpp.
|
inline |
Return size of specified max index.
[in] | idx | Input index (from 1). |
[in] | size | Size of container (ignored). |
Definition at line 54 of file rvalue_index_size.hpp.
|
inline |
Return size of specified min-max index.
[in] | idx | Input index (from 1). |
[in] | size | Size of container (ignored). |
Definition at line 65 of file rvalue_index_size.hpp.
int stan::model::test_gradients | ( | const M & | model, |
std::vector< double > & | params_r, | ||
std::vector< int > & | params_i, | ||
double | epsilon, | ||
double | error, | ||
stan::interface_callbacks::writer::base_writer & | writer | ||
) |
Test the log_prob_grad() function's ability to produce accurate gradients using finite differences.
This shouldn't be necessary when using autodiff, but is useful for finding bugs in hand-written code (or var).
propto | True if calculation is up to proportion (double-only terms dropped). |
jacobian_adjust_transform | True if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability. |
M | Class of model. |
model | Model. |
params_r | Real-valued parameter vector. |
params_i | Integer-valued parameter vector. |
epsilon | Real-valued scalar saying how much to perturb. Reasonable value is 1e-6. |
error | Real-valued scalar saying how much error to allow. Reasonable value is 1e-6. |
writer | Writer for messages |