Automatic Differentiation
 
Loading...
Searching...
No Matches
ordered_probit_rng.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_PROB_ORDERED_PROBIT_RNG_HPP
2#define STAN_MATH_PRIM_PROB_ORDERED_PROBIT_RNG_HPP
3
8
9namespace stan {
10namespace math {
11
12template <class RNG>
13inline int ordered_probit_rng(double eta, const Eigen::VectorXd& c, RNG& rng) {
14 static constexpr const char* function = "ordered_probit";
15 check_finite(function, "Location parameter", eta);
16 check_greater(function, "Size of cut points parameter", c.size(), 0);
17 check_ordered(function, "Cut points vector", c);
18 check_finite(function, "Cut-points", c);
19
20 Eigen::VectorXd cut(c.rows() + 1);
21 cut(0) = 1 - Phi(eta - c(0));
22 for (int j = 1; j < c.rows(); j++) {
23 cut(j) = Phi(eta - c(j - 1)) - Phi(eta - c(j));
24 }
25 cut(c.rows()) = Phi(eta - c(c.rows() - 1));
26
27 return categorical_rng(cut, rng);
28}
29
30} // namespace math
31} // namespace stan
32#endif
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
fvar< T > Phi(const fvar< T > &x)
Definition Phi.hpp:14
int ordered_probit_rng(double eta, const Eigen::VectorXd &c, 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.
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 ...