Automatic Differentiation
 
Loading...
Searching...
No Matches
stochastic_column_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_COLUMN_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_CONSTRAINT_SIMPLEX_COLUMN_CONSTRAIN_HPP
3
11#include <cmath>
12
13namespace stan {
14namespace math {
15
25template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
26 require_not_st_var<Mat>* = nullptr>
28 auto&& y_ref = to_ref(y);
29 const Eigen::Index M = y_ref.cols();
30 plain_type_t<Mat> ret(y_ref.rows() + 1, M);
31 for (Eigen::Index i = 0; i < M; ++i) {
32 ret.col(i) = simplex_constrain(y_ref.col(i));
33 }
34 return ret;
35}
36
50template <typename Mat, require_eigen_matrix_dynamic_t<Mat>* = nullptr,
51 require_not_st_var<Mat>* = nullptr>
54 auto&& y_ref = to_ref(y);
55 const Eigen::Index M = y_ref.cols();
56 plain_type_t<Mat> ret(y_ref.rows() + 1, M);
57 for (Eigen::Index i = 0; i < M; ++i) {
58 ret.col(i) = simplex_constrain(y_ref.col(i), lp);
59 }
60 return ret;
61}
62
77template <bool Jacobian, typename Mat, require_not_std_vector_t<Mat>* = nullptr>
80 if (Jacobian) {
81 return stochastic_column_constrain(y, lp);
82 } else {
84 }
85}
86
104template <bool Jacobian, typename T, require_std_vector_t<T>* = nullptr>
105inline auto stochastic_column_constrain(const T& y, return_type_t<T>& lp) {
106 return apply_vector_unary<T>::apply(y, [&lp](auto&& v) {
107 return stochastic_column_constrain<Jacobian>(v, lp);
108 });
109}
110
111} // namespace math
112} // namespace stan
113
114#endif
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.
plain_type_t< Mat > stochastic_column_constrain(const Mat &y)
Return a column stochastic matrix.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
Definition to_ref.hpp:17
plain_type_t< Vec > simplex_constrain(const Vec &y)
Return the simplex corresponding to the specified free vector.
typename plain_type< T >::type plain_type_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...