Stan Math Library: stan/math/prim/mat/prob/ordered_logistic_rng.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
6 #include <stan/math/prim/scal/fun/inv_logit.hpp>
7 #include <stan/math/prim/scal/fun/log1p_exp.hpp>
8 #include <stan/math/prim/scal/err/check_bounded.hpp>
9 #include <stan/math/prim/scal/err/check_finite.hpp>
10 #include <stan/math/prim/scal/err/check_greater.hpp>
11 #include <stan/math/prim/scal/err/check_less.hpp>
12 #include <stan/math/prim/scal/err/check_less_or_equal.hpp>
13 #include <stan/math/prim/scal/err/check_nonnegative.hpp>
14 #include <stan/math/prim/scal/err/check_positive.hpp>
15 #include <stan/math/prim/scal/fun/constants.hpp>
16 #include <stan/math/prim/mat/prob/categorical_rng.hpp>
17
18 namespace stan {
19
20 namespace math {
21
22 template <class RNG>
23 inline int
24 ordered_logistic_rng(const double eta,
25 const Eigen::Matrix<double, Eigen::Dynamic, 1>& c,
26 RNG& rng) {
27 using boost::variate_generator;
28 using stan::math::inv_logit;
29
30 static const char* function("stan::math::ordered_logistic");
31
32 using stan::math::check_finite;
33 using stan::math::check_positive;
34 using stan::math::check_nonnegative;
35 using stan::math::check_less;
36 using stan::math::check_less_or_equal;
37 using stan::math::check_greater;
38 using stan::math::check_bounded;
39
40 check_finite(function, "Location parameter", eta);
41 check_greater(function, "Size of cut points parameter", c.size(), 0);
42 for (int i = 1; i < c.size(); ++i) {
43 check_greater(function, "Cut points parameter", c(i), c(i - 1));
44 }
45 check_finite(function, "Cut points parameter", c(c.size()-1));
46 check_finite(function, "Cut points parameter", c(0));
47
48 Eigen::VectorXd cut(c.rows()+1);
49 cut(0) = 1 - inv_logit(eta - c(0));
50 for (int j = 1; j < c.rows(); j++)
51 cut(j) = inv_logit(eta - c(j - 1)) - inv_logit(eta - c(j));
52 cut(c.rows()) = inv_logit(eta - c(c.rows() - 1));
53
54 return stan::math::categorical_rng(cut, rng);
55 }
56 }
57 }
58
59 #endif
stan::math::check_less
bool check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is strictly less than high.
Definition: check_less.hpp:81
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::inv_logit
fvar< T > inv_logit(const fvar< T > &x)
Definition: inv_logit.hpp:15
stan::math::check_bounded
bool check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Return true if the value is between the low and high values, inclusively.
Definition: check_bounded.hpp:95
check_greater.hpp
check_nonnegative.hpp
stan::math::categorical_rng
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
Definition: categorical_rng.hpp:20
check_less_or_equal.hpp
stan::math::check_positive
bool check_positive(const char *function, const char *name, const T_y &y)
Return true if y is positive.
Definition: check_positive.hpp:68
stan::math::check_less_or_equal
bool check_less_or_equal(const char *function, const char *name, const T_y &y, const T_high &high)
Return true if y is less or equal to high.
Definition: check_less_or_equal.hpp:81
check_bounded.hpp
stan::math::check_finite
bool check_finite(const char *function, const char *name, const T_y &y)
Return true if y is finite.
Definition: check_finite.hpp:62
log1p_exp.hpp
constants.hpp
check_finite.hpp
stan::math::ordered_logistic_rng
int ordered_logistic_rng(const double eta, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &c, RNG &rng)
Definition: ordered_logistic_rng.hpp:24
stan::math::check_nonnegative
bool check_nonnegative(const char *function, const char *name, const T_y &y)
Return true if y is non-negative.
Definition: check_nonnegative.hpp:66
categorical_rng.hpp
inv_logit.hpp
check_less.hpp
stan::math::check_greater
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.
Definition: check_greater.hpp:84

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