| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

cov_matrix_free_lkj.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_FREE_LKJ_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_FREE_LKJ_HPP
3
4 #include <stan/math/prim/mat/err/check_square.hpp>
5 #include <stan/math/prim/mat/fun/Eigen.hpp>
6 #include <stan/math/prim/mat/meta/index_type.hpp>
7 #include <stan/math/prim/arr/err/check_nonzero_size.hpp>
8 #include <stan/math/prim/scal/err/domain_error.hpp>
9
10 namespace stan {
11 namespace math {
12
31 template <typename T>
32 Eigen::Matrix<T, Eigen::Dynamic, 1>
33 cov_matrix_free_lkj(
34 const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>& y) {
35 using Eigen::Array;
36 using Eigen::Dynamic;
37 using Eigen::Matrix;
38 typedef typename index_type<Matrix<T, Dynamic, Dynamic> >::type size_type;
39
40 check_nonzero_size("cov_matrix_free_lkj", "y", y);
41 check_square("cov_matrix_free_lkj", "y", y);
42 size_type k = y.rows();
43 size_type k_choose_2 = (k * (k-1)) / 2;
44 Array<T, Dynamic, 1> cpcs(k_choose_2);
45 Array<T, Dynamic, 1> sds(k);
46 bool successful = factor_cov_matrix(y, cpcs, sds);
47 if (!successful)
48 domain_error("cov_matrix_free_lkj",
49 "factor_cov_matrix failed on y", "", "");
50 Matrix<T, Dynamic, 1> x(k_choose_2 + k);
51 size_type pos = 0;
52 for (size_type i = 0; i < k_choose_2; ++i)
53 x[pos++] = cpcs[i];
54 for (size_type i = 0; i < k; ++i)
55 x[pos++] = sds[i];
56 return x;
57 }
58
59 }
60 }
61 #endif
stan
Definition: log_sum_exp.hpp:8
stan::math::check_nonzero_size
bool check_nonzero_size(const char *function, const char *name, const T_y &y)
Return true if the specified matrix/vector is of non-zero size.
Definition: check_nonzero_size.hpp:29
stan::math::size_type
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic >::Index size_type
Type for sizes and indexes in an Eigen matrix with double e.
Definition: typedefs.hpp:13
stan::math::index_type
Primary template class for the metaprogram to compute the index type of a container.
Definition: index_type.hpp:18
stan::math::factor_cov_matrix
bool factor_cov_matrix(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &Sigma, Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, Eigen::Array< T, Eigen::Dynamic, 1 > &sds)
This function is intended to make starting values, given a covariance matrix Sigma.
Definition: factor_cov_matrix.hpp:25
index_type.hpp
stan::math::cov_matrix_free_lkj
Eigen::Matrix< T, Eigen::Dynamic, 1 > cov_matrix_free_lkj(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &y)
Return the vector of unconstrained partial correlations and deviations that transform to the specifie...
Definition: cov_matrix_free_lkj.hpp:33
stan::math::domain_error
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.
Definition: domain_error.hpp:30
Eigen.hpp
domain_error.hpp
check_nonzero_size.hpp
stan::math::check_square
bool check_square(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is square.
Definition: check_square.hpp:28
check_square.hpp

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