JuliaML / LossFunctions.jl

Julia package of loss functions for machine learning.
https://juliaml.github.io/LossFunctions.jl/stable
Other
148 stars 34 forks source link

LogCosh Loss #136

Closed pfarndt closed 2 years ago

pfarndt commented 3 years ago

I am missing the LogCosh loss function.

L(r) log(cosh(r))

which has certain advantages and is often used, see e.g. here. Somewhere I found this implementation, which circumvents the computation of the cosh which easily overflows:

softplus(x::Real) = ifelse(x > 0, x + log1p(exp(-x)), log1p(exp(x)))
logcosh(x::T) where T = x + softplus(-2x) - log(convert(T, 2))

Would it be possible to include this loss function as well?