From f9e31a020c6cf65425dc0b0415a241dd946bfd31 Mon Sep 17 00:00:00 2001
From: Adarsh Kumar <45385384+AdarshKumar712@users.noreply.github.com>
Date: Mon, 2 Mar 2020 13:25:23 +0530
Subject: [PATCH] Updated huber_loss with other minute changes
---
src/layers/stateless.jl | 47 +++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 25 deletions(-)
diff --git a/src/layers/stateless.jl b/src/layers/stateless.jl
index 592e2fa1..01b26a8a 100644
--- a/src/layers/stateless.jl
+++ b/src/layers/stateless.jl
@@ -16,38 +16,31 @@ mse(ŷ, y) = sum((ŷ .- y).^2) * 1 // length(y)
"""
- msle(ŷ, y;ϵ1=eps.(Float64.(ŷ)),ϵ2=eps.(Float64.(y)))
+ msle(ŷ, y; ϵ1=eps.(Float64.(ŷ)))
-Mean Squared Logarithmic Error. Returns the mean of the squared logarithmic errors `sum((log.(ŷ+ϵ1).-log.(y+ϵ2)).^2) * 1 / length(y)`.
-The ϵ1 and ϵ2 terms provide numerical stability. This error penalizes an under-predicted estimate greater than an over-predicted estimate.
+Mean Squared Logarithmic Error. Returns the mean of the squared logarithmic errors `sum((log.(ŷ+ϵ1) .- log.(y+ϵ2)).^2) * 1 / length(y)`.
+The `ϵ` term provides numerical stability. This error penalizes an under-predicted estimate greater than an over-predicted estimate.
"""
-msle(ŷ, y;ϵ1=eps.(ŷ),ϵ2=eps.(eltype(ŷ).(y))) = sum((log.(ŷ+ϵ1).-log.(y+ϵ2)).^2) * 1 // length(y)
+msle(ŷ, y; ϵ=eps.(ŷ)) = sum((log.(ŷ+ϵ).-log.(y+ϵ)).^2) * 1 // length(y)
"""
- huber_loss(ŷ, y,delta=1.0)
+ huber_loss(ŷ, y; delta=1.0)
+
+Computes the mean of the Huber loss given the prediction `ŷ` and true values `y`. By default, delta is set to 1.0.
-Computes the mean of the Huber loss. By default, delta is set to 1.0.
| 0.5*|(ŷ-y)|, for |ŷ-y|<=delta
Hubber loss = |
| delta*(|ŷ-y| - 0.5*delta), otherwise
[`Huber Loss`](https://en.wikipedia.org/wiki/Huber_loss).
"""
-function huber_loss(ŷ, y,delta=1.0)
- abs_error = abs.(ŷ.-y)
- dtype= eltype(ŷ)
- delta = dtype(delta)
- hub_loss = dtype(0)
- for i in 1:length(y)
- if (abs_error[i]<=delta)
- hub_loss+=abs_error[i]^2*dtype(0.5)
- else
- hub_loss+=delta*(abs_error[i]- dtype(0.5*delta))
- end
- end
- hub_loss*1//length(y)
+function huber_loss(ŷ, y; delta = eltype(ŷ)(1))
+ abs_error = abs.(ŷ.-y)
+ temp = abs_error.