Automatic Differentiation
 
Loading...
Searching...
No Matches
ordered_logistic_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_ORDERED_LOGISTIC_RNG_HPP
2#define STAN_MATH_PRIM_PROB_ORDERED_LOGISTIC_RNG_HPP
3
8#include <boost/random/variate_generator.hpp>
9
10namespace stan {
11namespace math {
12
13template <class RNG>
15 double eta, const Eigen::Matrix<double, Eigen::Dynamic, 1>& c, RNG& rng) {
16 using boost::variate_generator;
17 static constexpr const char* function = "ordered_logistic";
18 check_finite(function, "Location parameter", eta);
19 check_greater(function, "Size of cut points parameter", c.size(), 0);
20 check_ordered(function, "Cut points parameter", c);
21 check_finite(function, "Cut points parameter", c(c.size() - 1));
22 check_finite(function, "Cut points parameter", c(0));
23
24 Eigen::VectorXd cut(c.rows() + 1);
25 cut(0) = 1 - inv_logit(eta - c(0));
26 for (int j = 1; j < c.rows(); j++) {
27 cut(j) = inv_logit(eta - c(j - 1)) - inv_logit(eta - c(j));
28 }
29 cut(c.rows()) = inv_logit(eta - c(c.rows() - 1));
30
31 return categorical_rng(cut, rng);
32}
33
34} // namespace math
35} // namespace stan
36#endif
int ordered_logistic_rng(double eta, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &c, RNG &rng)
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
void check_ordered(const char *function, const char *name, const T_y &y)
Throw an exception if the specified vector is not sorted into strictly increasing order.
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition inv_logit.hpp:20
void check_greater(const char *function, const char *name, const T_y &y, const T_low &low, Idxs... idxs)
Throw an exception if y is not strictly greater than low.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...