| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

cholesky_corr_free.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CHOLESKY_CORR_FREE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CHOLESKY_CORR_FREE_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/scal/fun/corr_constrain.hpp>
7 #include <stan/math/prim/scal/fun/square.hpp>
8 #include <stan/math/prim/scal/fun/corr_free.hpp>
9 #include <cmath>
10
11 namespace stan {
12 namespace math {
13
14 template <typename T>
15 Eigen::Matrix<T, Eigen::Dynamic, 1>
16 cholesky_corr_free(const Eigen::Matrix
17 <T, Eigen::Dynamic, Eigen::Dynamic>& x) {
18 using std::sqrt;
19 using Eigen::Matrix;
20 using Eigen::Dynamic;
21
22 check_square("cholesky_corr_free", "x", x);
23 // should validate lower-triangular, unit lengths
24
25 int K = (x.rows() * (x.rows() - 1)) / 2;
26 Matrix<T, Dynamic, 1> z(K);
27 int k = 0;
28 for (int i = 1; i < x.rows(); ++i) {
29 z(k++) = corr_free(x(i, 0));
30 double sum_sqs = square(x(i, 0));
31 for (int j = 1; j < i; ++j) {
32 z(k++) = corr_free(x(i, j) / sqrt(1.0 - sum_sqs));
33 sum_sqs += square(x(i, j));
34 }
35 }
36 return z;
37 }
38
39 }
40 }
41 #endif
stan::math::cholesky_corr_free
Eigen::Matrix< T, Eigen::Dynamic, 1 > cholesky_corr_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &x)
Definition: cholesky_corr_free.hpp:16
stan::math::sqrt
fvar< T > sqrt(const fvar< T > &x)
Definition: sqrt.hpp:14
stan::math::corr_free
T corr_free(const T y)
Return the unconstrained scalar that when transformed to a valid correlation produces the specified v...
Definition: corr_free.hpp:28
stan
Definition: log_sum_exp.hpp:8
square.hpp
stan::math::square
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:14
corr_constrain.hpp
Eigen.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
corr_free.hpp

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