1 #ifndef STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_HPP
29 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
32 <Eigen::Matrix<T, Eigen::Dynamic, 1> >::type K) {
41 Matrix<T, Dynamic, Dynamic> L(K, K);
42 if (x.size() != (K * (K + 1)) / 2)
45 for (size_type m = 0; m < K; ++m) {
46 for (
int n = 0; n < m; ++n)
48 L(m, m) =
exp(x(i++));
49 for (size_type n = m + 1; n < K; ++n)
69 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
73 Eigen::Dynamic> >::type K,
83 if (x.size() != (K * (K + 1)) / 2)
85 Matrix<T, Dynamic, Dynamic> L(K, K);
87 for (size_type m = 0; m < K; ++m) {
88 for (size_type n = 0; n < m; ++n)
90 L(m, m) =
exp(x(i++));
91 for (size_type n = m + 1; n < K; ++n)
96 for (
int k = 0; k < K; ++k)
97 lp += (K - k + 1) *
log(L(k, k));
98 return L * L.transpose();
const double LOG_2
The natural logarithm of 2, .
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename math::index_type< Eigen::Matrix< T, Eigen::Dynamic, 1 > >::type K)
Return the symmetric, positive-definite matrix of dimensions K by K resulting from transforming the s...
fvar< T > log(const fvar< T > &x)
Eigen::Matrix< fvar< T >, R, R > multiply_lower_tri_self_transpose(const Eigen::Matrix< fvar< T >, R, C > &m)
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Primary template class for the metaprogram to compute the index type of a container.
fvar< T > exp(const fvar< T > &x)
void domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.