-
Notifications
You must be signed in to change notification settings - Fork 13
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
Possible type instability with Mean
, Moments
, Sum
, Variance
#35
Comments
(Copy-pasted from joshday/OnlineStats.jl#265) |
The julia> o = Mean(Complex{Float64})
Mean: n=0 | value=0.0+0.0im
# fit with non-Complex{Float64} data
julia> fit!(o, 1:10)
Mean: n=10 | value=5.5+0.0im If the supertype here was # this is kinda annoying to do
fit!(o, Complex{Float64}(i) for i in 1:10) In other words, the I started holding a baby at this exact moment, so the rest will be brief 😄 Note: mutable struct MeanStdFilter{T}
nu::Int
tracker::OnlineStat # avoid abstract types here
end If I'm following your code correctly, here's a simpler implementation: julia> o = Group([Variance() for i in 1:5]...)
Group
├─ Variance: n=0 | value=1.0
├─ Variance: n=0 | value=1.0
├─ Variance: n=0 | value=1.0
├─ Variance: n=0 | value=1.0
└─ Variance: n=0 | value=1.0
julia> fit!(o, randn(5) for _ in 1:10^6)
Group
├─ Variance: n=1_000_000 | value=0.999672
├─ Variance: n=1_000_000 | value=0.998411
├─ Variance: n=1_000_000 | value=0.999115
├─ Variance: n=1_000_000 | value=0.999463
└─ Variance: n=1_000_000 | value=1.0014
julia> x = 1:5
1:5
julia> (x .- mean.(value(o))) ./ std.(value(o))
5-element Vector{Float64}:
0.9999604301846247
2.0024759146329214
3.0005499202160566
3.999616355074072
4.995462949480359 |
Thanks for the suggestions and the explanation, this actually solved my issue! |
Why are some statistics types subtyped with
OnlineStat{Number}
? For example:Is there a reason we can't have
mutable struct Mean{T,W} <: OnlineStat{T}
instead? This means that wheninput()
is called on statistics likeMean()
it will always returnNumber
instead of the actual input type (eg:Float32
). The same is true forMean
,Moments
,Sum
, andVariance
.I noticed this while playing around with a Mean/Stdev filter. My original code is as follows (and feel free to offer any suggestions on better/more efficient ways to do this, I'm new to this package).
Running with
T = Float32
I get:and with
T = Float64
it increases to:I suspect this is to do with having to convert
Float64
toFloat32
at some point in the pipeline because of the issue raised above.Thanks in advance for any help!
The text was updated successfully, but these errors were encountered: