All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
cov_matrix_constrain_lkj.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_LKJ_HPP
#define STAN_MATH_PRIM_MAT_FUN_COV_MATRIX_CONSTRAIN_LKJ_HPP
#include <stan/math/prim/mat/fun/Eigen.hpp>
#include <stan/math/prim/scal/fun/corr_constrain.hpp>
#include <stan/math/prim/scal/fun/positive_constrain.hpp>
#include <stan/math/prim/mat/fun/read_cov_matrix.hpp>
namespace stan {
namespace math {
template <typename T>
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
size_t k) {
size_t k_choose_2 = (k * (k - 1)) / 2;
Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
int pos = 0;
for (size_t i = 0; i < k_choose_2; ++i)
cpcs[i] = corr_constrain(x[pos++]);
Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
for (size_t i = 0; i < k; ++i)
sds[i] = positive_constrain(x[pos++]);
return read_cov_matrix(cpcs, sds);
}
template <typename T>
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
cov_matrix_constrain_lkj(const Eigen::Matrix<T, Eigen::Dynamic, 1>& x,
size_t k,
T& lp) {
size_t k_choose_2 = (k * (k - 1)) / 2;
Eigen::Array<T, Eigen::Dynamic, 1> cpcs(k_choose_2);
int pos = 0;
for (size_t i = 0; i < k_choose_2; ++i)
cpcs[i] = corr_constrain(x[pos++], lp);
Eigen::Array<T, Eigen::Dynamic, 1> sds(k);
for (size_t i = 0; i < k; ++i)
sds[i] = positive_constrain(x[pos++], lp);
return read_cov_matrix(cpcs, sds, lp);
}
}
}
#endif
stan::math::positive_constrain
T positive_constrain(const T x)
Return the positive value for the specified unconstrained input.
Definition: positive_constrain.hpp:22
stan::math::read_cov_matrix
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > read_cov_matrix(const Eigen::Array< T, Eigen::Dynamic, 1 > &CPCs, const Eigen::Array< T, Eigen::Dynamic, 1 > &sds, T &log_prob)
A generally worse alternative to call prior to evaluating the density of an elliptical distribution...
Definition: read_cov_matrix.hpp:23
corr_constrain.hpp
Eigen.hpp
positive_constrain.hpp
read_cov_matrix.hpp
stan::math::cov_matrix_constrain_lkj
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain_lkj(const Eigen::Matrix< T, Eigen::Dynamic, 1 > &x, size_t k)
Return the covariance matrix of the specified dimensionality derived from constraining the specified ...
Definition: cov_matrix_constrain_lkj.hpp:34
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:25

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