Classes | Functions
stan::model Namespace Reference

Classes

struct  cons_index_list
 
struct  index_max
 
struct  index_min
 
struct  index_min_max
 
struct  index_multi
 
struct  index_omni
 
struct  index_uni
 
struct  model_functional
 
struct  nil_index_list
 
class  prob_grad
 
struct  rvalue_return
 
struct  rvalue_return< C, nil_index_list >
 
struct  rvalue_return< Eigen::Matrix< T, 1, Eigen::Dynamic >, cons_index_list< index_uni, nil_index_list > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, 1 >, cons_index_list< index_uni, nil_index_list > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< I, cons_index_list< index_uni, nil_index_list > > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< I1, cons_index_list< I2, nil_index_list > > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, cons_index_list< I, nil_index_list > > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, cons_index_list< index_uni, nil_index_list > > >
 
struct  rvalue_return< Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic >, cons_index_list< index_uni, nil_index_list > >
 
struct  rvalue_return< Eigen::Matrix< T, R, C >, cons_index_list< I, nil_index_list > >
 
struct  rvalue_return< std::vector< C >, cons_index_list< I, L > >
 
struct  rvalue_return< std::vector< C >, cons_index_list< index_uni, L > >
 

Functions

template<bool propto, bool jacobian_adjust_transform, class M >
void finite_diff_grad (const M &model, stan::callbacks::interrupt &interrupt, std::vector< double > &params_r, std::vector< int > &params_i, std::vector< double > &grad, double epsilon=1e-6, std::ostream *msgs=0)
 
template<bool propto, bool jacobian_adjust_transform, class M >
double 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)
 
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)
 
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, callbacks::logger &logger)
 
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 (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 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<typename T >
const Tdeep_copy (const T &x)
 
template<typename T , int R, int C>
Eigen::Matrix< T, R, Cdeep_copy (const Eigen::Matrix< T, R, C > &a)
 
template<typename T >
std::vector< Tdeep_copy (const std::vector< T > &v)
 
template<typename I , typename T >
cons_index_list< I, Tcons_list (const I &idx1, const T &t)
 
nil_index_list index_list ()
 
template<typename I >
cons_index_list< I, nil_index_listindex_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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
template<typename T >
T rvalue (const T &c, const nil_index_list &, const char *="", int=0)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
int rvalue_at (int n, const index_multi &idx)
 
int rvalue_at (int n, const index_omni &idx)
 
int rvalue_at (int n, const index_min &idx)
 
int rvalue_at (int n, const index_max &idx)
 
int rvalue_at (int n, const index_min_max &idx)
 
int rvalue_index_size (const index_multi &idx, int size)
 
int rvalue_index_size (const index_omni &idx, int size)
 
int rvalue_index_size (const index_min &idx, int size)
 
int rvalue_index_size (const index_max &idx, int size)
 
int rvalue_index_size (const index_min_max &idx, int size)
 
template<bool propto, bool jacobian_adjust_transform, class M >
double log_prob_grad (const M &model, std::vector< double > &params_r, std::vector< int > &params_i, std::vector< double > &gradient, std::ostream *msgs=0)
 
template<bool propto, bool jacobian_adjust_transform, class M >
double log_prob_grad (const M &model, Eigen::VectorXd &params_r, Eigen::VectorXd &gradient, std::ostream *msgs=0)
 
template<bool jacobian_adjust_transform, class M >
double log_prob_propto (const M &model, std::vector< double > &params_r, std::vector< int > &params_i, std::ostream *msgs=0)
 
template<bool jacobian_adjust_transform, class M >
double log_prob_propto (const M &model, Eigen::VectorXd &params_r, std::ostream *msgs=0)
 
template<bool propto, bool jacobian_adjust_transform, class Model >
int test_gradients (const Model &model, std::vector< double > &params_r, std::vector< int > &params_i, double epsilon, double error, stan::callbacks::interrupt &interrupt, stan::callbacks::logger &logger, stan::callbacks::writer &parameter_writer)
 

Function Documentation

template<typename T , typename U >
void stan::model::assign ( T x,
const nil_index_list ,
const U &  y,
const char *  name = "ANON",
int  depth = 0 
)
inline

Assign the specified scalar reference under the specified indexing to the specified scalar value.

Types: x[] <- y

Template Parameters
TAssigned variable type.
UValue type (must be assignable to T).
Parameters
[in]xVariable to be assigned.
[in]yValue.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).

Definition at line 32 of file lvalue.hpp.

References submit_syst::y.

Referenced by assign(), TEST(), test_throw(), and test_throw_ia().

33  {
34  x = y;
35  }
template<typename T , typename U , int R, int C>
void stan::model::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 
)
inline

Definition at line 38 of file lvalue.hpp.

References assign(), MECModelEnuComparisons::i, submit_syst::x, and submit_syst::y.

42  {
43  x.resize(y.rows(), y.cols());
44  for (int i = 0; i < y.size(); ++i)
45  assign(x(i), nil_index_list(), y(i), name, depth + 1);
46  }
const XML_Char * name
Definition: expat.h:151
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)
Definition: lvalue.hpp:465
template<typename T , typename U >
void stan::model::assign ( std::vector< T > &  x,
const nil_index_list ,
const std::vector< U > &  y,
const char *  name = "ANON",
int  depth = 0 
)
inline

Definition at line 50 of file lvalue.hpp.

References assign(), and MECModelEnuComparisons::i.

52  {
53  x.resize(y.size());
54  for (size_t i = 0; i < y.size(); ++i)
55  assign(x[i], nil_index_list(), y[i], name, depth + 1);
56  }
const XML_Char * name
Definition: expat.h:151
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)
Definition: lvalue.hpp:465
template<typename T , typename U >
void stan::model::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 
)
inline

Assign the specified Eigen vector at the specified single index to the specified value.

Types: vec[uni] <- scalar

Template Parameters
TType of assigned vector scalar.
UType of value (must be assignable to T).
Parameters
[in]xVector variable to be assigned.
[in]idxsSequence of one single index (from 1).
[in]yValue scalar.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf the index is out of bounds.

Definition at line 75 of file lvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, stan::model::index_uni::n_, submit_syst::x, and submit_syst::y.

78  {
79  int i = idxs.head_.n_;
80  math::check_range("vector[uni] assign range", name, x.size(), i);
81  x(i - 1) = y;
82  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T , typename U >
void stan::model::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 
)
inline

Assign the specified Eigen vector at the specified single index to the specified value.

Types: row_vec[uni] <- scalar

Template Parameters
TType of assigned row vector scalar.
UType of value (must be assignable to T).
Parameters
[in]xRow vector variable to be assigned.
[in]idxsSequence of one single index (from 1).
[in]yValue scalar.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIndex is out of bounds.

Definition at line 100 of file lvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, stan::model::index_uni::n_, submit_syst::x, and submit_syst::y.

103  {
104  int i = idxs.head_.n_;
105  math::check_range("row_vector[uni] assign range", name, x.size(), i);
106  x(i - 1) = y;
107  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T , typename I , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::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 
)
inline

Assign the specified Eigen vector at the specified multiple index to the specified value.

Types: vec[multi] <- vec

Template Parameters
TType of assigned vector scalar.
IType of multiple index.
UType of vector value scalar (must be assignable to T).
Parameters
[in]xRow vector variable to be assigned.
[in]idxsSequence of one single index (from 1).
[in]yValue vector.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the value size isn't the same as the indexed size.

Definition at line 129 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

132  {
133  math::check_size_match("vector[multi] assign sizes",
134  "lhs", rvalue_index_size(idxs.head_, x.size()),
135  name, y.size());
136  for (int n = 0; n < y.size(); ++n) {
137  int i = rvalue_at(n, idxs.head_);
138  math::check_range("vector[multi] assign range", name, x.size(), i);
139  x(i - 1) = y(n);
140  }
141  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
template<typename T , typename I , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::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 
)
inline

Assign the specified Eigen row vector at the specified multiple index to the specified value.

Types: row_vec[multi] <- row_vec

Template Parameters
TScalar type for assigned row vector.
IType of multiple index.
UType of value row vector scalar (must be assignable to T).
Parameters
[in]xRow vector variable to be assigned.
[in]idxsSequence of one multiple index (from 1).
[in]yValue vector.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the value size isn't the same as the indexed size.

Definition at line 164 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

167  {
168  math::check_size_match("row_vector[multi] assign sizes",
169  "lhs", rvalue_index_size(idxs.head_, x.size()),
170  name, y.size());
171  for (int n = 0; n < y.size(); ++n) {
172  int i = rvalue_at(n, idxs.head_);
173  math::check_range("row_vector[multi] assign range", name, x.size(), i);
174  x(i - 1) = y(n);
175  }
176  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
template<typename T , typename U >
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

Template Parameters
TAssigned matrix scalar type.
UType of value scalar for row vector (must be assignable to T).
Parameters
[in]xMatrix variable to be assigned.
[in]idxsSequence of one single index (from 1).
[in]yValue row vector.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the number of columns in the row vector and matrix do not match.

Definition at line 197 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, calib::j, stan::model::index_uni::n_, submit_syst::x, and submit_syst::y.

200  {
201  math::check_size_match("matrix[uni] assign sizes",
202  "lhs", x.cols(),
203  name, y.cols());
204  int i = idxs.head_.n_;
205  math::check_range("matrix[uni] assign range", name, x.rows(), i);
206  for (int j = 0; j < x.cols(); ++j) // loop allows double to var assgn
207  x(i - 1, j) = y(j);
208  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
const double j
Definition: BetheBloch.cxx:29
template<typename T , typename I , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::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 
)
inline

Assign the specified Eigen matrix at the specified multiple index to the specified matrix value.

Types: mat[multi] = mat

Template Parameters
TAssigned matrix scalar type.
IMultiple index type.
UValue matrix scalar type (must be assignable to T).
Parameters
[in]xMatrix variable to be assigned.
[in]idxsSequence of one multiple index (from 1).
[in]yValue matrix.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the dimensions of the indexed matrix and right-hand side matrix do not match.

Definition at line 230 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, calib::j, m, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

233  {
234  int x_idx_rows = rvalue_index_size(idxs.head_, x.rows());
235  math::check_size_match("matrix[multi] assign row sizes",
236  "lhs", x_idx_rows,
237  name, y.rows());
238  math::check_size_match("matrix[multi] assign col sizes",
239  "lhs", x.cols(),
240  name, y.cols());
241  for (int i = 0; i < y.rows(); ++i) {
242  int m = rvalue_at(i, idxs.head_);
243  math::check_range("matrix[multi] assign range", name, x.rows(), m);
244  // recurse to allow double to var assign
245  for (int j = 0; j < x.cols(); ++j)
246  x(m - 1, j) = y(i, j);
247  }
248  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
const double j
Definition: BetheBloch.cxx:29
template<typename T , typename U >
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

Template Parameters
TMatrix scalar type.
UScalar type.
Parameters
[in]xMatrix variable to be assigned.
[in]idxsSequence of two single indexes (from 1).
[in]yValue scalar.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf either of the indices are out of bounds.

Definition at line 266 of file lvalue.hpp.

References stan::math::check_range(), m, getGoodRuns4SAM::n, submit_syst::x, and submit_syst::y.

271  {
272  int m = idxs.head_.n_;
273  int n = idxs.tail_.head_.n_;
274  math::check_range("matrix[uni,uni] assign range", name, x.rows(), m);
275  math::check_range("matrix[uni,uni] assign range", name, x.cols(), n);
276  x(m - 1, n - 1) = y;
277  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T , typename I , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::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 
)
inline

Assign the specified Eigen matrix at the specified single and multiple index to the specified row vector.

Types: mat[uni, multi] = rowvec

Template Parameters
TAssigned matrix scalar type.
IMulti-index type.
UValue row vector scalar type (must be assignable to T).
Parameters
[in]xMatrix variable to be assigned.
[in]idxsSequence of single and multiple index (from 1).
[in]yValue row vector.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the dimensions of the indexed matrix and right-hand side row vector do not match.

Definition at line 300 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), MECModelEnuComparisons::i, m, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

304  {
305  int x_idxs_cols = rvalue_index_size(idxs.tail_.head_, x.cols());
306  math::check_size_match("matrix[uni,multi] assign sizes",
307  "lhs", x_idxs_cols,
308  name, y.cols());
309  int m = idxs.head_.n_;
310  math::check_range("matrix[uni,multi] assign range", name, x.rows(), m);
311  for (int i = 0; i < y.size(); ++i) {
312  int n = rvalue_at(i, idxs.tail_.head_);
313  math::check_range("matrix[uni,multi] assign range", name, x.cols(), n);
314  x(m - 1, n - 1) = y(i);
315  }
316  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
template<typename T , typename I , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::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 
)
inline

Assign the specified Eigen matrix at the specified multiple and single index to the specified vector.

Types: mat[multi, uni] = vec

Template Parameters
TAssigned matrix scalar type.
IMulti-index type.
UValue vector scalar type (must be assignable to T).
Parameters
[in]xMatrix variable to be assigned.
[in]idxsSequence of multiple and single index (from 1).
[in]yValue vector.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the dimensions of the indexed matrix and right-hand side vector do not match.

Definition at line 338 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), MECModelEnuComparisons::i, m, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

343  {
344  int x_idxs_rows = rvalue_index_size(idxs.head_, x.rows());
345  math::check_size_match("matrix[multi,uni] assign sizes",
346  "lhs", x_idxs_rows,
347  name, y.rows());
348  int n = idxs.tail_.head_.n_;
349  math::check_range("matrix[multi,uni] assign range", name, x.cols(), n);
350  for (int i = 0; i < y.size(); ++i) {
351  int m = rvalue_at(i, idxs.head_);
352  math::check_range("matrix[multi,uni] assign range", name, x.rows(), m);
353  x(m - 1, n - 1) = y(i);
354  }
355  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
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 stan::model::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 
)
inline

Assign the specified Eigen matrix at the specified pair of multiple indexes to the specified matrix.

Types: mat[multi, multi] = mat

Template Parameters
TAssigned matrix scalar type.
I1First multiple index type.
I2Second multiple index type.
UValue matrix scalar type (must be assignable to T).
Parameters
[in]xMatrix variable to be assigned.
[in]idxsPair of multiple indexes (from 1).
[in]yValue matrix.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the dimensions of the indexed matrix and value matrix do not match.

Definition at line 380 of file lvalue.hpp.

References stan::math::check_range(), stan::math::check_size_match(), MECModelEnuComparisons::i, calib::j, m, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), submit_syst::x, and submit_syst::y.

384  {
385  int x_idxs_rows = rvalue_index_size(idxs.head_, x.rows());
386  int x_idxs_cols = rvalue_index_size(idxs.tail_.head_, x.cols());
387  math::check_size_match("matrix[multi,multi] assign sizes",
388  "lhs", x_idxs_rows,
389  name, y.rows());
390  math::check_size_match("matrix[multi,multi] assign sizes",
391  "lhs", x_idxs_cols,
392  name, y.cols());
393  for (int j = 0; j < y.cols(); ++j) {
394  int n = rvalue_at(j, idxs.tail_.head_);
395  math::check_range("matrix[multi,multi] assign range", name,
396  x.cols(), n);
397  for (int i = 0; i < y.rows(); ++i) {
398  int m = rvalue_at(i, idxs.head_);
399  math::check_range("matrix[multi,multi] assign range", name,
400  x.rows(), m);
401  x(m - 1, n - 1) = y(i, j);
402  }
403  }
404  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
const double j
Definition: BetheBloch.cxx:29
template<typename T , typename L , typename U >
void stan::model::assign ( std::vector< T > &  x,
const cons_index_list< index_uni, L > &  idxs,
const U &  y,
const char *  name = "ANON",
int  depth = 0 
)
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

Template Parameters
TAssigned vector member type.
LType of tail of index list.
UValue scalar type (must be assignable to indexed variable).
Parameters
[in]xArray variable to be assigned.
[in]idxsList of indexes beginning with single index (from 1).
[in]yValue.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf the dimensions do not match in the tail assignment.

Definition at line 430 of file lvalue.hpp.

References assign(), stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, stan::model::index_uni::n_, and stan::model::cons_index_list< H, T >::tail_.

432  {
433  int i = idxs.head_.n_;
434  math::check_range("vector[uni,...] assign range", name, x.size(), i);
435  assign(x[i - 1], idxs.tail_, y, name, depth + 1);
436  }
const XML_Char * name
Definition: expat.h:151
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)
Definition: lvalue.hpp:465
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T , typename I , typename L , typename U >
boost::disable_if<boost::is_same<I, index_uni>, void>::type stan::model::assign ( std::vector< T > &  x,
const cons_index_list< I, L > &  idxs,
const std::vector< U > &  y,
const char *  name = "ANON",
int  depth = 0 
)
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

Template Parameters
TAssigned vector member type.
IType of multiple index heading index list.
LType of tail of index list.
UValue scalar type (must be assignable to indexed variable).
Parameters
[in]xArray variable to be assigned.
[in]idxsList of indexes beginning with multiple index (from 1).
[in]yValue.
[in]nameName of variable (default "ANON").
[in]depthIndexing depth (default 0).
Exceptions
std::out_of_rangeIf any of the indices are out of bounds.
std::invalid_argumentIf 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 465 of file lvalue.hpp.

References assign(), stan::math::check_range(), stan::math::check_size_match(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), and stan::model::cons_index_list< H, T >::tail_.

467  {
468  int x_idx_size = rvalue_index_size(idxs.head_, x.size());
469  math::check_size_match("vector[multi,...] assign sizes",
470  "lhs", x_idx_size,
471  name, y.size());
472  for (size_t n = 0; n < y.size(); ++n) {
473  int i = rvalue_at(n, idxs.head_);
474  math::check_range("vector[multi,...] assign range", name, x.size(), i);
475  assign(x[i - 1], idxs.tail_, y[n], name, depth + 1);
476  }
477  }
const XML_Char * name
Definition: expat.h:151
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)
Definition: lvalue.hpp:465
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
template<typename I , typename T >
cons_index_list<I, T> stan::model::cons_list ( const I &  idx1,
const T t 
)
inline

Definition at line 43 of file index_list.hpp.

References confusionMatrixTree::t.

Referenced by index_list(), and TEST().

43  {
44  return cons_index_list<I, T>(idx1, t);
45  }
template<typename T >
const T& stan::model::deep_copy ( const T x)
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.

Template Parameters
TType of scalar.
Parameters
xInput value.
Returns
Constant reference to input.

Definition at line 24 of file deep_copy.hpp.

References submit_syst::x.

Referenced by TEST(), and test_vec().

24  {
25  return x;
26  }
template<typename T , int R, int C>
Eigen::Matrix<T, R, C> stan::model::deep_copy ( const Eigen::Matrix< T, R, C > &  a)
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.

Template Parameters
TScalar type.
RRow type specificiation.
CColumn type specificiation.
Parameters
aInput matrix, vector, or row vector.
Returns
Deep copy of input.

Definition at line 43 of file deep_copy.hpp.

References fillBadChanDBTables::result.

43  {
44  Eigen::Matrix<T, R, C> result(a);
45  return result;
46  }
const double a
template<typename T >
std::vector<T> stan::model::deep_copy ( const std::vector< T > &  v)
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.

Template Parameters
TScalar type.
Parameters
vInput vector.
Returns
Deep copy of input.

Definition at line 61 of file deep_copy.hpp.

References fillBadChanDBTables::result.

61  {
62  std::vector<T> result(v);
63  return result;
64  }
template<bool propto, bool jacobian_adjust_transform, class M >
void stan::model::finite_diff_grad ( const M &  model,
stan::callbacks::interrupt interrupt,
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.

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
modelModel.
interruptinterrupt callback to be called before calculating the finite differences for each parameter.
params_rReal-valued parameters.
params_iInteger-valued parameters.
[out]gradVector into which gradient is written.
epsilon
[in,out]msgs

Definition at line 32 of file finite_diff_grad.hpp.

References epsilon, and lem_server::msgs.

38  {
39  std::vector<double> perturbed(params_r);
40  grad.resize(params_r.size());
41  for (size_t k = 0; k < params_r.size(); k++) {
42  interrupt();
43  perturbed[k] += epsilon;
44  double logp_plus
45  = model
46  .template log_prob<propto,
47  jacobian_adjust_transform>(perturbed, params_i,
48  msgs);
49  perturbed[k] = params_r[k] - epsilon;
50  double logp_minus
51  = model
52  .template log_prob<propto,
53  jacobian_adjust_transform>(perturbed, params_i,
54  msgs);
55  double gradest = (logp_plus - logp_minus) / (2*epsilon);
56  grad[k] = gradest;
57  perturbed[k] = params_r[k];
58  }
59  }
static void grad(vari *vi)
Definition: grad.hpp:30
double epsilon
const XML_Char XML_Content * model
Definition: expat.h:151
template<bool propto, bool jacobian_adjust_transform, class M >
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).

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameter vector.
[in]params_iInteger-valued parameter vector.
[out]gradientVector to write gradient to.
[out]hessianVector 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()).
[in,out]msgsStream to which print statements in Stan programs are written, default is 0

Definition at line 34 of file grad_hess_log_prob.hpp.

References d, e, epsilon, gradient(), MECModelEnuComparisons::i, lem_server::msgs, fillBadChanDBTables::result, and check_grl::row.

38  {
39  static const double epsilon = 1e-3;
40  static const double half_epsilon = 0.5 * epsilon;
41  static const int order = 4;
42  static const double perturbations[order]
43  = {-2*epsilon, -1*epsilon, epsilon, 2*epsilon};
44  static const double coefficients[order]
45  = { 1.0 / 12.0, -2.0 / 3.0, 2.0 / 3.0, -1.0 / 12.0 };
46 
47  double result
48  = log_prob_grad<propto, jacobian_adjust_transform>(model, params_r,
49  params_i, gradient,
50  msgs);
51  hessian.assign(params_r.size() * params_r.size(), 0);
52  std::vector<double> temp_grad(params_r.size());
53  std::vector<double> perturbed_params(params_r.begin(), params_r.end());
54  for (size_t d = 0; d < params_r.size(); ++d) {
55  double* row = &hessian[d*params_r.size()];
56  for (int i = 0; i < order; ++i) {
57  perturbed_params[d] = params_r[d] + perturbations[i];
58  log_prob_grad<propto, jacobian_adjust_transform>(model,
59  perturbed_params,
60  params_i, temp_grad);
61  for (size_t dd = 0; dd < params_r.size(); ++dd) {
62  double increment = half_epsilon * coefficients[i] * temp_grad[dd];
63  row[dd] += increment;
64  hessian[d + dd*params_r.size()] += increment;
65  }
66  }
67  perturbed_params[d] = params_r[d];
68  }
69  return result;
70  }
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)
Definition: hessian.hpp:12
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)
Definition: gradient.hpp:15
Float_t d
Definition: plot.C:236
double epsilon
Float_t e
Definition: plot.C:35
const XML_Char XML_Content * model
Definition: expat.h:151
template<class M >
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 
)

Definition at line 12 of file grad_tr_mat_times_hessian.hpp.

References stan::math::grad_tr_mat_times_hessian(), and lem_server::msgs.

Referenced by TEST().

17  {
18  stan::math::grad_tr_mat_times_hessian(model_functional<M>(model, msgs),
19  x, X, grad_tr_X_hess_f);
20  }
void grad_tr_mat_times_hessian(const F &f, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > &M, Eigen::Matrix< double, Eigen::Dynamic, 1 > &grad_tr_MH)
Float_t X
Definition: plot.C:38
const XML_Char XML_Content * model
Definition: expat.h:151
template<class M >
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 
)

Definition at line 15 of file gradient.hpp.

References stan::math::gradient(), and lem_server::msgs.

Referenced by stan::variational::normal_meanfield::calc_grad(), stan::variational::normal_fullrank::calc_grad(), grad_hess_log_prob(), stan::services::util::initialize(), stan::optimization::newton_step(), TEST(), and stan::mcmc::base_hamiltonian< Model, unit_e_point, BaseRNG >::update_potential_gradient().

19  {
20  stan::math::gradient(model_functional<M>(model, msgs), x, f, grad_f);
21  }
void gradient(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, T &fx, Eigen::Matrix< T, Eigen::Dynamic, 1 > &grad_fx)
Definition: gradient.hpp:39
const XML_Char XML_Content * model
Definition: expat.h:151
template<class M >
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,
callbacks::logger logger 
)

Definition at line 24 of file gradient.hpp.

References e, stan::math::gradient(), stan::callbacks::logger::info(), and ss.

28  {
29  std::stringstream ss;
30  try {
31  stan::math::gradient(model_functional<M>(model, &ss), x, f, grad_f);
32  } catch (std::exception& e) {
33  if (ss.str().length() > 0)
34  logger.info(ss);
35  throw;
36  }
37  if (ss.str().length() > 0)
38  logger.info(ss);
39  }
Float_t ss
Definition: plot.C:24
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
Float_t e
Definition: plot.C:35
void gradient(const F &f, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, T &fx, Eigen::Matrix< T, Eigen::Dynamic, 1 > &grad_fx)
Definition: gradient.hpp:39
const XML_Char XML_Content * model
Definition: expat.h:151
template<class M >
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 
)

Definition at line 12 of file gradient_dot_vector.hpp.

References stan::math::gradient_dot_vector(), and lem_server::msgs.

Referenced by TEST().

17  {
18  stan::math::gradient_dot_vector(model_functional<M>(model, msgs),
19  x, v, f, grad_f_dot_v);
20  }
const XML_Char XML_Content * model
Definition: expat.h:151
void gradient_dot_vector(const F &f, const Eigen::Matrix< T1, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< T2, Eigen::Dynamic, 1 > &v, T1 &fx, T1 &grad_fx_dot_v)
template<class M >
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 
)

Definition at line 12 of file hessian.hpp.

References lem_server::msgs.

Referenced by stan::optimization::newton_step(), and TEST().

17  {
18  stan::math::hessian<model_functional<M> >(model_functional<M>(model,
19  msgs),
20  x, f, grad_f, hess_f);
21  }
const XML_Char XML_Content * model
Definition: expat.h:151
template<class M >
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 
)

Definition at line 12 of file hessian_times_vector.hpp.

References stan::math::hessian_times_vector(), and lem_server::msgs.

Referenced by TEST().

18  {
19  stan::math::hessian_times_vector(model_functional<M>(model, msgs),
20  x, v, f, hess_f_dot_v);
21  }
void hessian_times_vector(const F &f, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &x, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &v, double &fx, Eigen::Matrix< double, Eigen::Dynamic, 1 > &Hv)
const XML_Char XML_Content * model
Definition: expat.h:151
nil_index_list stan::model::index_list ( )
inline

Definition at line 48 of file index_list.hpp.

Referenced by index_list(), TEST(), vector_multi_test(), and vector_uni_test().

48  {
49  return nil_index_list();
50  }
template<typename I >
cons_index_list<I, nil_index_list> stan::model::index_list ( const I &  idx)
inline

Definition at line 54 of file index_list.hpp.

References cons_list(), and index_list().

54  {
55  return cons_list(idx, index_list());
56  }
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)
Definition: index_list.hpp:70
cons_index_list< I, T > cons_list(const I &idx1, const T &t)
Definition: index_list.hpp:43
template<typename I1 , typename I2 >
cons_index_list<I1, cons_index_list<I2, nil_index_list> > stan::model::index_list ( const I1 &  idx1,
const I2 &  idx2 
)
inline

Definition at line 60 of file index_list.hpp.

References cons_list(), and index_list().

60  {
61  return cons_list(idx1, index_list(idx2));
62  }
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)
Definition: index_list.hpp:70
cons_index_list< I, T > cons_list(const I &idx1, const T &t)
Definition: index_list.hpp:43
template<typename I1 , typename I2 , typename I3 >
cons_index_list<I1, cons_index_list<I2, cons_index_list<I3, nil_index_list> > > stan::model::index_list ( const I1 &  idx1,
const I2 &  idx2,
const I3 &  idx3 
)
inline

Definition at line 70 of file index_list.hpp.

References cons_list(), and index_list().

70  {
71  return cons_list(idx1, index_list(idx2, idx3));
72  }
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)
Definition: index_list.hpp:70
cons_index_list< I, T > cons_list(const I &idx1, const T &t)
Definition: index_list.hpp:43
template<bool propto, bool jacobian_adjust_transform, class M >
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.

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameters.
[in]params_iInteger-valued parameters.
[out]gradientVector into which gradient is written.
[in,out]msgs

Definition at line 29 of file log_prob_grad.hpp.

References MECModelEnuComparisons::i, lem_server::msgs, stan::math::recover_memory(), and PandAna.Demos.tute_pid_validation::var.

Referenced by stan::optimization::ModelAdaptor< M >::operator()().

33  {
34  using std::vector;
35  using stan::math::var;
36  double lp;
37  try {
38  vector<var> ad_params_r(params_r.size());
39  for (size_t i = 0; i < model.num_params_r(); ++i) {
40  stan::math::var var_i(params_r[i]);
41  ad_params_r[i] = var_i;
42  }
43  var adLogProb
44  = model.template log_prob<propto, jacobian_adjust_transform>
45  (ad_params_r, params_i, msgs);
46  lp = adLogProb.val();
47  adLogProb.grad(ad_params_r, gradient);
48  } catch (const std::exception &ex) {
50  throw;
51  }
53  return lp;
54  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
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)
Definition: gradient.hpp:15
static void recover_memory()
const XML_Char XML_Content * model
Definition: expat.h:151
template<bool propto, bool jacobian_adjust_transform, class M >
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.

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameters.
[out]gradientVector into which gradient is written.
[in,out]msgs

Definition at line 73 of file log_prob_grad.hpp.

References stan::math::grad(), MECModelEnuComparisons::i, lem_server::msgs, stan::math::recover_memory(), febshutoff_auto::val, and PandAna.Demos.tute_pid_validation::var.

76  {
77  using std::vector;
78  using stan::math::var;
79 
80  Eigen::Matrix<var, Eigen::Dynamic, 1> ad_params_r(params_r.size());
81  for (size_t i = 0; i < model.num_params_r(); ++i) {
82  stan::math::var var_i(params_r[i]);
83  ad_params_r[i] = var_i;
84  }
85  try {
86  var adLogProb
87  = model
88  .template log_prob<propto,
89  jacobian_adjust_transform>(ad_params_r, msgs);
90  double val = adLogProb.val();
91  stan::math::grad(adLogProb, ad_params_r, gradient);
92  return val;
93  } catch (std::exception &ex) {
95  throw;
96  }
97  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
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)
Definition: gradient.hpp:15
static void grad(vari *vi)
Definition: grad.hpp:30
static void recover_memory()
const XML_Char XML_Content * model
Definition: expat.h:151
template<bool jacobian_adjust_transform, class M >
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.

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameters.
[in]params_iInteger-valued parameters.
[in,out]msgs

Definition at line 33 of file log_prob_propto.hpp.

References MECModelEnuComparisons::i, lem_server::msgs, stan::math::recover_memory(), febshutoff_auto::val, and PandAna.Demos.tute_pid_validation::var.

Referenced by stan::optimization::ModelAdaptor< M >::operator()().

36  {
37  using stan::math::var;
38  using std::vector;
39  vector<var> ad_params_r;
40  ad_params_r.reserve(model.num_params_r());
41  for (size_t i = 0; i < model.num_params_r(); ++i)
42  ad_params_r.push_back(params_r[i]);
43  try {
44  double lp
45  = model.template log_prob<true, jacobian_adjust_transform>
46  (ad_params_r, params_i, msgs).val();
48  return lp;
49  } catch (std::exception &ex) {
51  throw;
52  }
53  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static void recover_memory()
const XML_Char XML_Content * model
Definition: expat.h:151
template<bool jacobian_adjust_transform, class M >
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.

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
MClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameters.
[in,out]msgs

Definition at line 76 of file log_prob_propto.hpp.

References MECModelEnuComparisons::i, lem_server::msgs, stan::math::recover_memory(), febshutoff_auto::val, and PandAna.Demos.tute_pid_validation::var.

78  {
79  using stan::math::var;
80  using std::vector;
81  vector<int> params_i(0);
82 
83  double lp;
84  try {
85  vector<var> ad_params_r;
86  ad_params_r.reserve(model.num_params_r());
87  for (size_t i = 0; i < model.num_params_r(); ++i)
88  ad_params_r.push_back(params_r(i));
89  lp
90  = model
91  .template log_prob<true,
92  jacobian_adjust_transform>(ad_params_r, params_i,
93  msgs)
94  .val();
95  } catch (std::exception &ex) {
97  throw;
98  }
100  return lp;
101  }
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
static void recover_memory()
const XML_Char XML_Content * model
Definition: expat.h:151
template<typename T >
T stan::model::rvalue ( const T c,
const nil_index_list ,
const char *  = "",
int  = 0 
)
inline

Return the result of indexing a specified value with a nil index list, which just returns the value.

Types: T[] : T

Template Parameters
TScalar type.
Parameters
[in]cValue to index.
Returns
Input value.

Definition at line 31 of file rvalue.hpp.

References make_syst_table_plots::c.

Referenced by rvalue(), TEST(), test_out_of_range(), vector_multi_test(), and vector_uni_test().

32  {
33  return c;
34  }
template<typename T >
T stan::model::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 
)
inline

Return the result of indexing the specified Eigen vector with a sequence containing one single index, returning a scalar.

Types: vec[single] : scal

Template Parameters
TScalar type.
Parameters
[in]vVector being indexed.
[in]idxOne single index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing vector.

Definition at line 50 of file rvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, stan::model::index_uni::n_, and registry_explorer::v.

52  {
53  int ones_idx = idx.head_.n_;
54  math::check_range("vector[single] indexing", name, v.size(), ones_idx);
55  return v(ones_idx - 1);
56  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T >
T stan::model::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 
)
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

Template Parameters
TScalar type.
Parameters
[in]rvRow vector being indexed.
[in]idxOne single index in list.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing row vector.

Definition at line 73 of file rvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, getGoodRuns4SAM::n, and stan::model::index_uni::n_.

75  {
76  int n = idx.head_.n_;
77  math::check_range("row_vector[single] indexing", name,
78  rv.size(), n);
79  return rv(n - 1);
80  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
template<typename T , typename I >
boost::disable_if<boost::is_same<I, index_uni>, Eigen::Matrix<T, Eigen::Dynamic, 1> >::type stan::model::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 
)
inline

Return the result of indexing the specified Eigen vector with a sequence containing one multiple index, returning a vector.

Types: vec[multiple] : vec

Template Parameters
TScalar type.
IMulti-index type.
Parameters
[in]vEigen vector.
[in]idxIndex consisting of one multi-index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing vector.

Definition at line 100 of file rvalue.hpp.

References a, stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), gen_flatrecord::size, and registry_explorer::v.

102  {
103  int size = rvalue_index_size(idx.head_, v.size());
104  Eigen::Matrix<T, Eigen::Dynamic, 1> a(size);
105  for (int i = 0; i < size; ++i) {
106  int n = rvalue_at(i, idx.head_);
107  math::check_range("vector[multi] indexing", name, v.size(), n);
108  a(i) = v(n - 1);
109  }
110  return a;
111  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
const double a
template<typename T , typename I >
boost::disable_if<boost::is_same<I, index_uni>, Eigen::Matrix<T, 1, Eigen::Dynamic> >::type stan::model::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 
)
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

Template Parameters
TScalar type.
IMulti-index type.
Parameters
[in]rvEigen row vector.
[in]idxIndex consisting of one multi-index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing vector.

Definition at line 132 of file rvalue.hpp.

References a, stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), rvalue_index_size(), and gen_flatrecord::size.

134  {
135  int size = rvalue_index_size(idx.head_, rv.size());
136  Eigen::Matrix<T, 1, Eigen::Dynamic> a(size);
137  for (int i = 0; i < size; ++i) {
138  int n = rvalue_at(i, idx.head_);
139  math::check_range("row_vector[multi] indexing", name, rv.size(), n);
140  a(i) = rv(n - 1);
141  }
142  return a;
143  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
const double a
template<typename T >
Eigen::Matrix<T, 1, Eigen::Dynamic> stan::model::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 
)
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

Template Parameters
TScalar type.
Parameters
[in]aEigen matrix.
[in]idxIndex consisting of one uni-index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 160 of file rvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, getGoodRuns4SAM::n, stan::model::index_uni::n_, and T.

162  {
163  int n = idx.head_.n_;
164  math::check_range("matrix[uni] indexing", name, a.rows(), n);
165  return a.row(n - 1);
166  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
const double a
template<typename T , typename I >
boost::disable_if<boost::is_same<I, index_uni>, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> >::type stan::model::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 
)
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

Template Parameters
TScalar type.
IType of multiple index.
Parameters
[in]aMatrix to index.
[in]idxIndex consisting of single multiple index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 186 of file rvalue.hpp.

References b, stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, rvalue_at(), and rvalue_index_size().

188  {
189  int n_rows = rvalue_index_size(idx.head_, a.rows());
190  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> b(n_rows, a.cols());
191  for (int i = 0; i < n_rows; ++i) {
192  int n = rvalue_at(i, idx.head_);
193  math::check_range("matrix[multi] indexing", name, a.rows(), n);
194  b.row(i) = a.row(n - 1);
195  }
196  return b;
197  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
const double a
const hit & b
Definition: hits.cxx:21
template<typename T >
T stan::model::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 
)
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

Template Parameters
TScalar type.
Parameters
[in]aMatrix to index.
[in]idxPair of single indexes.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 214 of file rvalue.hpp.

References a, stan::math::check_range(), compare_h5_caf::idx, m, getGoodRuns4SAM::n, and T.

218  {
219  int m = idx.head_.n_;
220  int n = idx.tail_.head_.n_;
221  math::check_range("matrix[uni,uni] indexing, row", name, a.rows(), m);
222  math::check_range("matrix[uni,uni] indexing, col", name, a.cols(), n);
223  return a(m - 1, n - 1);
224  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
const double a
template<typename T , typename I >
boost::disable_if<boost::is_same<I, index_uni>, Eigen::Matrix<T, 1, Eigen::Dynamic> >::type stan::model::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 
)
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

Template Parameters
TScalar type.
IType of multiple index.
Parameters
[in]aMatrix to index.
[in]idxPair of single index and multiple index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 245 of file rvalue.hpp.

References stan::math::check_range(), compare_h5_caf::idx, m, r(), and rvalue().

248  {
249  int m = idx.head_.n_;
250  math::check_range("matrix[uni,multi] indexing, row", name, a.rows(), m);
251  Eigen::Matrix<T, 1, Eigen::Dynamic> r = a.row(m - 1);
252  return rvalue(r, idx.tail_);
253  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
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)
Definition: rvalue.hpp:376
const double a
TRandom3 r(0)
template<typename T , typename I >
boost::disable_if<boost::is_same<I, index_uni>, Eigen::Matrix<T, Eigen::Dynamic, 1> >::type stan::model::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 
)
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

Template Parameters
TScalar type.
IType of multiple index.
Parameters
[in]aMatrix to index.
[in]idxPair multiple index and single index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 274 of file rvalue.hpp.

References a, make_syst_table_plots::c, stan::math::check_range(), MECModelEnuComparisons::i, compare_h5_caf::idx, m, getGoodRuns4SAM::n, fillBadChanDBTables::rows, rvalue_at(), rvalue_index_size(), and T.

277  {
278  int rows = rvalue_index_size(idx.head_, a.rows());
279  Eigen::Matrix<T, Eigen::Dynamic, 1> c(rows);
280  for (int i = 0; i < rows; ++i) {
281  int m = rvalue_at(i, idx.head_);
282  int n = idx.tail_.head_.n_;
283  math::check_range("matrix[multi,uni] index row", name, a.rows(), m);
284  math::check_range("matrix[multi,uni] index col", name, a.cols(), n);
285  c(i) = a(m - 1, n - 1);
286  }
287  return c;
288  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
const double a
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 stan::model::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 
)
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

Template Parameters
TScalar type.
IType of multiple index.
Parameters
[in]aMatrix to index.
[in]idxPair of multiple indexes.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing matrix.

Definition at line 311 of file rvalue.hpp.

References a, make_syst_table_plots::c, stan::math::check_range(), cols, MECModelEnuComparisons::i, compare_h5_caf::idx, calib::j, m, getGoodRuns4SAM::n, fillBadChanDBTables::rows, rvalue_at(), and rvalue_index_size().

314  {
315  int rows = rvalue_index_size(idx.head_, a.rows());
316  int cols = rvalue_index_size(idx.tail_.head_, a.cols());
317  Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> c(rows, cols);
318  for (int j = 0; j < cols; ++j) {
319  for (int i = 0; i < rows; ++i) {
320  int m = rvalue_at(i, idx.head_);
321  int n = rvalue_at(j, idx.tail_.head_);
322  math::check_range("matrix[multi,multi] row index", name,
323  a.rows(), m);
324  math::check_range("matrix[multi,multi] col index", name,
325  a.cols(), n);
326  c(i, j) = a(m - 1, n - 1);
327  }
328  }
329  return c;
330  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
const double a
const int cols[3]
const double j
Definition: BetheBloch.cxx:29
template<typename T , typename L >
rvalue_return<std::vector<T>, cons_index_list<index_uni, L> >::type stan::model::rvalue ( const std::vector< T > &  c,
const cons_index_list< index_uni, L > &  idx,
const char *  name = "ANON",
int  depth = 0 
)
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]

Template Parameters
TType of list elements.
LIndex list type for indexes after first index.
Parameters
[in]cContainer of list elements.
[in]idxIndex list beginning with single index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing array.

Definition at line 351 of file rvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, getGoodRuns4SAM::n, stan::model::index_uni::n_, rvalue(), and stan::model::cons_index_list< H, T >::tail_.

352  {
353  int n = idx.head_.n_;
354  math::check_range("array[uni,...] index", name, c.size(), n);
355  return rvalue(c[n - 1], idx.tail_, name, depth + 1);
356  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
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)
Definition: rvalue.hpp:376
template<typename T , typename I , typename L >
rvalue_return<std::vector<T>, cons_index_list<I, L> >::type stan::model::rvalue ( const std::vector< T > &  c,
const cons_index_list< I, L > &  idx,
const char *  name = "ANON",
int  depth = 0 
)
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]>

Template Parameters
TType of list elements.
LIndex list type for indexes after first index.
Parameters
[in]cContainer of list elements.
[in]idxIndex list beginning with multiple index.
[in]nameString form of expression being evaluated.
[in]depthDepth of indexing dimension.
Returns
Result of indexing array.

Definition at line 376 of file rvalue.hpp.

References stan::math::check_range(), stan::model::cons_index_list< H, T >::head_, MECModelEnuComparisons::i, getGoodRuns4SAM::n, fillBadChanDBTables::result, rvalue(), rvalue_at(), rvalue_index_size(), and stan::model::cons_index_list< H, T >::tail_.

377  {
378  typename rvalue_return<std::vector<T>,
379  cons_index_list<I, L> >::type result;
380  for (int i = 0; i < rvalue_index_size(idx.head_, c.size()); ++i) {
381  int n = rvalue_at(i, idx.head_);
382  math::check_range("array[multi,...] index", name, c.size(), n);
383  result.push_back(rvalue(c[n - 1], idx.tail_, name, depth + 1));
384  }
385  return result;
386  }
const XML_Char * name
Definition: expat.h:151
void check_range(const char *function, const char *name, int max, int index, int nested_level, const char *error_msg)
Definition: check_range.hpp:28
int rvalue_index_size(const index_multi &idx, int size)
int rvalue_at(int n, const index_multi &idx)
Definition: rvalue_at.hpp:21
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)
Definition: rvalue.hpp:376
::xsd::cxx::tree::type type
Definition: Database.h:110
int stan::model::rvalue_at ( int  n,
const index_multi idx 
)
inline

Return the index in the underlying array corresponding to the specified position in the specified multi-index.

Parameters
[in]nRelative index position (from 0).
[in]idxIndex (from 1).
Returns
Underlying index position (from 1).

Definition at line 21 of file rvalue_at.hpp.

References getGoodRuns4SAM::n, and stan::model::index_multi::ns_.

Referenced by assign(), and rvalue().

21  {
22  return idx.ns_[n];
23  }
int stan::model::rvalue_at ( int  n,
const index_omni idx 
)
inline

Return the index in the underlying array corresponding to the specified position in the specified omni-index.

Parameters
[in]nRelative index position (from 0).
[in]idxIndex (from 1).
Returns
Underlying index position (from 1).

Definition at line 33 of file rvalue_at.hpp.

33  {
34  return n + 1;
35  }
int stan::model::rvalue_at ( int  n,
const index_min idx 
)
inline

Return the index in the underlying array corresponding to the specified position in the specified min-index.

All indexing begins from 1.

Parameters
[in]nRelative index position (from 0).
[in]idxIndex (from 1)
Returns
Underlying index position (from 1).

Definition at line 47 of file rvalue_at.hpp.

References stan::model::index_min::min_, and getGoodRuns4SAM::n.

47  {
48  return idx.min_ + n;
49  }
int stan::model::rvalue_at ( int  n,
const index_max idx 
)
inline

Return the index in the underlying array corresponding to the specified position in the specified max-index.

All indexing begins from 1.

Parameters
[in]nRelative index position (from 0).
[in]idxIndex (from 1).
Returns
Underlying index position (from 1).

Definition at line 61 of file rvalue_at.hpp.

61  {
62  return n + 1;
63  }
int stan::model::rvalue_at ( int  n,
const index_min_max idx 
)
inline

Return the index in the underlying array corresponding to the specified position in the specified min-max-index.

All indexing begins from 1.

Parameters
[in]nRelative index position (from 0).
[in]idxIndex (from 1).
Returns
Underlying index position (from 1).

Definition at line 75 of file rvalue_at.hpp.

References stan::model::index_min_max::min_, and getGoodRuns4SAM::n.

75  {
76  return idx.min_ + n;
77  }
int stan::model::rvalue_index_size ( const index_multi idx,
int  size 
)
inline

Return size of specified multi-index.

Parameters
[in]idxInput index (from 1).
[in]sizeSize of container (ignored here).
Returns
Size of result.

Definition at line 19 of file rvalue_index_size.hpp.

References stan::model::index_multi::ns_.

Referenced by assign(), rvalue(), and TEST().

19  {
20  return idx.ns_.size();
21  }
int stan::model::rvalue_index_size ( const index_omni idx,
int  size 
)
inline

Return size of specified omni-index for specified size of input.

Parameters
[in]idxInput index (from 1).
[in]sizeSize of container.
Returns
Size of result.

Definition at line 31 of file rvalue_index_size.hpp.

References gen_flatrecord::size.

31  {
32  return size;
33  }
int stan::model::rvalue_index_size ( const index_min idx,
int  size 
)
inline

Return size of specified min index for specified size of input.

Parameters
[in]idxInput index (from 1).
[in]sizeSize of container.
Returns
Size of result.

Definition at line 43 of file rvalue_index_size.hpp.

References stan::model::index_min::min_.

43  {
44  return size - idx.min_ + 1;
45  }
int stan::model::rvalue_index_size ( const index_max idx,
int  size 
)
inline

Return size of specified max index.

Parameters
[in]idxInput index (from 1).
[in]sizeSize of container (ignored).
Returns
Size of result.

Definition at line 54 of file rvalue_index_size.hpp.

References stan::model::index_max::max_.

54  {
55  return idx.max_;
56  }
int stan::model::rvalue_index_size ( const index_min_max idx,
int  size 
)
inline

Return size of specified min - max index. If the maximum value index is less than the minimun index, the size will be zero.

Parameters
[in]idxInput index (from 1).
[in]sizeSize of container (ignored).
Returns
Size of result.

Definition at line 66 of file rvalue_index_size.hpp.

References stan::model::index_min_max::max_, and stan::model::index_min_max::min_.

66  {
67  return (idx.max_ < idx.min_) ? 0 : (idx.max_ - idx.min_ + 1);
68  }
template<bool propto, bool jacobian_adjust_transform, class Model >
int stan::model::test_gradients ( const Model model,
std::vector< double > &  params_r,
std::vector< int > &  params_i,
double  epsilon,
double  error,
stan::callbacks::interrupt interrupt,
stan::callbacks::logger logger,
stan::callbacks::writer parameter_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).

Template Parameters
proptoTrue if calculation is up to proportion (double-only terms dropped).
jacobian_adjust_transformTrue if the log absolute Jacobian determinant of inverse parameter transforms is added to the log probability.
ModelClass of model.
Parameters
[in]modelModel.
[in]params_rReal-valued parameter vector.
[in]params_iInteger-valued parameter vector.
[in]epsilonReal-valued scalar saying how much to perturb. Reasonable value is 1e-6.
[in]errorReal-valued scalar saying how much error to allow. Reasonable value is 1e-6.
[in,out]interruptcallback to be called at every iteration
[in,out]loggerLogger for messages
[in,out]parameter_writerWriter callback for file output
Returns
number of failed gradient comparisons versus allowed error, so 0 if all gradients pass

Definition at line 41 of file test_gradients.hpp.

References epsilon, stan::math::fabs(), stan::math::grad(), submit_syst::header, stan::callbacks::logger::info(), make_syst_table_plots::line, and lem_server::msg.

48  {
49  std::stringstream msg;
50  std::vector<double> grad;
51  double lp = log_prob_grad<propto, jacobian_adjust_transform>(model,
52  params_r,
53  params_i,
54  grad,
55  &msg);
56  if (msg.str().length() > 0) {
57  logger.info(msg);
58  parameter_writer(msg.str());
59  }
60 
61  std::vector<double> grad_fd;
62  finite_diff_grad<false, true, Model>(model, interrupt, params_r, params_i,
63  grad_fd, epsilon, &msg);
64  if (msg.str().length() > 0) {
65  logger.info(msg);
66  parameter_writer(msg.str());
67  }
68 
69  int num_failed = 0;
70 
71  std::stringstream lp_msg;
72  lp_msg << " Log probability=" << lp;
73 
74  parameter_writer();
75  parameter_writer(lp_msg.str());
76  parameter_writer();
77 
78  logger.info("");
79  logger.info(lp_msg);
80  logger.info("");
81 
82  std::stringstream header;
83  header << std::setw(10) << "param idx"
84  << std::setw(16) << "value"
85  << std::setw(16) << "model"
86  << std::setw(16) << "finite diff"
87  << std::setw(16) << "error";
88 
89  parameter_writer(header.str());
90  logger.info(header);
91 
92  for (size_t k = 0; k < params_r.size(); k++) {
93  std::stringstream line;
94  line << std::setw(10) << k
95  << std::setw(16) << params_r[k]
96  << std::setw(16) << grad[k]
97  << std::setw(16) << grad_fd[k]
98  << std::setw(16) << (grad[k] - grad_fd[k]);
99  parameter_writer(line.str());
100  logger.info(line);
101  if (std::fabs(grad[k] - grad_fd[k]) > error)
102  num_failed++;
103  }
104  return num_failed;
105  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
static void grad(vari *vi)
Definition: grad.hpp:30
virtual void info(const std::string &message)
Definition: logger.hpp:47
double epsilon
const XML_Char XML_Content * model
Definition: expat.h:151