ordered_logistic_log.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_LOG_HPP
#define STAN_MATH_PRIM_MAT_PROB_ORDERED_LOGISTIC_LOG_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/log1m.hpp>
#include <stan/math/prim/scal/fun/log1m_exp.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>
#include <stan/math/prim/scal/meta/include_summand.hpp>
#include <stan/math/prim/mat/prob/ordered_logistic_lpmf.hpp>
namespace stan {
namespace math {
template <bool propto, typename T_lambda, typename T_cut>
typename 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) {
using std::exp;
using std::log;
static const char* function("ordered_logistic");
int K = c.size() + 1;
check_bounded(function, "Random variable", y, 1, K);
check_finite(function, "Location parameter", lambda);
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));
// log(1 - inv_logit(lambda))
if (y == 1)
return -log1p_exp(lambda - c(0));
// log(inv_logit(lambda - c(K-3)));
if (y == K) {
return -log1p_exp(c(K-2) - lambda);
}
// if (2 < y < K) { ... }
// log(inv_logit(lambda - c(y-2)) - inv_logit(lambda - c(y-1)))
return log_inv_logit_diff(c(y-2) - lambda,
c(y-1) - lambda);
}
template <typename T_lambda, typename T_cut>
typename 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) {
return ordered_logistic_log<false>(y, lambda, c);
}
}
}
#endif
stan::math::check_finite
void check_finite(const char *function, const char *name, const T_y &y)
Check if y is finite.
Definition: check_finite.hpp:57
stan::math::check_bounded
void check_bounded(const char *function, const char *name, const T_y &y, const T_low &low, const T_high &high)
Check if the value is between the low and high values, inclusively.
Definition: check_bounded.hpp:90
check_positive.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
stan::math::log_inv_logit_diff
T log_inv_logit_diff(const T &alpha, const T &beta)
Definition: ordered_logistic_lpmf.hpp:25
include_summand.hpp
check_greater.hpp
check_nonnegative.hpp
check_less_or_equal.hpp
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
log1m_exp.hpp
ordered_logistic_lpmf.hpp
log1m.hpp
check_bounded.hpp
log1p_exp.hpp
constants.hpp
stan::math::log1p_exp
fvar< T > log1p_exp(const fvar< T > &x)
Definition: log1p_exp.hpp:13
check_finite.hpp
stan::math::check_greater
void check_greater(const char *function, const char *name, const T_y &y, const T_low &low)
Check if y is strictly greater than low.
Definition: check_greater.hpp:78
categorical_rng.hpp
inv_logit.hpp
check_less.hpp
stan::math::ordered_logistic_log
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 ...
Definition: ordered_logistic_log.hpp:51

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