1 #ifndef STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__ORDERED_LOGISTIC_HPP
2 #define STAN__PROB__DISTRIBUTIONS__UNIVARIATE__DISCRETE__ORDERED_LOGISTIC_HPP
4 #include <boost/random/uniform_01.hpp>
5 #include <boost/random/variate_generator.hpp>
58 template <
bool propto,
typename T_lambda,
typename T_cut>
59 typename boost::math::tools::promote_args<T_lambda,T_cut>::type
61 const Eigen::Matrix<T_cut,Eigen::Dynamic,1>& c) {
68 static const char*
function =
"stan::prob::ordered_logistic(%1%)";
80 typename boost::math::tools::promote_args<T_lambda,T_cut>::type lp(0.0);
82 check_finite(
function, lambda,
"Location parameter", &lp);
83 check_greater(
function, c.size(), 0,
"Size of cut points parameter", &lp);
84 for (
int i = 1; i < c.size(); ++i)
85 check_greater(
function, c(i), c(i - 1),
"Cut points parameter", &lp);
87 check_finite(
function, c(c.size()-1),
"Cut points parameter", &lp);
88 check_finite(
function, c(0),
"Cut points parameter", &lp);
106 template <
typename T_lambda,
typename T_cut>
107 typename boost::math::tools::promote_args<T_lambda,T_cut>::type
109 const Eigen::Matrix<T_cut,Eigen::Dynamic,1>& c) {
110 return ordered_logistic_log<false>(y,lambda,c);
116 const Eigen::Matrix<double,Eigen::Dynamic,1>& c,
118 using boost::variate_generator;
121 static const char*
function =
"stan::prob::ordered_logistic(%1%)";
131 check_finite(
function, eta,
"Location parameter", (
double*)0);
132 check_greater(
function, c.size(), 0,
"Size of cut points parameter",
134 for (
int i = 1; i < c.size(); ++i) {
136 "Cut points parameter", (
double*)0);
139 "Cut points parameter", (
double*)0);
141 "Cut points parameter", (
double*)0);
143 Eigen::VectorXd cut(c.rows()+1);
145 for(
int j = 1; j < c.rows(); j++)
147 cut(c.rows()) =
inv_logit(eta - c(c.rows() - 1));
bool check_bounded(const char *function, const T_y &y, const T_low &low, const T_high &high, const char *name, T_result *result)
fvar< T > log1p_exp(const fvar< T > &x)
boost::math::tools::promote_args< T >::type log1p_exp(const T a)
Calculates the log of 1 plus the exponential of the specified value without overflow.
bool check_greater(const char *function, const T_y &y, const T_low &low, const char *name, T_result *result)
bool check_finite(const char *function, const T_y &y, const char *name, T_result *result)
Checks if the variable y is finite.
boost::math::tools::promote_args< T >::type inv_logit(const T a)
Returns the inverse logit function applied to the argument.
int categorical_rng(const Eigen::Matrix< double, Eigen::Dynamic, 1 > &theta, RNG &rng)
boost::math::tools::promote_args< T_lambda, T_cut >::type ordered_logistic_log(int y, const T_lambda &lambda, const Eigen::Matrix< T_cut, Eigen::Dynamic, 1 > &c)
Returns the (natural) log probability of the specified integer outcome given the continuous location ...
fvar< T > inv_logit(const fvar< T > &x)
T log_inv_logit_diff(const T &alpha, const T &beta)
bool check_nonnegative(const char *function, const T_y &y, const char *name, T_result *result)
fvar< T > log1m_exp(const fvar< T > &x)
bool check_positive(const char *function, const T_y &y, const char *name, T_result *result)
bool check_less_or_equal(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result)
boost::math::tools::promote_args< T >::type log1m_exp(const T a)
Calculates the log of 1 minus the exponential of the specified value without overflow log1m_exp(x) = ...
bool check_less(const char *function, const T_y &y, const T_high &high, const char *name, T_result *result)
int ordered_logistic_rng(const double eta, const Eigen::Matrix< double, Eigen::Dynamic, 1 > &c, RNG &rng)
fvar< T > log(const fvar< T > &x)
fvar< T > exp(const fvar< T > &x)
boost::math::tools::promote_args< T >::type log1m(T x)
Return the natural logarithm of one minus the specified value.