From 8e25843bee7d705354a97bc573850f3154682cbe Mon Sep 17 00:00:00 2001 From: "Anthony Blaom, PhD" Date: Tue, 18 Aug 2020 12:29:20 +1200 Subject: [PATCH 1/6] revert CI: julia 1.5 -> julia 1.4 While waiting forhttps://github.com/JuliaStats/Distributions.jl/pull/1157 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03a498a3..afa9ea81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ env: - JULIA_NUM_THREADS=30 julia: - 1.0 - - 1.5 + - 1.4 - nightly jobs: allow_failures: From cb0f50b691a01044341376c28af67707c3d76b4f Mon Sep 17 00:00:00 2001 From: Venkateshprasad Date: Wed, 2 Sep 2020 15:58:01 +0530 Subject: [PATCH 2/6] Added Log-cosh loss --- src/MLJBase.jl | 2 +- src/measures/continuous.jl | 30 ++++++++++++++++++++++++++++++ test/measures/continuous.jl | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/MLJBase.jl b/src/MLJBase.jl index 4937a6fe..cda90d22 100644 --- a/src/MLJBase.jl +++ b/src/MLJBase.jl @@ -186,7 +186,7 @@ export orientation, reports_each_observation, spports_weights, prediction_type # measures/continuous.jl: -export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2 +export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2, log_cosh # measures/confusion_matrix.jl: export confusion_matrix, confmat diff --git a/src/measures/continuous.jl b/src/measures/continuous.jl index b40294e7..6bc372fc 100644 --- a/src/measures/continuous.jl +++ b/src/measures/continuous.jl @@ -320,3 +320,33 @@ function (m::MAPE)(ŷ::Vec{<:Real}, y::Vec{<:Real}) end return ret / count end + +struct LogCosh <: Measure end + +""" + LogCosh(ŷ, y) + +Log-Cosh loss: + +``\\text{Log-Cosh} = m^{-1}∑ᵢ log(cosh(ŷᵢ-yᵢ))`` + +where `yᵢ` is the target and `ŷᵢ` is the output, `m` is the number of indices. + +For more information, run `info(log_cosh)`. +""" +const log_cosh = LogCosh() + +metadata_measure(LogCosh; + name = "log_cosh", + target_scitype = Union{Vec{Continuous},Vec{Count}}, + prediction_type = :deterministic, + orientation = :loss, + reports_each_observation = false, + is_feature_dependent = false, + supports_weights = false, + docstring = "LogCosh; aliases: `log_cosh`.") + +function (log_cosh::LogCosh)(ŷ::Vec{<:Real}, y::Vec{<:Real}) + check_dimensions(ŷ, y) + return sum(log.(cosh.(ŷ-y))) / length(y) +end diff --git a/test/measures/continuous.jl b/test/measures/continuous.jl index c84ce01e..02b73ee4 100644 --- a/test/measures/continuous.jl +++ b/test/measures/continuous.jl @@ -12,6 +12,7 @@ rng = StableRNG(666899) @test isapprox(mean(l1(yhat, y, w)), mae(yhat, y, w)) @test isapprox(mean(l2(yhat, y)), 5) @test isapprox(mean(l2(yhat, y, w)), rms(yhat, y, w)^2) + @test isapprox(log_cosh(yhat, y), 1.3715546675) yhat = y .+ 1 @test isapprox(rmsl(yhat, y), From 2a6a324bbd37ed20cc14ef3e4ec628ede9d06519 Mon Sep 17 00:00:00 2001 From: Venkateshprasad Date: Wed, 2 Sep 2020 15:58:48 +0530 Subject: [PATCH 3/6] Revert "Merge remote-tracking branch 'origin/master'" This reverts commit 9939b924876b4fd493e261b87d8ee9c44e698d12. --- src/MLJBase.jl | 2 +- src/measures/continuous.jl | 30 ------------------------------ test/measures/continuous.jl | 1 - 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/src/MLJBase.jl b/src/MLJBase.jl index cda90d22..4937a6fe 100644 --- a/src/MLJBase.jl +++ b/src/MLJBase.jl @@ -186,7 +186,7 @@ export orientation, reports_each_observation, spports_weights, prediction_type # measures/continuous.jl: -export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2, log_cosh +export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2 # measures/confusion_matrix.jl: export confusion_matrix, confmat diff --git a/src/measures/continuous.jl b/src/measures/continuous.jl index 6bc372fc..b40294e7 100644 --- a/src/measures/continuous.jl +++ b/src/measures/continuous.jl @@ -320,33 +320,3 @@ function (m::MAPE)(ŷ::Vec{<:Real}, y::Vec{<:Real}) end return ret / count end - -struct LogCosh <: Measure end - -""" - LogCosh(ŷ, y) - -Log-Cosh loss: - -``\\text{Log-Cosh} = m^{-1}∑ᵢ log(cosh(ŷᵢ-yᵢ))`` - -where `yᵢ` is the target and `ŷᵢ` is the output, `m` is the number of indices. - -For more information, run `info(log_cosh)`. -""" -const log_cosh = LogCosh() - -metadata_measure(LogCosh; - name = "log_cosh", - target_scitype = Union{Vec{Continuous},Vec{Count}}, - prediction_type = :deterministic, - orientation = :loss, - reports_each_observation = false, - is_feature_dependent = false, - supports_weights = false, - docstring = "LogCosh; aliases: `log_cosh`.") - -function (log_cosh::LogCosh)(ŷ::Vec{<:Real}, y::Vec{<:Real}) - check_dimensions(ŷ, y) - return sum(log.(cosh.(ŷ-y))) / length(y) -end diff --git a/test/measures/continuous.jl b/test/measures/continuous.jl index 02b73ee4..c84ce01e 100644 --- a/test/measures/continuous.jl +++ b/test/measures/continuous.jl @@ -12,7 +12,6 @@ rng = StableRNG(666899) @test isapprox(mean(l1(yhat, y, w)), mae(yhat, y, w)) @test isapprox(mean(l2(yhat, y)), 5) @test isapprox(mean(l2(yhat, y, w)), rms(yhat, y, w)^2) - @test isapprox(log_cosh(yhat, y), 1.3715546675) yhat = y .+ 1 @test isapprox(rmsl(yhat, y), From 6bc54da46f6e12ddd1ad40b57af06dc4372d5f75 Mon Sep 17 00:00:00 2001 From: Venkateshprasad Date: Wed, 2 Sep 2020 16:39:07 +0530 Subject: [PATCH 4/6] Added Log cosh loss --- src/MLJBase.jl | 2 +- src/measures/continuous.jl | 30 ++++++++++++++++++++++++++++++ test/measures/continuous.jl | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/MLJBase.jl b/src/MLJBase.jl index 4937a6fe..cda90d22 100644 --- a/src/MLJBase.jl +++ b/src/MLJBase.jl @@ -186,7 +186,7 @@ export orientation, reports_each_observation, spports_weights, prediction_type # measures/continuous.jl: -export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2 +export mav, mae, mape, rms, rmsl, rmslp1, rmsp, l1, l2, log_cosh # measures/confusion_matrix.jl: export confusion_matrix, confmat diff --git a/src/measures/continuous.jl b/src/measures/continuous.jl index b40294e7..6bc372fc 100644 --- a/src/measures/continuous.jl +++ b/src/measures/continuous.jl @@ -320,3 +320,33 @@ function (m::MAPE)(ŷ::Vec{<:Real}, y::Vec{<:Real}) end return ret / count end + +struct LogCosh <: Measure end + +""" + LogCosh(ŷ, y) + +Log-Cosh loss: + +``\\text{Log-Cosh} = m^{-1}∑ᵢ log(cosh(ŷᵢ-yᵢ))`` + +where `yᵢ` is the target and `ŷᵢ` is the output, `m` is the number of indices. + +For more information, run `info(log_cosh)`. +""" +const log_cosh = LogCosh() + +metadata_measure(LogCosh; + name = "log_cosh", + target_scitype = Union{Vec{Continuous},Vec{Count}}, + prediction_type = :deterministic, + orientation = :loss, + reports_each_observation = false, + is_feature_dependent = false, + supports_weights = false, + docstring = "LogCosh; aliases: `log_cosh`.") + +function (log_cosh::LogCosh)(ŷ::Vec{<:Real}, y::Vec{<:Real}) + check_dimensions(ŷ, y) + return sum(log.(cosh.(ŷ-y))) / length(y) +end diff --git a/test/measures/continuous.jl b/test/measures/continuous.jl index c84ce01e..02b73ee4 100644 --- a/test/measures/continuous.jl +++ b/test/measures/continuous.jl @@ -12,6 +12,7 @@ rng = StableRNG(666899) @test isapprox(mean(l1(yhat, y, w)), mae(yhat, y, w)) @test isapprox(mean(l2(yhat, y)), 5) @test isapprox(mean(l2(yhat, y, w)), rms(yhat, y, w)^2) + @test isapprox(log_cosh(yhat, y), 1.3715546675) yhat = y .+ 1 @test isapprox(rmsl(yhat, y), From 84e44feedb61486b488a19348b50aac9e7429bc7 Mon Sep 17 00:00:00 2001 From: Venkateshprasad Date: Thu, 3 Sep 2020 12:25:27 +0530 Subject: [PATCH 5/6] Modified to report each observation --- src/measures/continuous.jl | 6 +++--- test/measures/continuous.jl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/measures/continuous.jl b/src/measures/continuous.jl index 6bc372fc..17d07370 100644 --- a/src/measures/continuous.jl +++ b/src/measures/continuous.jl @@ -341,12 +341,12 @@ metadata_measure(LogCosh; target_scitype = Union{Vec{Continuous},Vec{Count}}, prediction_type = :deterministic, orientation = :loss, - reports_each_observation = false, + reports_each_observation = true, is_feature_dependent = false, supports_weights = false, - docstring = "LogCosh; aliases: `log_cosh`.") + docstring = "log cosh loss; aliases: `log_cosh`.") function (log_cosh::LogCosh)(ŷ::Vec{<:Real}, y::Vec{<:Real}) check_dimensions(ŷ, y) - return sum(log.(cosh.(ŷ-y))) / length(y) + return log.(cosh.(ŷ-y)) end diff --git a/test/measures/continuous.jl b/test/measures/continuous.jl index 02b73ee4..a444f2fe 100644 --- a/test/measures/continuous.jl +++ b/test/measures/continuous.jl @@ -12,7 +12,7 @@ rng = StableRNG(666899) @test isapprox(mean(l1(yhat, y, w)), mae(yhat, y, w)) @test isapprox(mean(l2(yhat, y)), 5) @test isapprox(mean(l2(yhat, y, w)), rms(yhat, y, w)^2) - @test isapprox(log_cosh(yhat, y), 1.3715546675) + @test isapprox(mean(log_cosh(yhat, y)), 1.3715546675) yhat = y .+ 1 @test isapprox(rmsl(yhat, y), From ef07d521df486be698c328084256b7867ba83b72 Mon Sep 17 00:00:00 2001 From: Venkateshprasad Date: Thu, 3 Sep 2020 21:57:55 +0530 Subject: [PATCH 6/6] Doc-string update --- src/measures/continuous.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/measures/continuous.jl b/src/measures/continuous.jl index 17d07370..39045443 100644 --- a/src/measures/continuous.jl +++ b/src/measures/continuous.jl @@ -324,13 +324,13 @@ end struct LogCosh <: Measure end """ - LogCosh(ŷ, y) + log_cosh(ŷ, y) -Log-Cosh loss: +Log-Cosh per-observation loss: -``\\text{Log-Cosh} = m^{-1}∑ᵢ log(cosh(ŷᵢ-yᵢ))`` +``\\text{Log-Cosh Loss} = log(cosh(ŷᵢ-yᵢ))`` -where `yᵢ` is the target and `ŷᵢ` is the output, `m` is the number of indices. +where `yᵢ` is the target and `ŷᵢ` is the output. For more information, run `info(log_cosh)`. """