Automatic Differentiation
 
Loading...
Searching...
No Matches
log_inv_logit_diff.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_LOG_INV_LOGIT_DIFF_HPP
2#define STAN_MATH_PRIM_FUN_LOG_INV_LOGIT_DIFF_HPP
3
9
10namespace stan {
11namespace math {
12
36template <typename T1, typename T2, require_all_arithmetic_t<T1, T2>* = nullptr>
37inline return_type_t<T1, T2> log_inv_logit_diff(const T1& x, const T2& y) {
38 if (is_inf(x) && x >= 0) {
39 return -log1p_exp(y);
40 }
41 return x - log1p_exp(x) + log1m_exp(y - x) - log1p_exp(y);
42}
43
54template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr>
55inline auto log_inv_logit_diff(const T1& a, const T2& b) {
56 return apply_scalar_binary(a, b, [&](const auto& c, const auto& d) {
57 return log_inv_logit_diff(c, d);
58 });
59}
60
61} // namespace math
62} // namespace stan
63
64#endif
typename return_type< Ts... >::type return_type_t
Convenience type for the return type of the specified template parameters.
fvar< T > log1m_exp(const fvar< T > &x)
Return the natural logarithm of one minus the exponentiation of the specified argument.
Definition log1m_exp.hpp:23
fvar< T > log_inv_logit_diff(const fvar< T > &x, const fvar< T > &y)
Returns fvar with the natural logarithm of the difference of the inverse logits of the specified argu...
fvar< T > log1p_exp(const fvar< T > &x)
Definition log1p_exp.hpp:13
int is_inf(const fvar< T > &x)
Returns 1 if the input's value is infinite and 0 otherwise.
Definition is_inf.hpp:21
auto apply_scalar_binary(const T1 &x, const T2 &y, const F &f)
Base template function for vectorization of binary scalar functions defined by applying a functor to ...
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9