1#ifndef STAN_MATH_PRIM_CONSTRAINT_COV_MATRIX_CONSTRAIN_LKJ_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_COV_MATRIX_CONSTRAIN_LKJ_HPP
35template <
typename T, require_eigen_col_vector_t<T>* =
nullptr>
36inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
38 size_t k_choose_2 = (k * (k - 1)) / 2;
39 decltype(
auto) x_ref =
to_ref(std::forward<T>(x));
41 "k_choose_2 + k", k_choose_2 + k);
42 auto cpcs = x_ref.head(k_choose_2);
45 internal::cholesky_corr_factor<internal::CorrOrder::column>(
63template <
typename T, require_eigen_col_vector_t<T>* =
nullptr>
64inline Eigen::Matrix<value_type_t<T>, Eigen::Dynamic, Eigen::Dynamic>
66 size_t k_choose_2 = (k * (k - 1)) / 2;
67 decltype(
auto) x_ref =
to_ref(std::forward<T>(x));
69 "k_choose_2 + k", k_choose_2 + k);
70 auto cpcs = x_ref.head(k_choose_2);
71 auto log_sds = x_ref.tail(k);
78 internal::cholesky_corr_factor<internal::CorrOrder::column>(
79 cpcs, log_cosh_cpcs, k)));
102template <
bool Jacobian,
typename T, require_not_std_vector_t<T>* =
nullptr>
104 if constexpr (Jacobian) {
131template <
bool Jacobian,
typename T, require_std_vector_t<T>* =
nullptr>
133 return apply_vector_unary<T>::apply(std::forward<T>(x), [&lp, k](
auto&& v) {
134 return cov_matrix_constrain_lkj<Jacobian>(std::forward<
decltype(v)>(v), k,
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
auto corr_matrix_log_jacobian_coefficients(Eigen::Index K)
Return a lazy expression of the coefficients c for which the log absolute Jacobian determinant of cor...
Eigen::Matrix< value_type_t< EigMat >, EigMat::RowsAtCompileTime, EigMat::RowsAtCompileTime > multiply_lower_tri_self_transpose(const EigMat &m)
auto diag_pre_multiply(const T1 &m1, const T2 &m2)
Return the product of the diagonal matrix formed from the vector or row_vector and a matrix.
auto positive_constrain(T &&x)
Return the positive value for the specified unconstrained input.
static constexpr double LOG_TWO
The natural logarithm of 2, .
Eigen::Matrix< value_type_t< T >, Eigen::Dynamic, Eigen::Dynamic > cov_matrix_constrain_lkj(T &&x, size_t k)
Return the k x k covariance matrix (diag(sds) L) (diag(sds) L)^T, with L the Cholesky factor of the c...
auto sum(const std::vector< T > &m)
Return the sum of the entries of the specified standard vector.
fvar< T > log_cosh(const fvar< T > &x)
Return the natural logarithm of the hyperbolic cosine of the argument.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
Check if the provided sizes match.
auto dot_product(const T_a &a, const T_b &b)
Returns the dot product of the specified vectors.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...