Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log cosh #421

Merged
merged 12 commits into from
Sep 3, 2020
Merged

Log cosh #421

merged 12 commits into from
Sep 3, 2020

Conversation

ven-k
Copy link
Collaborator

@ven-k ven-k commented Sep 2, 2020

  • Log-Cosh gives losses similar to MSE, but isn't much affected by occasional wild predictions.
  • It can be differentiated twice
  • Keras has similar implementation.
  • It's computed by
    log_cosh = sum (log (cosh (yhat - y))) / n

@codecov-commenter
Copy link

codecov-commenter commented Sep 2, 2020

Codecov Report

Merging #421 into dev will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     JuliaAI/MLJBase.jl#421   +/-   ##
=======================================
  Coverage   81.83%   81.83%           
=======================================
  Files          38       38           
  Lines        2703     2703           
=======================================
  Hits         2212     2212           
  Misses        491      491           
Impacted Files Coverage Δ
src/MLJBase.jl 100.00% <ø> (ø)
src/measures/continuous.jl 100.00% <100.00%> (ø)
src/univariate_finite/arrays.jl 100.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7869e14...ef07d52. Read the comment docs.

function (log_cosh::LogCosh)(ŷ::Vec{<:Real}, y::Vec{<:Real})
check_dimensions(ŷ, y)
return sum(log.(cosh.(ŷ-y))) / length(y)
end
Copy link
Member

@ablaom ablaom Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion (see C below): return a vector of per-observation losses: return log.(cosh.(ŷ-y))) / length(y)

oops I mean't to drop the /length(y) as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sum is missing in this definition

Copy link
Member

@ablaom ablaom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ven-k Thanks for this contribution and for taking the time to wrap your head around the API!

C

As the loss is just the mean of a per-observation loss, can I suggest the changes above? By default this loss will be aggregated in resampling using the mean (aggregation(...) = Mean()). In this way the per-observation losses will be available, for example, to hyper-parameter optimisation strategies that use this information (some Bayesian methods).

So then the code will look basically the same as l1 which has this behaviour:

julia> l1([1,2,3], [2,3,4])
3-element Array{Int64,1}:
 1
 1
 1


Log-Cosh loss:

``\\text{Log-Cosh} = m^{-1}∑ᵢ log(cosh(ŷᵢ-yᵢ))``
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing update the docstring to reflect new behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@ablaom ablaom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OkonSamuel Yeah it is a bit confusing. Some measures that could be implemented as per-observation losses are not, eg, mae (which I guess essentially duplicates l1, which is per-observation loss).

@ven-k For the record, measures is overdue for a thorough review and migration out of MLJ https://github.com/alan-turing-institute/MLJBase.jl/issues/299 .

@ablaom ablaom merged commit 32912ae into JuliaAI:dev Sep 3, 2020
@ablaom ablaom mentioned this pull request Sep 3, 2020
@ablaom
Copy link
Member

ablaom commented Sep 4, 2020

@ven-k Now live (see above)

@ven-k
Copy link
Collaborator Author

ven-k commented Sep 4, 2020

Thanks! @ablaom and @OkonSamuel

I am following JuliaAI/StatisticalMeasures.jl#17 and #416. I am interested in StatisticalMeasures and possible visualisation package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants