1#ifndef STAN_MATH_PRIM_PROB_WIENER5_LPDF_HPP
2#define STAN_MATH_PRIM_PROB_WIENER5_LPDF_HPP
28template <
typename T_y,
typename T_a,
typename T_v,
typename T_w,
typename T_sv>
30 T_w&& w_value, T_sv&& sv)
noexcept {
31 const auto w = 1.0 - w_value;
32 const auto v = -v_value;
33 const auto sv_sqr =
square(sv);
34 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
35 const auto two_avw = 2.0 * a * v * w;
36 const auto two_log_a = 2.0 *
log(a);
38 / 2.0 / one_plus_svsqr_y
39 - two_log_a - 0.5 *
log(one_plus_svsqr_y));
58template <
bool Density,
GradientCalc GradW,
typename T_y,
typename T_a,
59 typename T_w_value,
typename T_err>
61 T_err&& error)
noexcept {
62 const auto two_error = 2.0 * error;
63 const auto y_asq = y /
square(a);
64 const auto two_log_a = 2 *
log(a);
65 const auto log_y_asq =
log(y) - two_log_a;
66 const auto w = 1.0 - w_value;
68 const auto n_1_factor = Density ? 2 : 3;
69 const auto n_1 = (
sqrt(n_1_factor * y_asq) + w) / 2.0;
70 auto u_eps = (Density || GradW)
74 const auto arg_mult = (Density || GradW) ? 1 : 3;
75 const auto arg = -arg_mult * y_asq * (u_eps -
sqrt(-2.0 * u_eps - 2.0));
97template <
typename T_y,
typename T_a,
typename T_w_value,
typename T_err>
100 T_err&& error)
noexcept {
101 const auto y_asq = y /
square(a);
102 const auto log_y_asq =
log(y) - 2 *
log(a);
103 static constexpr double PI_SQUARED =
pi() *
pi();
104 auto n_1 = 1.0 / (
pi() *
sqrt(y_asq));
105 const auto two_log_piy = -2.0 * (
LOG_PI + log_y_asq + error);
107 = (two_log_piy >= 0) ?
sqrt(two_log_piy / (PI_SQUARED * y_asq)) : 0.0;
126template <
GradientCalc GradW,
typename T_y,
typename T_a,
typename T_w_value,
130 T_err&& error)
noexcept {
131 const auto y_asq = y /
square(a);
132 const auto log_y_asq =
log(y) - 2 *
log(a);
133 static constexpr double PI_SQUARED =
pi() *
pi();
134 const auto n_1_factor = GradW ? 2 : 3;
135 auto n_1 =
sqrt(n_1_factor / y_asq) /
pi();
136 const auto two_error = 2.0 * error;
138 = GradW ?
log(4.0) -
log(9.0) + 2.0 *
LOG_PI + 3.0 * log_y_asq + two_error
139 :
log(3.0) -
log(5.0) +
LOG_PI + 2.0 * log_y_asq + error;
140 const auto u_eps =
fmin(-1, u_eps_arg);
141 const auto arg_mult = GradW ? 1 : (2.0 / PI_SQUARED / y_asq);
142 const auto arg = -arg_mult * (u_eps -
sqrt(-2.0 * u_eps - 2.0));
143 auto n_2 = GradW ? ((
arg > 0) ?
sqrt(
arg / y_asq) /
pi() : n_1)
166template <
bool Density,
GradientCalc GradW,
typename T_y,
typename T_a,
167 typename T_w,
typename T_nsmall,
typename T_nlarge>
169 T_nsmall&& n_terms_small_t,
170 T_nlarge&& n_terms_large_t)
noexcept {
171 const auto y_asq = y /
square(a);
172 const auto w = 1.0 - w_value;
173 const bool small_n_terms_small_t
174 = Density ? (2 * n_terms_small_t <= n_terms_large_t)
175 : (2 * n_terms_small_t < n_terms_large_t);
176 const auto scaling = small_n_terms_small_t ?
inv(2.0 * y_asq) : y_asq / 2.0;
181 if (small_n_terms_small_t) {
182 constexpr double mult = Density ? 1.0 : 3.0;
184 for (
auto k = n_terms_small_t; k >= 1; k--) {
185 const auto w_plus_2_k = w + 2.0 * k;
186 const auto w_minus_2_k = w - 2.0 * k;
187 const auto square_w_plus_2_k_minus_offset =
square(w_plus_2_k) - y_asq;
188 if (square_w_plus_2_k_minus_offset > 0) {
189 const auto summand_plus =
log(square_w_plus_2_k_minus_offset)
190 -
square(w_plus_2_k) * scaling;
192 }
else if (square_w_plus_2_k_minus_offset < 0) {
193 const auto summand_plus =
log(-square_w_plus_2_k_minus_offset)
194 -
square(w_plus_2_k) * scaling;
197 const auto square_w_minus_2_k_minus_offset
198 =
square(w_minus_2_k) - y_asq;
199 if (square_w_minus_2_k_minus_offset > 0) {
200 const auto summand_minus =
log(square_w_minus_2_k_minus_offset)
201 -
square(w_minus_2_k) * scaling;
203 }
else if (square_w_minus_2_k_minus_offset < 0) {
204 const auto summand_minus =
log(-square_w_minus_2_k_minus_offset)
205 -
square(w_minus_2_k) * scaling;
209 const auto square_w_minus_offset =
square(w) - y_asq;
210 if (square_w_minus_offset > 0) {
211 const auto new_val =
log(square_w_minus_offset) -
square(w) * scaling;
213 }
else if (square_w_minus_offset < 0) {
214 const auto new_val =
log(-square_w_minus_offset) -
square(w) * scaling;
218 for (
auto k = n_terms_small_t; k >= 1; k--) {
219 const auto w_plus_2_k = w + 2.0 * k;
220 const auto w_minus_2_k = w - 2.0 * k;
221 const auto summand_plus
222 = mult *
log(w_plus_2_k) -
square(w_plus_2_k) * scaling;
224 const auto summand_minus
225 = mult *
log(-w_minus_2_k) -
square(w_minus_2_k) * scaling;
227 fminus = summand_minus;
230 }
else if (fminus > summand_minus) {
231 fminus = fminus +
log1p_exp(summand_minus - fminus);
233 fminus = summand_minus +
log1p_exp(fminus - summand_minus);
236 const auto new_val = mult *
log(w) -
square(w) * scaling;
240 constexpr double mult = (Density ? 1 : (GradW ? 2 : 3));
241 for (
auto k = n_terms_large_t; k >= 1; k--) {
242 const auto pi_k = k *
pi();
243 const auto check = (GradW) ?
cos(pi_k * w) :
sin(pi_k * w);
246 fplus, mult *
log(k) -
square(pi_k) * scaling +
log(check));
247 }
else if ((GradW && check < 0) || !GradW) {
249 fminus, mult *
log(k) -
square(pi_k) * scaling +
log(-check));
253 current_sign = (fplus < fminus) ? -1 : 1;
255 return std::make_pair(fminus, current_sign);
257 return std::make_pair(fplus, current_sign);
258 }
else if (fplus > fminus) {
259 return std::make_pair(
log_diff_exp(fplus, fminus), current_sign);
260 }
else if (fplus < fminus) {
261 return std::make_pair(
log_diff_exp(fminus, fplus), current_sign);
287template <
bool NaturalScale =
false,
typename T_y,
typename T_a,
typename T_w,
288 typename T_v,
typename T_sv,
typename T_err>
290 const T_w& w_value,
const T_sv& sv,
291 T_err&& err =
log(1
e-12)) noexcept {
292 const auto error_term
294 const auto error = (err - error_term);
295 const auto n_terms_small_t
296 = wiener5_n_terms_small_t<GradientCalc::ON, GradientCalc::OFF>(
297 y, a, w_value, error);
298 const auto n_terms_large_t
301 auto res = wiener5_log_sum_exp<GradientCalc::ON, GradientCalc::OFF>(
302 y, a, w_value, n_terms_small_t, n_terms_large_t)
304 if (2 * n_terms_small_t <= n_terms_large_t) {
306 - 1.5 * (
log(y) - 2 *
log(a)) + res;
307 return NaturalScale ?
exp(log_density) : log_density;
309 auto log_density = error_term + res +
LOG_PI;
310 return NaturalScale ?
exp(log_density) : log_density;
334template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
335 typename T_v,
typename T_sv,
typename T_err>
337 const T_w& w_value,
const T_sv& sv,
338 T_err&& err =
log(1
e-12)) noexcept {
339 const auto two_log_a = 2 *
log(a);
340 const auto log_y_asq =
log(y) - two_log_a;
341 const auto error_term
343 const auto w = 1.0 - w_value;
344 const auto v = -v_value;
345 const auto sv_sqr =
square(sv);
346 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
347 const auto density_part_one
350 + sv_sqr * (1 - (2.0 * a * v * w)) +
square(v))
351 /
square(one_plus_svsqr_y);
352 const auto error = (err - error_term) + two_log_a;
353 const auto n_terms_small_t
354 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
355 y, a, w_value, error);
356 const auto n_terms_large_t
357 = wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
358 y, a, w_value, error);
359 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
360 y, a, w_value, n_terms_small_t, n_terms_large_t);
361 auto&& result = wiener_res.first;
362 auto&& newsign = wiener_res.second;
363 const auto error_log_density
365 const auto log_density = wiener5_density<GradientCalc::OFF>(
366 y, a, v_value, w_value, sv, err - error_log_density);
367 if (2 * n_terms_small_t < n_terms_large_t) {
368 auto ans = density_part_one - 1.5 / y
371 - 3.5 * log_y_asq + result - log_density);
372 return WrtLog ? ans *
exp(log_density) : ans;
374 auto ans = density_part_one
377 + result - log_density);
378 return WrtLog ? ans *
exp(log_density) : ans;
402template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
403 typename T_v,
typename T_sv,
typename T_err>
405 const T_w& w_value,
const T_sv& sv,
406 T_err&& err =
log(1
e-12)) noexcept {
407 const auto two_log_a = 2 *
log(a);
408 const auto error_term
410 const auto w = 1.0 - w_value;
411 const auto v = -v_value;
412 const auto sv_sqr =
square(sv);
413 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
414 const auto density_part_one
415 = (-v * w + sv_sqr *
square(w) * a) / one_plus_svsqr_y;
416 const auto error = err - error_term + 3 *
log(a) -
log(y) -
LOG_TWO;
418 const auto n_terms_small_t
419 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::OFF>(
420 y, a, w_value, error);
421 const auto n_terms_large_t
422 = wiener5_gradient_large_reaction_time_terms<GradientCalc::OFF>(
423 y, a, w_value, error);
424 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::OFF>(
425 y, a, w_value, n_terms_small_t, n_terms_large_t);
426 auto&& result = wiener_res.first;
427 auto&& newsign = wiener_res.second;
428 const auto error_log_density =
log(
429 fmax(
fabs(density_part_one + 1.0 / a),
fabs(density_part_one - 2.0 / a)));
430 const auto log_density = wiener5_density<GradientCalc::OFF>(
431 y, a, v_value, w_value, sv, err - error_log_density);
432 if (2 * n_terms_small_t < n_terms_large_t) {
434 = density_part_one + 1.0 / a
437 + 2.0 * two_log_a + error_term + result - log_density);
438 return WrtLog ? ans *
exp(log_density) : ans;
440 auto ans = density_part_one - 2.0 / a
444 return WrtLog ? ans *
exp(log_density) : ans;
468template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
469 typename T_v,
typename T_sv,
typename T_err>
471 const T_w& w_value,
const T_sv& sv,
472 T_err&& err =
log(1
e-12)) noexcept {
473 auto ans = (a * (1 - w_value) - v_value * y) / (1.0 +
square(sv) * y);
475 return ans * wiener5_density<true>(y, a, v_value, w_value, sv, err);
501template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
502 typename T_v,
typename T_sv,
typename T_err>
504 const T_w& w_value,
const T_sv& sv,
505 T_err&& err =
log(1
e-12)) noexcept {
506 const auto two_log_a = 2 *
log(a);
507 const auto log_y_asq =
log(y) - two_log_a;
508 const auto error_term
510 const auto w = 1.0 - w_value;
511 const auto v = -v_value;
512 const auto sv_sqr =
square(sv);
513 const auto one_plus_svsqr_y = 1 + sv_sqr * y;
514 const auto density_part_one
515 = (-v * a + sv_sqr *
square(a) * w) / one_plus_svsqr_y;
516 const auto error = (err - error_term);
518 const auto n_terms_small_t
519 = wiener5_n_terms_small_t<GradientCalc::OFF, GradientCalc::ON>(
520 y, a, w_value, error);
521 const auto n_terms_large_t
522 = wiener5_gradient_large_reaction_time_terms<GradientCalc::ON>(
523 y, a, w_value, error);
524 auto wiener_res = wiener5_log_sum_exp<GradientCalc::OFF, GradientCalc::ON>(
525 y, a, w_value, n_terms_small_t, n_terms_large_t);
526 auto&& result = wiener_res.first;
527 auto&& newsign = wiener_res.second;
528 const auto log_density = wiener5_density<GradientCalc::OFF>(
529 y, a, v_value, w_value, sv, err -
log(
fabs(density_part_one)));
530 if (2 * n_terms_small_t < n_terms_large_t) {
531 auto ans = -(density_part_one
533 *
exp(result - (log_density - error_term)
535 return WrtLog ? ans *
exp(log_density) : ans;
539 + newsign *
exp(result - (log_density - error_term) + 2 *
LOG_PI));
540 return WrtLog ? ans *
exp(log_density) : ans;
564template <
bool WrtLog =
false,
typename T_y,
typename T_a,
typename T_w,
565 typename T_v,
typename T_sv,
typename T_err>
567 const T_w& w_value,
const T_sv& sv,
568 T_err&& err =
log(1
e-12)) noexcept {
569 const auto one_plus_svsqr_y = 1 +
square(sv) * y;
570 const auto w = 1.0 - w_value;
571 const auto v = -v_value;
572 const auto t1 = -y / one_plus_svsqr_y;
573 const auto t2 = (
square(a * w) + 2 * a * v * w * y +
square(v * y))
574 /
square(one_plus_svsqr_y);
575 const auto ans = sv * (t1 + t2);
576 return WrtLog ? ans * wiener5_density<true>(y, a, v_value, w_value, sv, err)
590template <
size_t NestedIndex,
typename Scalar1,
typename Scalar2>
606template <
size_t NestedIndex,
typename Scalar,
typename... TArgs>
607inline void assign_err(std::tuple<TArgs...>& args_tuple, Scalar err) {
608 std::get<NestedIndex>(args_tuple) = err;
628template <
size_t ErrIndex,
size_t NestedIndex = 0,
630 typename F,
typename T_err,
typename... ArgsTupleT>
632 ArgsTupleT&&... args_tuple) {
633 auto result = functor(args_tuple...);
634 auto log_fabs_result = LogResult ?
log(
fabs(result)) :
fabs(result);
635 if (log_fabs_result < err) {
636 log_fabs_result =
is_inf(log_fabs_result) ? 0 : log_fabs_result;
637 auto err_args_tuple = std::make_tuple(args_tuple...);
639 = GradW7 ? err + log_fabs_result +
LOG_TWO : err + log_fabs_result;
640 assign_err<NestedIndex>(std::get<ErrIndex>(err_args_tuple), new_error);
642 =
math::apply([](
auto&& func,
auto&&... args) {
return func(args...); },
643 err_args_tuple, functor);
671template <
bool propto =
false,
typename T_y,
typename T_a,
typename T_t0,
672 typename T_w,
typename T_v,
typename T_sv>
673inline auto wiener_lpdf(
const T_y& y,
const T_a& a,
const T_t0& t0,
674 const T_w& w,
const T_v& v,
const T_sv& sv,
675 const double& precision_derivatives = 1
e-4) {
688 static constexpr const char* function_name =
"wiener5_lpdf";
691 "Boundary separation", a,
"Drift rate", v,
692 "A-priori bias", w,
"Nondecision time", t0,
693 "Inter-trial variability in drift rate", sv);
697 T_t0_ref t0_ref = t0;
700 T_sv_ref sv_ref = sv;
711 check_less(function_name,
"A-priori bias", w_val, 1);
714 check_finite(function_name,
"Nondecision time", t0_val);
717 check_finite(function_name,
"Inter-trial variability in drift rate", sv_val);
722 const size_t N =
max_size(y, a, t0, w, v, sv);
733 const size_t N_y_t0 =
max_size(y, t0);
735 for (
size_t i = 0; i < N_y_t0; ++i) {
736 if (y_vec[i] <= t0_vec[i]) {
737 std::stringstream msg;
738 msg <<
", but must be greater than nondecision time = " << t0_vec[i];
739 std::string msg_str(msg.str());
745 const auto log_error_density =
log(1
e-6);
746 const auto log_error_derivative =
log(precision_derivatives);
747 const double log_error_absolute_val =
log(1
e-12);
748 const T_partials_return log_error_absolute = log_error_absolute_val;
749 T_partials_return log_density = 0.0;
756 for (
size_t i = 0; i < N; i++) {
761 const auto y_value = y_vec.val(i);
762 const auto a_value = a_vec.val(i);
763 const auto t0_value = t0_vec.val(i);
764 const auto w_value = w_vec.val(i);
765 const auto v_value = v_vec.val(i);
766 const auto sv_value = sv_vec.val(i);
771 return internal::wiener5_density<GradientCalc::OFF>(args...);
773 log_error_density -
LOG_TWO, y_value - t0_value, a_value, v_value,
774 w_value, sv_value, log_error_absolute);
776 log_density += l_density;
778 const auto new_est_err = l_density + log_error_derivative - LOG_FOUR;
786 return internal::wiener5_grad_t<GradientCalc::OFF>(args...);
788 new_est_err, y_value - t0_value, a_value, v_value, w_value,
789 sv_value, log_error_absolute);
793 partials<0>(ops_partials)[i] = deriv_y;
796 partials<1>(ops_partials)[i]
800 return internal::wiener5_grad_a<GradientCalc::OFF>(args...);
802 new_est_err, y_value - t0_value, a_value, v_value, w_value,
803 sv_value, log_error_absolute);
806 partials<2>(ops_partials)[i] = -deriv_y;
809 partials<3>(ops_partials)[i]
813 return internal::wiener5_grad_w<GradientCalc::OFF>(args...);
815 new_est_err, y_value - t0_value, a_value, v_value, w_value,
816 sv_value, log_error_absolute);
819 partials<4>(ops_partials)[i]
820 = internal::wiener5_grad_v<GradientCalc::OFF>(
821 y_value - t0_value, a_value, v_value, w_value, sv_value,
822 log_error_absolute_val);
825 partials<5>(ops_partials)[i]
826 = internal::wiener5_grad_sv<GradientCalc::OFF>(
827 y_value - t0_value, a_value, v_value, w_value, sv_value,
828 log_error_absolute_val);
831 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)
size_t max_size(const T1 &x1, const Ts &... xs)
Calculate the size of the largest input.
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)
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< Condition, T >::type ref_type_if_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...