Skip to content

brucala/OnlineStatsBase.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docs Builds Tests
Build Status Build status codecov

OnlineStatsBase

This package defines the basic types and interface for OnlineStats.

Interface

Required

  • _fit!(stat, y): Update the "sufficient statistics" of the estimator from a single observation y.

Optional

  • _merge!(stat1, stat2) Merge stat2 into stat1. By default, a warning will occur.

Defaults

  • 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 returns stat.n.

Example

  • Make a subtype of OnlineStat and give it a _fit!(::OnlineStat{T}, y::T) method.
  • T is 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)
end

That's all there is to it!

y = randn(1000)

o = fit!(MyMean(), y)

Packages

No packages published

Languages

  • Julia 100.0%