Stan Math Library  2.20.0
reverse mode automatic differentiation
ordered_logistic_rng.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_RNG_HPP
2 #define STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_RNG_HPP
3 
5 #include <boost/random/variate_generator.hpp>
10 
11 namespace stan {
12 namespace math {
13 
14 template <class RNG>
16  double eta, const Eigen::Matrix<double, Eigen::Dynamic, 1>& c, RNG& rng) {
17  using boost::variate_generator;
18 
19  static const char* function = "ordered_logistic";
20 
21  check_finite(function, "Location parameter", eta);
22  check_greater(function, "Size of cut points parameter", c.size(), 0);
23  for (int i = 1; i < c.size(); ++i) {
24  check_greater(function, "Cut points parameter", c(i), c(i - 1));
25  }
26  check_finite(function, "Cut points parameter", c(c.size() - 1));
27  check_finite(function, "Cut points parameter", c(0));
28 
29  Eigen::VectorXd cut(c.rows() + 1);
30  cut(0) = 1 - inv_logit(eta - c(0));
31  for (int j = 1; j < c.rows(); j++)
32  cut(j) = inv_logit(eta - c(j - 1)) - inv_logit(eta - c(j));
33  cut(c.rows()) = inv_logit(eta - c(c.rows() - 1));
34 
35  return categorical_rng(cut, rng);
36 }
37 
38 } // namespace math
39 } // namespace stan
40 #endif
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
int ordered_logistic_rng(double eta, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &c, RNG &rng)
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition: inv_logit.hpp:20
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
void check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is strictly greater than low.

     [ Stan Home Page ] © 2011–2018, Stan Development Team.