All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
ordered_logistic_rng.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_RNG_HPP
#define STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_RNG_HPP
#include <boost/random/uniform_01.hpp>
#include <boost/random/variate_generator.hpp>
#include <stan/math/prim/scal/fun/inv_logit.hpp>
#include <stan/math/prim/scal/fun/log1p_exp.hpp>
#include <stan/math/prim/scal/err/check_bounded.hpp>
#include <stan/math/prim/scal/err/check_finite.hpp>
#include <stan/math/prim/scal/err/check_greater.hpp>
#include <stan/math/prim/scal/err/check_less.hpp>
#include <stan/math/prim/scal/err/check_less_or_equal.hpp>
#include <stan/math/prim/scal/err/check_nonnegative.hpp>
#include <stan/math/prim/scal/err/check_positive.hpp>
#include <stan/math/prim/scal/fun/constants.hpp>
#include <stan/math/prim/mat/prob/categorical_rng.hpp>
namespace stan {
namespace math {
template <class RNG>
inline int
ordered_logistic_rng(const double eta,
const Eigen::Matrix<double, Eigen::Dynamic, 1>& c,
RNG& rng) {
using boost::variate_generator;
using stan::math::inv_logit;
static const char* function("stan::math::ordered_logistic");
using stan::math::check_finite;
using stan::math::check_positive;
using stan::math::check_nonnegative;
using stan::math::check_less;
using stan::math::check_less_or_equal;
using stan::math::check_greater;
using stan::math::check_bounded;
check_finite(function, "Location parameter", eta);
check_greater(function, "Size of cut points parameter", c.size(), 0);
for (int i = 1; i < c.size(); ++i) {
check_greater(function, "Cut points parameter", c(i), c(i - 1));
}
check_finite(function, "Cut points parameter", c(c.size()-1));
check_finite(function, "Cut points parameter", c(0));
Eigen::VectorXd cut(c.rows()+1);
cut(0) = 1 - inv_logit(eta - c(0));
for (int j = 1; j < c.rows(); j++)
cut(j) = inv_logit(eta - c(j - 1)) - inv_logit(eta - c(j));
cut(c.rows()) = inv_logit(eta - c(c.rows() - 1));
return stan::math::categorical_rng(cut, rng);
}
}
}
#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::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–2015, Stan Development Team.