| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 namespace math {
11
31 template <typename T>
32 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
33 cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
34 size_t k) {
35 size_t k_choose_2 = (k * (k - 1)) / 2;
36 Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
37 int pos = 0;
38 for (size_t i = 0; i < k_choose_2; ++i)
39 cpcs[i] = corr_constrain(x[pos++]);
40 Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
41 for (size_t i = 0; i < k; ++i)
42 sds[i] = positive_constrain(x[pos++]);
43 return read_cov_matrix(cpcs, sds);
44 }
45
70 template <typename T>
71 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
72 cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
73 size_t k,
74 T& lp) {
75 size_t k_choose_2 = (k * (k - 1)) / 2;
76 Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
77 int pos = 0;
78 for (size_t i = 0; i < k_choose_2; ++i)
79 cpcs[i] = corr_constrain(x[pos++], lp);
80 Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
81 for (size_t i = 0; i < k; ++i)
82 sds[i] = positive_constrain(x[pos++], lp);
83 return read_cov_matrix(cpcs, sds, lp);
84 }
85
86 }
87
88 }
89
90 #endif
stan::math::positive_constrain
T positive_constrain(const T x)
Return the positive value for the specified unconstrained input.
Definition: positive_constrain.hpp:20
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:22
stan
Definition: log_sum_exp.hpp:8
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:33
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:24

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