| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
cov_matrix_constrain_lkj.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_LKJ_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_LKJ_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/scal/fun/corr_constrain.hpp>
6 #include <stan/math/prim/scal/fun/positive_constrain.hpp>
7 #include <stan/math/prim/mat/fun/read_cov_matrix.hpp>
8
9 namespace stan {
10
11 namespace math {
12
32 template <typename T>
33 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
34 cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
35 size_t k) {
36 size_t k_choose_2 = (k * (k - 1)) / 2;
37 Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
38 int pos = 0;
39 for (size_t i = 0; i < k_choose_2; ++i)
40 cpcs[i] = corr_constrain(x[pos++]);
41 Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
42 for (size_t i = 0; i < k; ++i)
43 sds[i] = positive_constrain(x[pos++]);
44 return read_cov_matrix(cpcs, sds);
45 }
46
71 template <typename T>
72 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
73 cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
74 size_t k,
75 T& lp) {
76 size_t k_choose_2 = (k * (k - 1)) / 2;
77 Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
78 int pos = 0;
79 for (size_t i = 0; i < k_choose_2; ++i)
80 cpcs[i] = corr_constrain(x[pos++], lp);
81 Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
82 for (size_t i = 0; i < k; ++i)
83 sds[i] = positive_constrain(x[pos++], lp);
84 return read_cov_matrix(cpcs, sds, lp);
85 }
86
87 }
88
89 }
90
91 #endif
stan::math::positive_constrain
T positive_constrain(const T x)
Return the positive value for the specified unconstrained input.
Definition: positive_constrain.hpp:22
stan::math::read_cov_matrix
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > read_cov_matrix(const Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, const Eigen::Array< T, Eigen::Dynamic, 1 > &sds, T &log_prob)
A generally worse alternative to call prior to evaluating the density of an elliptical distribution...
Definition: read_cov_matrix.hpp:23
corr_constrain.hpp
Eigen.hpp
positive_constrain.hpp
read_cov_matrix.hpp
stan::math::cov_matrix_constrain_lkj
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain_lkj(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, size_t k)
Return the covariance matrix of the specified dimensionality derived from constraining the specified ...
Definition: cov_matrix_constrain_lkj.hpp:34
stan::math::corr_constrain
T corr_constrain(const T x)
Return the result of transforming the specified scalar to have a valid correlation value between -1 a...
Definition: corr_constrain.hpp:25

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