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;
61template <
typename Vec,
typename Lp, require_eigen_vector_t<Vec>* =
nullptr,
62 require_not_st_var<Vec>* =
nullptr,
63 require_convertible_t<value_type_t<Vec>, Lp>* =
nullptr>
73 for (Eigen::Index k = 0; k < Km1; ++k) {
74 double eq_share = -
log(Km1 - k);
75 T adj_y_k = y.coeff(k) + eq_share;
77 x.coeffRef(k) = stick_len * z_k;
81 stick_len -= x.coeff(k);
83 x.coeffRef(Km1) = stick_len;
97template <
typename T, require_std_vector_t<T>* =
nullptr>
116template <
typename T,
typename Lp, require_std_vector_t<T>* =
nullptr,
117 require_convertible_t<return_type_t<T>, Lp>* =
nullptr>
141template <
bool Jacobian,
typename Vec,
typename Lp,
144 if constexpr (Jacobian) {
require_t< std::is_convertible< std::decay_t< T >, std::decay_t< S > > > require_convertible_t
Require types T and S satisfies std::is_convertible.
typename value_type< T >::type value_type_t
Helper function for accessing underlying type.
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 ...