Comments (4)
This is too much stuff. Do you have a MWE?
from onlinestats.jl.
Thanks @joshday for this nice projet and for your answer.
Here is a MWE
using OnlineStatsBase
using OnlineStats: StatLag
mutable struct MyMean <: OnlineStat{Number}
value::Float64
n::Int
MyMean() = new(0.0, 0)
end
function OnlineStatsBase._fit!(o::MyMean, y)
o.n += 1
o.value += (1 / o.n) * (y - o.value)
end
y = Float64[10, 11, 12, 13, 14, 15]
println(y)
o = MyMean()
o = StatLag(o, 3)
fit!(o, y)
println(value(o))
println(value(o.lag[end-1]))
println(value(o.lag[end-2]))
and a MNWE
using OnlineStatsBase
"""
StatLag(stat, b)
Track a moving window (previous `b` copies) of `stat`.
# Example
fit!(StatLag(Mean(), 10), 1:20)
"""
struct StatLag{T, O<:OnlineStat{T}} <: OnlineStatsBase.StatWrapper{T}
lag::CircBuff{O}
stat::O
end
function StatLag(stat::O, b::Integer) where {T, O<:OnlineStat{T}}
StatLag{T,O}(CircBuff(O,b), stat)
end
function _fit!(o::StatLag, y)
_fit!(o.stat, y)
_fit!(o.lag, copy(o.stat))
end
function Base.show(io::IO, o::StatLag)
print(io, name(o, false, false), ": ")
print(io, "n=", nobs(o))
print(io, " | stat_values_old_to_new= ")
show(IOContext(io, :compact => true), value.(value(o.lag)))
end
mutable struct MyMean <: OnlineStat{Number}
value::Float64
n::Int
MyMean() = new(0.0, 0)
end
function OnlineStatsBase._fit!(o::MyMean, y)
o.n += 1
o.value += (1 / o.n) * (y - o.value)
end
y = Float64[10, 11, 12, 13, 14, 15]
println(y)
o = MyMean()
o = StatLag(o, 3)
fit!(o, y)
println(value(o))
println(value(o.lag[end-1]))
println(value(o.lag[end-2]))
this one raises
ERROR: LoadError: MethodError: no method matching _fit!(::StatLag{Number, MyMean}, ::Float64)
from onlinestats.jl.
Looks like you're missing a OnlineStatsBase.
here:
function _fit!(o::StatLag, y)
_fit!(o.stat, y)
_fit!(o.lag, copy(o.stat))
end
from onlinestats.jl.
Thanks @joshday
I got it
using OnlineStatsBase
"""
StatLag(stat, b)
Track a moving window (previous `b` copies) of `stat`.
# Example
fit!(StatLag(Mean(), 10), 1:20)
"""
struct StatLag{T, O<:OnlineStat{T}} <: OnlineStatsBase.StatWrapper{T}
lag::CircBuff{O}
stat::O
end
function StatLag(stat::O, b::Integer) where {T, O<:OnlineStat{T}}
StatLag{T,O}(CircBuff(O,b), stat)
end
function OnlineStatsBase._fit!(o::StatLag, y)
OnlineStatsBase._fit!(o.stat, y)
OnlineStatsBase._fit!(o.lag, copy(o.stat))
end
function Base.show(io::IO, o::StatLag)
print(io, name(o, false, false), ": ")
print(io, "n=", nobs(o))
print(io, " | stat_values_old_to_new= ")
show(IOContext(io, :compact => true), value.(value(o.lag)))
end
mutable struct MyMean <: OnlineStat{Number}
value::Float64
n::Int
MyMean() = new(0.0, 0)
end
function OnlineStatsBase._fit!(o::MyMean, y)
o.n += 1
o.value += (1 / o.n) * (y - o.value)
end
y = Float64[10, 11, 12, 13, 14, 15]
println(y)
o = MyMean()
o = StatLag(o, 3)
fit!(o, y)
println(value(o))
println(value(o.lag[end-1]))
println(value(o.lag[end-2]))
from onlinestats.jl.
Related Issues (20)
- Group with 3 Stats not working for multi-observations? HOT 3
- Julia VS Code extension reports "Possible method call error" for `fit!` HOT 3
- _fit! on AutoCov is not type stable HOT 1
- Extract field of an observation before feeding an OnlineStats - ValueExtractor wrapper HOT 2
- Feature Request: OnlineStat Chaining HOT 1
- ExtremeValues doesn't work HOT 2
- Odd interaction of `Group` with broadcast HOT 2
- [speculative] `NullStat` HOT 1
- Plot of GroupBy of HeatMap fails HOT 1
- when fit!-ing a Group to a NamedTuple, the names are ignored HOT 2
- Documentation Request: List which Monoids support merge HOT 1
- Feature Request: PCA wrapper around CovMatrix which also supports transform methods
- Pretty printing is unpretty inside DataFrame HOT 5
- Support `keys` and `values` on `GroupBy` HOT 1
- Bug: Y-Marginals for heatmap are wrong HOT 1
- Allow counts argument in `fit!` HOT 5
- Suggestions for OnlineStats v2 HOT 1
- Standard Deviation - StdDev HOT 1
- Integrate `StreamSampling` in `OnlineStats` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from onlinestats.jl.