All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
cholesky_factor_free.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_FREE_HPP
#define STAN_MATH_PRIM_MAT_FUN_CHOLESKY_FACTOR_FREE_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/mat/err/check_cholesky_factor.hpp>
#include <cmath>
#include <stdexcept>
namespace stan {
namespace math {
template <typename T>
Eigen::Matrix<T, Eigen::Dynamic, 1>
cholesky_factor_free(const Eigen::Matrix
<T, Eigen::Dynamic, Eigen::Dynamic>& y) {
using std::log;
if (!stan::math::check_cholesky_factor("cholesky_factor_free", "y", y))
throw std::domain_error("cholesky_factor_free: "
"y is not a Cholesky factor");
int M = y.rows();
int N = y.cols();
Eigen::Matrix<T, Eigen::Dynamic, 1> x((N * (N + 1)) / 2 + (M - N) * N);
int pos = 0;
// lower triangle of upper square
for (int m = 0; m < N; ++m) {
for (int n = 0; n < m; ++n)
x(pos++) = y(m, n);
// diagonal of upper square
x(pos++) = log(y(m, m));
}
// lower rectangle
for (int m = N; m < M; ++m)
for (int n = 0; n < N; ++n)
x(pos++) = y(m, n);
return x;
}
}
}
#endif
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
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:24
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:32
Eigen.hpp
stan::math::check_cholesky_factor
bool check_cholesky_factor(const char *function, const char *name, const Eigen::Matrix< T_y, Dynamic, Dynamic > &y)
Return true if the specified matrix is a valid Cholesky factor.
Definition: check_cholesky_factor.hpp:36

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