| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

corr_matrix_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CORR_MATRIX_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CORR_MATRIX_CONSTRAIN_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/meta/index_type.hpp>
6 #include <stan/math/prim/scal/err/check_size_match.hpp>
7 #include <stan/math/prim/scal/fun/corr_constrain.hpp>
8 #include <stan/math/prim/mat/fun/read_corr_matrix.hpp>
9 #include <stdexcept>
10
11 namespace stan {
12 namespace math {
13
38 template <typename T>
39 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
40 corr_matrix_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
41 typename math::index_type
42 <Eigen::Matrix<T, Eigen::Dynamic, 1> >::type k) {
43 using Eigen::Dynamic;
44 using Eigen::Matrix;
45 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
46
47 size_type k_choose_2 = (k * (k - 1)) / 2;
48 check_size_match("cov_matrix_constrain",
49 "x.size()", x.size(),
50 "k_choose_2", k_choose_2);
51 Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
52 for (size_type i = 0; i < k_choose_2; ++i)
53 cpcs[i] = corr_constrain(x[i]);
54 return read_corr_matrix(cpcs, k);
55 }
56
76 template <typename T>
77 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
78 corr_matrix_constrain(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
79 typename math::index_type
80 <Eigen::Matrix<T, Eigen::Dynamic, 1> >::type k,
81 T& lp) {
82 using Eigen::Array;
83 using Eigen::Dynamic;
84 using Eigen::Matrix;
85 typedef typename index_type<Matrix<T, Dynamic, 1> >::type size_type;
86
87 size_type k_choose_2 = (k * (k - 1)) / 2;
88 check_size_match("cov_matrix_constrain",
89 "x.size()", x.size(),
90 "k_choose_2", k_choose_2);
91 Array<T, Dynamic, 1> cpcs(k_choose_2);
92 for (size_type i = 0; i < k_choose_2; ++i)
93 cpcs[i] = corr_constrain(x[i], lp);
94 return read_corr_matrix(cpcs, k, lp);
95 }
96
97 }
98 }
99 #endif
stan::math::corr_matrix_constrain
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > corr_matrix_constrain(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, typename math::index_type< Eigen::Matrix< T, Eigen::Dynamic, 1 > >::type k)
Return the correlation matrix of the specified dimensionality derived from the specified vector of un...
Definition: corr_matrix_constrain.hpp:40
stan::math::read_corr_matrix
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > read_corr_matrix(const Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, const size_t K)
Return the correlation matrix of the specified dimensionality corresponding to the specified canonica...
Definition: read_corr_matrix.hpp:26
check_size_match.hpp
stan
Definition: log_sum_exp.hpp:8
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
corr_constrain.hpp
index_type.hpp
stan::math::check_size_match
bool check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Return true if the provided sizes match.
Definition: check_size_match.hpp:30
Eigen.hpp
read_corr_matrix.hpp
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.