Automatic Differentiation
 
Loading...
Searching...
No Matches
binary_log_loss.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_BINARY_LOG_LOSS_HPP
2#define STAN_MATH_PRIM_FUN_BINARY_LOG_LOSS_HPP
3
8#include <cmath>
9
10namespace stan {
11namespace math {
12
29template <typename T, require_arithmetic_t<T>* = nullptr>
30inline T binary_log_loss(int y, const T& y_hat) {
31 using std::log;
32 return y ? -log(y_hat) : -log1m(y_hat);
33}
34
45template <typename T1, typename T2, require_any_container_t<T1, T2>* = nullptr,
46 require_not_var_matrix_t<T2>* = nullptr>
47inline auto binary_log_loss(const T1& a, const T2& b) {
48 return apply_scalar_binary(a, b, [&](const auto& c, const auto& d) {
49 return binary_log_loss(c, d);
50 });
51}
52
53} // namespace math
54} // namespace stan
55
56#endif
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
fvar< T > binary_log_loss(int y, const fvar< T > &y_hat)
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 ...
fvar< T > log1m(const fvar< T > &x)
Definition log1m.hpp:12
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...