Stan Math Library  2.14.0
reverse mode automatic differentiation
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 
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
void check_cholesky_factor(const char *function, const char *name, const Eigen::Matrix< T_y, Eigen::Dynamic, Eigen::Dynamic > &y)
Check if the specified matrix is a valid Cholesky factor.
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
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...

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