1#ifndef STAN_MATH_PRIM_PROB_STUDENT_T_QF_HPP
2#define STAN_MATH_PRIM_PROB_STUDENT_T_QF_HPP
29template <
typename T_p,
typename T_nu,
typename T_mu,
typename T_sigma,
30 require_all_stan_scalar_t<T_p, T_nu, T_mu, T_sigma>* =
nullptr,
31 require_all_arithmetic_t<T_p, T_nu, T_mu, T_sigma>* =
nullptr>
32inline double student_t_qf(
const T_p& p,
const T_nu& nu,
const T_mu& mu,
33 const T_sigma& sigma) {
34 static constexpr const char* function =
"student_t_qf";
37 check_bounded(function,
"Probability parameter", p, 0.0, 1.0);
41 }
else if (p == 1.0) {
43 }
else if (p == 0.5) {
47 const double p_val_flip = p < 0.5 ? p : 1.0 - p;
48 const double p_sign = p < 0.5 ? -1.0 : 1.0;
49 const auto ibeta_arg =
inv_inc_beta(0.5 * nu, 0.5, 2 * p_val_flip);
51 return mu + p_sign * sigma *
sqrt(nu) *
sqrt(-1.0 + 1.0 / ibeta_arg);
70template <
typename T_p,
typename T_nu,
typename T_mu,
typename T_sigma,
72inline auto student_t_qf(
const T_p& p,
const T_nu& nu,
const T_mu& mu,
73 const T_sigma& sigma) {
75 static constexpr const char* function =
"student_t_qf";
76 const size_t max_size_all =
max_size(p, nu, mu, sigma);
77 Eigen::Matrix<ret_scalar, -1, 1> result(max_size_all);
79 decltype(
auto) p_ref =
to_ref(p);
80 decltype(
auto) nu_ref =
to_ref(nu);
81 decltype(
auto) mu_ref =
to_ref(mu);
82 decltype(
auto) sigma_ref =
to_ref(sigma);
89 for (
size_t i = 0; i < max_size_all; ++i) {
90 result[i] =
student_t_qf(p_vec[i], nu_vec[i], mu_vec[i], sigma_vec[i]);
scalar_seq_view provides a uniform sequence-like wrapper around either a scalar or a sequence of scal...
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
require_any_t< is_vector< std::decay_t< Types > >... > require_any_vector_t
Require any of the types satisfy is_vector.
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
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.
static constexpr double NEGATIVE_INFTY
Negative infinity.
fvar< T > sqrt(const fvar< T > &x)
auto student_t_qf(const T_p &p, const T_nu &nu, const T_mu &mu, const T_sigma &sigma)
fvar< partials_return_t< T1, T2, T3 > > inv_inc_beta(const T1 &a, const T2 &b, const T3 &p)
The inverse of the normalized incomplete beta function of a, b, with probability p.
void check_positive(const char *function, const char *name, const T_y &y)
Check if y is positive.
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
static constexpr double INFTY
Positive infinity.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...