| Docs | Builds | Tests |
|---|---|---|
This package defines the basic types and interface for OnlineStats.
_fit!(stat, y): Update the "sufficient statistics" of the estimator from a single observationy.
_merge!(stat1, stat2)Mergestat2intostat1. By default, a warning will occur.
value(stat, args...; kw...): Calculate the value of the estimator from the "sufficient statistics". By default, this returns the first field of the OnlineStat.nobs(stat): Return the number of observations. By default, this returnsstat.n.
- Make a subtype of OnlineStat and give it a
_fit!(::OnlineStat{T}, y::T)method. Tis the type of a single observation. Make sure it's adequately wide.
using OnlineStatsBase
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)
endy = randn(1000)
o = fit!(MyMean(), y)