1#ifndef STAN_MATH_PRIM_FUN_FACTOR_U_HPP
2#define STAN_MATH_PRIM_FUN_FACTOR_U_HPP
22template <
typename T_U,
typename T_CPCs, require_eigen_t<T_U>* =
nullptr,
23 require_eigen_vector_t<T_CPCs>* =
nullptr,
24 require_vt_same<T_U, T_CPCs>* =
nullptr>
30 const Eigen::Ref<const plain_type_t<T_U>>& U_ref = U;
33 CPCs(0) =
atanh(U_ref(0, 1));
37 Eigen::Array<value_type_t<T_U>, 1, Eigen::Dynamic> temp
38 = U_ref.row(0).tail(pull);
40 CPCs.head(pull) = temp;
42 Eigen::Array<value_type_t<T_U>, Eigen::Dynamic, 1> acc(K);
44 acc.tail(pull) = 1.0 - temp.square();
45 for (
size_t i = 1; i < (K - 1); i++) {
48 temp = U_ref.row(i).tail(pull);
49 temp /=
sqrt(acc.tail(pull) / acc(i));
50 CPCs.segment(position, pull) = temp;
51 acc.tail(pull) *= 1.0 - temp.square();
53 CPCs = 0.5 * ((1.0 + CPCs) / (1.0 - CPCs)).
log();
fvar< T > atanh(const fvar< T > &x)
Return inverse hyperbolic tangent of specified value.
fvar< T > log(const fvar< T > &x)
fvar< T > sqrt(const fvar< T > &x)
void factor_U(const T_U &U, T_CPCs &&CPCs)
This function is intended to make starting values, given a unit upper-triangular matrix U such that U...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...