joshday / OnlineStats.jl

⚡ Single-pass algorithms for statistics
https://joshday.github.io/OnlineStats.jl/latest/
MIT License
831 stars 62 forks source link

Suggestions for OnlineStats v2 #285

Closed adknudson closed 3 months ago

adknudson commented 5 months ago

In the event that a version 2 is ever released, I think it would be good to have place to discuss potential design changes. Please close this issue if it's inappropriate or not worth discussing :)

To start, I think Sum(Integer) should only accept integer types. The fact that it can accept a real value and round to an integer can cause unexpected behavior, and requires extra code in OnlineStatsBase to handle that condition:

_fit!(o::Sum{T}, x::Real) where {T<:AbstractFloat} = (o.sum += convert(T, x); o.n += 1)
_fit!(o::Sum{T}, x::Real) where {T<:Integer} = (o.sum += round(T, x); o.n += 1) # <- this should be an error
joshday commented 3 months ago

Agreed! This is one of the earliest pieces of code ever added to OnlineStats(Base). I vet contributions with a little more rigor nowadays...

I'm removing the methods that use round.