1#ifndef STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_CONSTRAIN_HPP
27template <
typename Vec, require_eigen_vector_t<Vec>* =
nullptr,
28 require_not_st_var<Vec>* =
nullptr>
37 for (Eigen::Index k = 0; k < Km1; ++k) {
39 x.coeffRef(k) = stick_len * z_k;
40 stick_len -= x.coeff(k);
42 x.coeffRef(Km1) = stick_len;
59template <
typename Vec, require_eigen_vector_t<Vec>* =
nullptr,
60 require_not_st_var<Vec>* =
nullptr>
71 for (Eigen::Index k = 0; k < Km1; ++k) {
72 double eq_share = -
log(Km1 - k);
73 T adj_y_k = y.coeff(k) + eq_share;
75 x.coeffRef(k) = stick_len * z_k;
79 stick_len -= x.coeff(k);
81 x.coeffRef(Km1) = stick_len;
101template <
bool Jacobian,
typename Vec, require_not_std_vector_t<Vec>* =
nullptr>
127template <
bool Jacobian,
typename T, require_std_vector_t<T>* =
nullptr>
130 y, [&lp](
auto&& v) {
return simplex_constrain<Jacobian>(v, lp); });
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
fvar< T > log(const fvar< T > &x)
fvar< T > log1p_exp(const fvar< T > &x)
plain_type_t< Vec > simplex_constrain(const Vec &y)
Return the simplex corresponding to the specified free vector.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...