Skip to content

Division by zero if o.W == 0 results in NaN values #42

Open
@rlefmann

Description

@rlefmann

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions