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

No difference between `WeightedMean` and `WeighedSum` when `normalize=false` #149

Closed ablaom closed 1 year ago

ablaom commented 2 years ago

This looks like a bug to me:

julia> y = rand(3); yhat = rand(3); w = rand(3);

julia> value(L1DistLoss(), y, yhat, AggMode.WeightedMean(w, normalize=false))
0.4515037807304132

julia> value(L1DistLoss(), y, yhat, AggMode.WeightedSum(w, normalize=false))
0.4515037807304132

I believe the problem is with weighted mean:

julia> value(L1DistLoss(), [1, 2, 3], [2, 5, -2], AggMode.WeightedMean([1, 2, 1], normalize=false))
12.0

The unweighed distances are [1, 3, 1]. So the weighted distances are [1, 6, 1], giving a weighed mean of (1 + 6 + 1) /(1 + 2 + 1) = 8/5 not 12, right?

juliohm commented 2 years ago

Definitely a bug @ablaom , sorry for only seeing this issue now. I am revamping the package for a new minor release and will try to fix this right away.

ablaom commented 1 year ago

@juliohm Friendly reminder.