1#ifndef STAN_MATH_REV_CONSTRAINT_STOCHASTIC_COLUMN_CONSTRAIN_HPP
2#define STAN_MATH_REV_CONSTRAINT_STOCHASTIC_COLUMN_CONSTRAIN_HPP
25template <
typename T, require_rev_matrix_t<T>* =
nullptr>
29 const auto N = y.rows();
30 const auto M = y.cols();
40 const auto M = arena_y.cols();
42 auto&& x_val = arena_x.val_op();
43 auto&& x_adj = arena_x.adj_op();
45 Eigen::VectorXd x_pre_softmax_adj(x_val.rows());
46 for (Eigen::Index i = 0; i < M; ++i) {
48 x_pre_softmax_adj.noalias()
49 = -x_val.col(i) * x_adj.col(i).dot(x_val.col(i))
50 + x_val.col(i).cwiseProduct(x_adj.col(i));
74template <
typename T, require_rev_matrix_t<T>* =
nullptr>
79 const auto N = y.rows();
80 const auto M = y.cols();
93 const auto M = arena_y.cols();
95 auto&& x_val = arena_x.val_op();
96 auto&& x_adj = arena_x.adj_op();
98 const auto x_val_rows = x_val.rows();
100 Eigen::VectorXd x_pre_softmax_adj(x_val.rows());
101 for (Eigen::Index i = 0; i < M; ++i) {
103 x_pre_softmax_adj.noalias()
105 * (x_adj.col(i).dot(x_val.col(i)) + lp.adj() * x_val_rows)
106 + (x_val.col(i).cwiseProduct(x_adj.col(i)).array() + lp.adj())
void sum_to_zero_vector_backprop(T &&y_adj, const Eigen::VectorXd &z_adj)
The reverse pass backprop for the sum_to_zero_constrain on vectors.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
plain_type_t< Mat > stochastic_column_constrain(const Mat &y)
Return a column stochastic matrix.
typename plain_type< std::decay_t< T > >::type plain_type_t
typename scalar_type< T >::type scalar_type_t
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...