Stan Math Library  2.12.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 
4 #include <boost/random/uniform_01.hpp>
5 #include <boost/random/variate_generator.hpp>
17 
18 namespace stan {
19  namespace math {
20 
21  template <class RNG>
22  inline int
23  ordered_logistic_rng(const double eta,
24  const Eigen::Matrix<double, Eigen::Dynamic, 1>& c,
25  RNG& rng) {
26  using boost::variate_generator;
27 
28  static const char* function("ordered_logistic");
29 
30  check_finite(function, "Location parameter", eta);
31  check_greater(function, "Size of cut points parameter", c.size(), 0);
32  for (int i = 1; i < c.size(); ++i) {
33  check_greater(function, "Cut points parameter", c(i), c(i - 1));
34  }
35  check_finite(function, "Cut points parameter", c(c.size()-1));
36  check_finite(function, "Cut points parameter", c(0));
37 
38  Eigen::VectorXd cut(c.rows()+1);
39  cut(0) = 1 - inv_logit(eta - c(0));
40  for (int j = 1; j < c.rows(); j++)
41  cut(j) = inv_logit(eta - c(j - 1)) - inv_logit(eta - c(j));
42  cut(c.rows()) = inv_logit(eta - c(c.rows() - 1));
43 
44  return categorical_rng(cut, rng);
45  }
46 
47  }
48 }
49 #endif
fvar< T > inv_logit(const fvar< T > &x)
Definition: inv_logit.hpp:14
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
int ordered_logistic_rng(const double eta, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &c, RNG &rng)
bool check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Return true if y is strictly greater than low.

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