You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some of the algorithms, like WeightedMean and WeightedCovMatrix, return NaN values if the first weight is zero. Example:
using WeightedOnlineStats
m =WeightedMean()
x =ones(3)
w = [0.0, 0.5, 1.0]
fit!(m, x, w)
# WeightedMean: ∑wᵢ=1.5 | value=NaN# but if we reverse the sequences everything works as expected:
m =WeightedMean()
fit!(m, reverse(x), reverse(w))
# WeightedMean: ∑wᵢ=1.5 | value=1.0
If at any point in the computation the sum of the previous weights, o.W, becomes zero, there will be NaN values because of division by zero. For the weighted mean this could be fixed by not changing mu in that case.
The text was updated successfully, but these errors were encountered:
rlefmann
changed the title
Division by zero if o.W != 0 results in NaN values
Division by zero if o.W == 0 results in NaN values
Feb 17, 2021
Good catch. Thanks for reporting. The whole thing was written without zero weights in mind.
This also poses the question if we should we increase the counter of observations when encountering a zero weight or just not do anything at all?
We also don't guard for negative weights so should we guard for zero weights? I personally lean in favor of leaving this in the responsibility of the user.
To spin this even further: Negative weights could also lead to W == 0 later on.
Some of the algorithms, like
WeightedMean
andWeightedCovMatrix
, returnNaN
values if the first weight is zero. Example:If at any point in the computation the sum of the previous weights,
o.W
, becomes zero, there will beNaN
values because of division by zero. For the weighted mean this could be fixed by not changingmu
in that case.The text was updated successfully, but these errors were encountered: