1#ifndef STAN_MATH_PRIM_PROB_WIENER5_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_WIENER5_LPDF_HPP
29template <
typename T_y,
typename T_a,
typename T_v,
typename T_w,
typename T_sv>
31 T_w&& w_value, T_sv&& sv)
noexcept {
32 const auto w = 1.0 - w_value;
33 const auto v = -v_value;
34 const auto sv_sqr =
square(sv);
35 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
36 const auto two_avw = 2.0 * a * v * w;
37 const auto two_log_a = 2.0 *
log(a);
39 / 2.0 / one_plus_svsqr_y
40 - two_log_a - 0.5 *
log(one_plus_svsqr_y));
59template <
bool Density,
GradientCalc GradW,
typename T_y,
typename T_a,
60 typename T_w_value,
typename T_err>
62 T_err&& error)
noexcept {
63 const auto two_error = 2.0 * error;
64 const auto y_asq = y /
square(a);
65 const auto two_log_a = 2 *
log(a);
66 const auto log_y_asq =
log(y) - two_log_a;
67 const auto w = 1.0 - w_value;
69 const auto n_1_factor = Density ? 2 : 3;
70 const auto n_1 = (
sqrt(n_1_factor * y_asq) + w) / 2.0;
71 auto u_eps = (Density || GradW)
75 const auto arg_mult = (Density || GradW) ? 1 : 3;
76 const auto arg = -arg_mult * y_asq * (u_eps -
sqrt(-2.0 * u_eps - 2.0));
98template <
typename T_y,
typename T_a,
typename T_w_value,
typename T_err>
101 T_err&& error)
noexcept {
102 const auto y_asq = y /
square(a);
103 const auto log_y_asq =
log(y) - 2 *
log(a);
104 static constexpr double PI_SQUARED =
pi() *
pi();
105 auto n_1 = 1.0 / (
pi() *
sqrt(y_asq));
106 const auto two_log_piy = -2.0 * (
LOG_PI + log_y_asq + error);
108 = (two_log_piy >= 0) ?
sqrt(two_log_piy / (PI_SQUARED * y_asq)) : 0.0;
127template <
GradientCalc GradW,
typename T_y,
typename T_a,
typename T_w_value,
131 T_err&& error)
noexcept {
132 const auto y_asq = y /
square(a);
133 const auto log_y_asq =
log(y) - 2 *
log(a);
134 static constexpr double PI_SQUARED =
pi() *
pi();
135 const auto n_1_factor = GradW ? 2 : 3;
136 auto n_1 =
sqrt(n_1_factor / y_asq) /
pi();
137 const auto two_error = 2.0 * error;
139 = GradW ?
log(4.0) -
log(9.0) + 2.0 *
LOG_PI + 3.0 * log_y_asq + two_error
140 :
log(3.0) -
log(5.0) +
LOG_PI + 2.0 * log_y_asq + error;
141 const auto u_eps =
fmin(-1, u_eps_arg);
142 const auto arg_mult = GradW ? 1 : (2.0 / PI_SQUARED / y_asq);
143 const auto arg = -arg_mult * (u_eps -
sqrt(-2.0 * u_eps - 2.0));
144 auto n_2 = GradW ? ((
arg > 0) ?
sqrt(
arg / y_asq) /
pi() : n_1)
167template <
bool Density,
GradientCalc GradW,
typename T_y,
typename T_a,
168 typename T_w,
typename T_nsmall,
typename T_nlarge>
170 T_nsmall&& n_terms_small_t,
171 T_nlarge&& n_terms_large_t)
noexcept {
172 const auto y_asq = y /
square(a);
173 const auto w = 1.0 - w_value;
174 const bool small_n_terms_small_t
175 = Density ? (2 * n_terms_small_t <= n_terms_large_t)
176 : (2 * n_terms_small_t < n_terms_large_t);
177 const auto scaling = small_n_terms_small_t ?
inv(2.0 * y_asq) : y_asq / 2.0;
182 if (small_n_terms_small_t) {
183 constexpr double mult = Density ? 1.0 : 3.0;
185 for (
auto k = n_terms_small_t; k >= 1; k--) {
186 const auto w_plus_2_k = w + 2.0 * k;
187 const auto w_minus_2_k = w - 2.0 * k;
188 const auto square_w_plus_2_k_minus_offset =
square(w_plus_2_k) - y_asq;
189 if (square_w_plus_2_k_minus_offset > 0) {
190 const auto summand_plus =
log(square_w_plus_2_k_minus_offset)
191 -
square(w_plus_2_k) * scaling;
193 }
else if (square_w_plus_2_k_minus_offset < 0) {
194 const auto summand_plus =
log(-square_w_plus_2_k_minus_offset)
195 -
square(w_plus_2_k) * scaling;
198 const auto square_w_minus_2_k_minus_offset
199 =
square(w_minus_2_k) - y_asq;
200 if (square_w_minus_2_k_minus_offset > 0) {
201 const auto summand_minus =
log(square_w_minus_2_k_minus_offset)
202 -
square(w_minus_2_k) * scaling;
204 }
else if (square_w_minus_2_k_minus_offset < 0) {
205 const auto summand_minus =
log(-square_w_minus_2_k_minus_offset)
206 -
square(w_minus_2_k) * scaling;
210 const auto square_w_minus_offset =
square(w) - y_asq;
211 if (square_w_minus_offset > 0) {
212 const auto new_val =
log(square_w_minus_offset) -
square(w) * scaling;
214 }
else if (square_w_minus_offset < 0) {
215 const auto new_val =
log(-square_w_minus_offset) -
square(w) * scaling;
219 for (
auto k = n_terms_small_t; k >= 1; k--) {
220 const auto w_plus_2_k = w + 2.0 * k;
221 const auto w_minus_2_k = w - 2.0 * k;
222 const auto summand_plus
223 = mult *
log(w_plus_2_k) -
square(w_plus_2_k) * scaling;
225 const auto summand_minus
226 = mult *
log(-w_minus_2_k) -
square(w_minus_2_k) * scaling;
228 fminus = summand_minus;
231 }
else if (fminus > summand_minus) {
232 fminus = fminus +
log1p_exp(summand_minus - fminus);
234 fminus = summand_minus +
log1p_exp(fminus - summand_minus);
237 const auto new_val = mult *
log(w) -
square(w) * scaling;
241 constexpr double mult = (Density ? 1 : (GradW ? 2 : 3));
242 for (
auto k = n_terms_large_t; k >= 1; k--) {
243 const auto pi_k = k *
pi();
244 const auto check = (GradW) ?
cos(pi_k * w) :
sin(pi_k * w);
247 fplus, mult *
log(k) -
square(pi_k) * scaling +
log(check));
248 }
else if ((GradW && check < 0) || !GradW) {
250 fminus, mult *
log(k) -
square(pi_k) * scaling +
log(-check));
254 current_sign = (fplus < fminus) ? -1 : 1;
256 return std::make_pair(fminus, current_sign);
258 return std::make_pair(fplus, current_sign);
259 }
else if (fplus > fminus) {
260 return std::make_pair(
log_diff_exp(fplus, fminus), current_sign);
261 }
else if (fplus < fminus) {
262 return std::make_pair(
log_diff_exp(fminus, fplus), current_sign);
288template <
bool NaturalScale =
false,
typename T_y,
typename T_a,
typename T_w,
289 typename T_v,
typename T_sv,
typename T_err>
291 const T_w& w_value,
const T_sv& sv,
292 T_err&& err =
log(1
e-12)) noexcept {
293 const auto error_term
295 const auto error = (err - error_term);
296 const auto n_terms_small_t
297 = wiener5_n_terms_small_t<GradientCalc::ON, GradientCalc::OFF>(
298 y, a, w_value, error);
299 const auto n_terms_large_t
302 auto res = wiener5_log_sum_exp<GradientCalc::ON, GradientCalc::OFF>(
303 y, a, w_value, n_terms_small_t, n_terms_large_t)
305 if (2 * n_terms_small_t <= n_terms_large_t) {
307 - 1.5 * (
log(y) - 2 *
log(a)) + res;
308 return NaturalScale ?
exp(log_density) : log_density;
310 auto log_density = error_term + res +
LOG_PI;
311 return NaturalScale ?
exp(log_density) : log_density;
335template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
336 typename T_v,
typename T_sv,
typename T_err>
338 const T_w& w_value,
const T_sv& sv,
339 T_err&& err =
log(1
e-12)) noexcept {
340 const auto two_log_a = 2 *
log(a);
341 const auto log_y_asq =
log(y) - two_log_a;
342 const auto error_term
344 const auto w = 1.0 - w_value;
345 const auto v = -v_value;
346 const auto sv_sqr =
square(sv);
347 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
348 const auto density_part_one
351 + sv_sqr * (1 - (2.0 * a * v * w)) +
square(v))
352 /
square(one_plus_svsqr_y);
353 const auto error = (err - error_term) + two_log_a;
354 const auto n_terms_small_t
355 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
356 y, a, w_value, error);
357 const auto n_terms_large_t
358 = wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
359 y, a, w_value, error);
360 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
361 y, a, w_value, n_terms_small_t, n_terms_large_t);
362 auto&& result = wiener_res.first;
363 auto&& newsign = wiener_res.second;
364 const auto error_log_density
366 const auto log_density = wiener5_density<GradientCalc::OFF>(
367 y, a, v_value, w_value, sv, err - error_log_density);
368 if (2 * n_terms_small_t < n_terms_large_t) {
369 auto ans = density_part_one - 1.5 / y
372 - 3.5 * log_y_asq + result - log_density);
373 return WrtLog ? ans *
exp(log_density) : ans;
375 auto ans = density_part_one
378 + result - log_density);
379 return WrtLog ? ans *
exp(log_density) : ans;
403template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
404 typename T_v,
typename T_sv,
typename T_err>
406 const T_w& w_value,
const T_sv& sv,
407 T_err&& err =
log(1
e-12)) noexcept {
408 const auto two_log_a = 2 *
log(a);
409 const auto error_term
411 const auto w = 1.0 - w_value;
412 const auto v = -v_value;
413 const auto sv_sqr =
square(sv);
414 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
415 const auto density_part_one
416 = (-v * w + sv_sqr *
square(w) * a) / one_plus_svsqr_y;
417 const auto error = err - error_term + 3 *
log(a) -
log(y) -
LOG_TWO;
419 const auto n_terms_small_t
420 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
421 y, a, w_value, error);
422 const auto n_terms_large_t
423 = wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
424 y, a, w_value, error);
425 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
426 y, a, w_value, n_terms_small_t, n_terms_large_t);
427 auto&& result = wiener_res.first;
428 auto&& newsign = wiener_res.second;
429 const auto error_log_density =
log(
430 fmax(
fabs(density_part_one + 1.0 / a),
fabs(density_part_one - 2.0 / a)));
431 const auto log_density = wiener5_density<GradientCalc::OFF>(
432 y, a, v_value, w_value, sv, err - error_log_density);
433 if (2 * n_terms_small_t < n_terms_large_t) {
435 = density_part_one + 1.0 / a
438 + 2.0 * two_log_a + error_term + result - log_density);
439 return WrtLog ? ans *
exp(log_density) : ans;
441 auto ans = density_part_one - 2.0 / a
445 return WrtLog ? ans *
exp(log_density) : ans;
469template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
470 typename T_v,
typename T_sv,
typename T_err>
472 const T_w& w_value,
const T_sv& sv,
473 T_err&& err =
log(1
e-12)) noexcept {
474 auto ans = (a * (1 - w_value) - v_value * y) / (1.0 +
square(sv) * y);
476 return ans * wiener5_density<true>(y, a, v_value, w_value, sv, err);
502template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
503 typename T_v,
typename T_sv,
typename T_err>
505 const T_w& w_value,
const T_sv& sv,
506 T_err&& err =
log(1
e-12)) noexcept {
507 const auto two_log_a = 2 *
log(a);
508 const auto log_y_asq =
log(y) - two_log_a;
509 const auto error_term
511 const auto w = 1.0 - w_value;
512 const auto v = -v_value;
513 const auto sv_sqr =
square(sv);
514 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
515 const auto density_part_one
516 = (-v * a + sv_sqr *
square(a) * w) / one_plus_svsqr_y;
517 const auto error = (err - error_term);
519 const auto n_terms_small_t
520 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::ON>(
521 y, a, w_value, error);
522 const auto n_terms_large_t
523 = wiener5_gradient_large_reaction_time_terms<GradientCalc::ON>(
524 y, a, w_value, error);
525 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::ON>(
526 y, a, w_value, n_terms_small_t, n_terms_large_t);
527 auto&& result = wiener_res.first;
528 auto&& newsign = wiener_res.second;
529 const auto log_density = wiener5_density<GradientCalc::OFF>(
530 y, a, v_value, w_value, sv, err -
log(
fabs(density_part_one)));
531 if (2 * n_terms_small_t < n_terms_large_t) {
532 auto ans = -(density_part_one
534 *
exp(result - (log_density - error_term)
536 return WrtLog ? ans *
exp(log_density) : ans;
540 + newsign *
exp(result - (log_density - error_term) + 2 *
LOG_PI));
541 return WrtLog ? ans *
exp(log_density) : ans;
565template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
566 typename T_v,
typename T_sv,
typename T_err>
568 const T_w& w_value,
const T_sv& sv,
569 T_err&& err =
log(1
e-12)) noexcept {
570 const auto one_plus_svsqr_y = 1 +
square(sv) * y;
571 const auto w = 1.0 - w_value;
572 const auto v = -v_value;
573 const auto t1 = -y / one_plus_svsqr_y;
574 const auto t2 = (
square(a * w) + 2 * a * v * w * y +
square(v * y))
575 /
square(one_plus_svsqr_y);
576 const auto ans = sv * (t1 + t2);
577 return WrtLog ? ans * wiener5_density<true>(y, a, v_value, w_value, sv, err)
591template <
size_t NestedIndex,
typename Scalar1,
typename Scalar2>
607template <
size_t NestedIndex,
typename Scalar,
typename... TArgs>
608inline void assign_err(std::tuple<TArgs...>& args_tuple, Scalar err) {
609 std::get<NestedIndex>(args_tuple) = err;
629template <
size_t ErrIndex,
size_t NestedIndex = 0,
631 typename F,
typename T_err,
typename... ArgsTupleT>
633 ArgsTupleT&&... args_tuple) {
634 auto result = functor(args_tuple...);
635 auto log_fabs_result = LogResult ?
log(
fabs(result)) :
fabs(result);
636 if (log_fabs_result < err) {
637 log_fabs_result =
is_inf(log_fabs_result) ? 0 : log_fabs_result;
638 auto err_args_tuple = std::make_tuple(args_tuple...);
640 = GradW7 ? err + log_fabs_result +
LOG_TWO : err + log_fabs_result;
641 assign_err<NestedIndex>(std::get<ErrIndex>(err_args_tuple), new_error);
643 =
math::apply([](
auto&& func,
auto&&... args) {
return func(args...); },
644 err_args_tuple, functor);
672template <
bool propto =
false,
typename T_y,
typename T_a,
typename T_t0,
673 typename T_w,
typename T_v,
typename T_sv>
674inline auto wiener_lpdf(
const T_y& y,
const T_a& a,
const T_t0& t0,
675 const T_w& w,
const T_v& v,
const T_sv& sv,
676 const double& precision_derivatives = 1
e-4) {
689 static constexpr const char* function_name =
"wiener5_lpdf";
692 "Boundary separation", a,
"Drift rate", v,
693 "A-priori bias", w,
"Nondecision time", t0,
694 "Inter-trial variability in drift rate", sv);
698 T_t0_ref t0_ref = t0;
701 T_sv_ref sv_ref = sv;
712 check_less(function_name,
"A-priori bias", w_val, 1);
715 check_finite(function_name,
"Nondecision time", t0_val);
718 check_finite(function_name,
"Inter-trial variability in drift rate", sv_val);
723 const size_t N =
max_size(y, a, t0, w, v, sv);
734 const size_t N_y_t0 =
max_size(y, t0);
736 for (
size_t i = 0; i < N_y_t0; ++i) {
737 if (y_vec[i] <= t0_vec[i]) {
738 std::stringstream msg;
739 msg <<
", but must be greater than nondecision time = " << t0_vec[i];
740 std::string msg_str(msg.str());
746 const auto log_error_density =
log(1
e-6);
747 const auto log_error_derivative =
log(precision_derivatives);
748 const double log_error_absolute_val =
log(1
e-12);
749 const T_partials_return log_error_absolute = log_error_absolute_val;
750 T_partials_return log_density = 0.0;
757 for (
size_t i = 0; i < N; i++) {
762 const auto y_value = y_vec.val(i);
763 const auto a_value = a_vec.val(i);
764 const auto t0_value = t0_vec.val(i);
765 const auto w_value = w_vec.val(i);
766 const auto v_value = v_vec.val(i);
767 const auto sv_value = sv_vec.val(i);
772 return internal::wiener5_density<GradientCalc::OFF>(args...);
774 log_error_density -
LOG_TWO, y_value - t0_value, a_value, v_value,
775 w_value, sv_value, log_error_absolute);
777 log_density += l_density;
779 const auto new_est_err = l_density + log_error_derivative - LOG_FOUR;
787 return internal::wiener5_grad_t<GradientCalc::OFF>(args...);
789 new_est_err, y_value - t0_value, a_value, v_value, w_value,
790 sv_value, log_error_absolute);
794 partials<0>(ops_partials)[i] = deriv_y;
797 partials<1>(ops_partials)[i]
801 return internal::wiener5_grad_a<GradientCalc::OFF>(args...);
803 new_est_err, y_value - t0_value, a_value, v_value, w_value,
804 sv_value, log_error_absolute);
807 partials<2>(ops_partials)[i] = -deriv_y;
810 partials<3>(ops_partials)[i]
814 return internal::wiener5_grad_w<GradientCalc::OFF>(args...);
816 new_est_err, y_value - t0_value, a_value, v_value, w_value,
817 sv_value, log_error_absolute);
820 partials<4>(ops_partials)[i]
821 = internal::wiener5_grad_v<GradientCalc::OFF>(
822 y_value - t0_value, a_value, v_value, w_value, sv_value,
823 log_error_absolute_val);
826 partials<5>(ops_partials)[i]
827 = internal::wiener5_grad_sv<GradientCalc::OFF>(
828 y_value - t0_value, a_value, v_value, w_value, sv_value,
829 log_error_absolute_val);
832 return ops_partials.build(log_density);
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.
auto wiener5_grad_v(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the derivative of the wiener5 density w.r.t.
auto wiener5_density_large_reaction_time_terms(T_y &&y, T_a &&a, T_w_value &&w_value, T_err &&error) noexcept
Calculate the 'n_terms_large_t' term for a wiener5 density.
auto wiener5_grad_a(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the derivative of the wiener5 density w.r.t.
auto wiener5_grad_sv(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the derivative of the wiener5 density w.r.t.
void assign_err(Scalar1 arg, Scalar2 err)
Utility function for replacing a value with a specified error value.
auto wiener5_n_terms_small_t(T_y &&y, T_a &&a, T_w_value &&w_value, T_err &&error) noexcept
Calculate the 'n_terms_small_t' term for a wiener5 density or gradient.
auto wiener5_gradient_large_reaction_time_terms(T_y &&y, T_a &&a, T_w_value &&w_value, T_err &&error) noexcept
Calculate the 'n_terms_large_t' term for a wiener5 gradient.
auto wiener5_grad_t(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the derivative of the wiener5 density w.r.t.
auto wiener5_density(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the wiener5 density.
auto wiener5_grad_w(const T_y &y, const T_a &a, const T_v &v_value, const T_w &w_value, const T_sv &sv, T_err &&err=log(1e-12)) noexcept
Calculate the derivative of the wiener5 density w.r.t.
auto estimate_with_err_check(F &&functor, T_err &&err, ArgsTupleT &&... args_tuple)
Utility function for estimating a function with a given set of arguments, checking the result against...
auto wiener5_compute_error_term(T_y &&y, T_a &&a, T_v &&v_value, T_w &&w_value, T_sv &&sv) noexcept
Calculate the 'error_term' term for a wiener5 density or gradient.
auto wiener5_log_sum_exp(T_y &&y, T_a &&a, T_w &&w_value, T_nsmall &&n_terms_small_t, T_nlarge &&n_terms_large_t) noexcept
Calculate the 'result' term and its sign for a wiener5 density or gradient.
fvar< T > sin(const fvar< T > &x)
void check_nonnegative(const char *function, const char *name, const T_y &y)
Check if y is non-negative.
bool size_zero(const T &x)
Returns 1 if input is of length 0, returns 0 otherwise.
fvar< T > fmin(const fvar< T > &x1, const fvar< T > &x2)
static constexpr double e()
Return the base of the natural logarithm.
fvar< T > arg(const std::complex< fvar< T > > &z)
Return the phase angle of the complex argument.
T eval(T &&arg)
Inputs which have a plain_type equal to the own time are forwarded unmodified (for Eigen expressions ...
fvar< T > log(const fvar< T > &x)
static constexpr double NEGATIVE_INFTY
Negative infinity.
void throw_domain_error(const char *function, const char *name, const T &y, const char *msg1, const char *msg2)
Throw a domain error with a consistently formatted message.
static constexpr double LOG_TWO
The natural logarithm of 2, .
fvar< T > log1p_exp(const fvar< T > &x)
auto as_value_column_array_or_scalar(T &&a)
Extract the value from an object and for eigen vectors and std::vectors convert to an eigen column ar...
void check_consistent_sizes(const char *)
Trivial no input case, this function is a no-op.
fvar< T > sqrt(const fvar< T > &x)
static constexpr double LOG_SQRT_PI
The natural logarithm of the square root of , .
ref_type_t< T && > to_ref(T &&a)
This evaluates expensive Eigen expressions.
static constexpr double LOG_PI
The natural logarithm of , .
void check_finite(const char *function, const char *name, const T_y &y)
Return true if all values in y are finite.
fvar< T > fmax(const fvar< T > &x1, const fvar< T > &x2)
Return the greater of the two specified arguments.
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > cos(const fvar< T > &x)
static constexpr double pi()
Return the value of pi.
auto wiener_lpdf(const T_y &y, const T_a &a, const T_t0 &t0, const T_w &w, const T_v &v, const T_sv &sv, const double &precision_derivatives=1e-4)
Log-density function for the 5-parameter Wiener density.
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high, Idxs... idxs)
Throw an exception if y is not strictly less than high.
fvar< T > ceil(const fvar< T > &x)
int64_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
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.
fvar< T > inv(const fvar< T > &x)
auto make_partials_propagator(Ops &&... ops)
Construct an partials_propagator.
constexpr decltype(auto) apply(F &&f, Tuple &&t, PreArgs &&... pre_args)
void check_positive_finite(const char *function, const char *name, const T_y &y)
Check if y is positive and finite.
fvar< T > fabs(const fvar< T > &x)
fvar< T > square(const fvar< T > &x)
fvar< T > log_sum_exp(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > exp(const fvar< T > &x)
typename ref_type_if< true, T >::type ref_type_t
typename partials_return_type< Args... >::type partials_return_t
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Extends std::true_type when instantiated with zero or more template parameters, all of which extend t...
Template metaprogram to calculate whether a summand needs to be included in a proportional (log) prob...