| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

cholesky_factor_free.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_FREE_HPP
2 #define STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_FREE_HPP
3
4 #include <stan/math/prim/mat/fun/Eigen.hpp>
5 #include <stan/math/prim/mat/err/check_cholesky_factor.hpp>
6 #include <cmath>
7 #include <stdexcept>
8
9 namespace stan {
10 namespace math {
11
21 template <typename T>
22 Eigen::Matrix<T, Eigen::Dynamic, 1>
23 cholesky_factor_free(const Eigen::Matrix
24 <T, Eigen::Dynamic, Eigen::Dynamic>& y) {
25 using std::log;
26 check_cholesky_factor("cholesky_factor_free", "y", y);
27 int M = y.rows();
28 int N = y.cols();
29 Eigen::Matrix<T, Eigen::Dynamic, 1> x((N * (N + 1)) / 2 + (M - N) * N);
30 int pos = 0;
31
32 for (int m = 0; m < N; ++m) {
33 for (int n = 0; n < m; ++n)
34 x(pos++) = y(m, n);
35 x(pos++) = log(y(m, m));
36 }
37
38 for (int m = N; m < M; ++m)
39 for (int n = 0; n < N; ++n)
40 x(pos++) = y(m, n);
41 return x;
42 }
43
44 }
45 }
46 #endif
stan::math::check_cholesky_factor
bool check_cholesky_factor(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Return true if the specified matrix is a valid Cholesky factor.
Definition: check_cholesky_factor.hpp:34
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
check_cholesky_factor.hpp
stan::math::cholesky_factor_free
Eigen::Matrix< T, Eigen::Dynamic, 1 > cholesky_factor_free(const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &y)
Return the unconstrained vector of parameters correspdonding to the specified Cholesky factor...
Definition: cholesky_factor_free.hpp:23
Eigen.hpp

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