Skip to content

Commit 330127d

Browse files
committed
remove Mean/Variance
1 parent d1244ce commit 330127d

4 files changed

Lines changed: 4 additions & 95 deletions

File tree

docs/src/index.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
```@raw html
2-
<img src="https://user-images.githubusercontent.com/8075494/32734476-260821d0-c860-11e7-8c91-49ba0b86397a.gif"
3-
style = "display: block; margin-left: auto; margin-right: auto; width: 50%;">
4-
```
5-
61
# Home
72

83
**OnlineStats** is a Julia package for statistical analysis with algorithms that run both **online** and **in parallel**. Online algorithms are well suited for streaming data or when data is too large to hold in memory. Observations are processed one at a time and all **algorithms use O(1) memory**.
@@ -94,4 +89,6 @@ fit!(g, itr)
9489

9590
```@raw html
9691
<iframe src="https://ghbtns.com/github-btn.html?user=joshday&repo=OnlineStats.jl&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>
97-
```
92+
```
93+
94+
![](https://user-images.githubusercontent.com/8075494/32734476-260821d0-c860-11e7-8c91-49ba0b86397a.gif)

src/OnlineStats.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module OnlineStats
33
using RecipesBase, Reexport, Statistics, LinearAlgebra, Dates
44
@reexport using OnlineStatsBase, LossFunctions, PenaltyFunctions, LearnBase
55

6-
import OnlineStatsBase: OnlineStat, name, _fit!, _merge!, eachrow, eachcol
6+
import OnlineStatsBase: OnlineStat, name, _fit!, _merge!, eachrow, Mean, Variance
77
import LearnBase: fit!, nobs, value, predict, transform, transform!
88
import StatsBase: autocov, autocor, confint, skewness, kurtosis, entropy, midpoints,
99
fweights, sample, coef, Histogram

src/stats/stats.jl

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,6 @@ function print_stat_tree(io::IO, stats)
1313
end
1414
end
1515

16-
#-----------------------------------------------------------------------# Variance
17-
"""
18-
Variance(T = Float64; weight=EqualWeight())
19-
20-
Univariate variance, tracked as type `T`.
21-
22-
# Example
23-
24-
o = fit!(Variance(), randn(10^6))
25-
mean(o)
26-
var(o)
27-
std(o)
28-
"""
29-
mutable struct Variance{T, W} <: OnlineStat{Number}
30-
σ2::T
31-
μ::T
32-
weight::W
33-
n::Int
34-
end
35-
function Variance(T::Type{<:Number} = Float64; weight = EqualWeight())
36-
Variance(zero(T), zero(T), weight, 0)
37-
end
38-
Base.copy(o::Variance) = Variance(o.σ2, o.μ, o.weight, o.n)
39-
function _fit!(o::Variance{T}, x) where {T}
40-
μ = o.μ
41-
γ = T(o.weight(o.n += 1))
42-
o.μ = smooth(o.μ, T(x), γ)
43-
o.σ2 = smooth(o.σ2, (T(x) - o.μ) * (T(x) - μ), γ)
44-
end
45-
function _merge!(o::Variance, o2::Variance)
46-
γ = o2.n / (o.n += o2.n)
47-
δ = o2.μ - o.μ
48-
o.σ2 = smooth(o.σ2, o2.σ2, γ) + δ ^ 2 * γ * (1.0 - γ)
49-
o.μ = smooth(o.μ, o2.μ, γ)
50-
o
51-
end
52-
value(o::Variance) = o.n > 1 ? o.σ2 * unbias(o) : 1.0
53-
Statistics.var(o::Variance) = value(o)
54-
Statistics.mean(o::Variance) = o.μ
55-
5616
#-----------------------------------------------------------------------# AutoCov and Lag
5717
# Lag
5818
"""
@@ -703,30 +663,6 @@ function _fit!(o::KMeans, x)
703663
end
704664
end
705665

706-
#-----------------------------------------------------------------------# Mean
707-
"""
708-
Mean(T = Float64; weight=EqualWeight())
709-
710-
Track a univariate mean, stored as type `T`.
711-
712-
# Example
713-
714-
@time fit!(Mean(), randn(10^6))
715-
"""
716-
mutable struct Mean{T,W} <: OnlineStat{Number}
717-
μ::T
718-
weight::W
719-
n::Int
720-
end
721-
Mean(T::Type{<:Number} = Float64; weight = EqualWeight()) = Mean(zero(T), weight, 0)
722-
_fit!(o::Mean{T}, x) where {T} = (o.μ = smooth(o.μ, x, T(o.weight(o.n += 1))))
723-
function _merge!(o::Mean, o2::Mean)
724-
o.n += o2.n
725-
o.μ = smooth(o.μ, o2.μ, o2.n / o.n)
726-
end
727-
Statistics.mean(o::Mean) = o.μ
728-
Base.copy(o::Mean) = Mean(o.μ, o.weight, o.n)
729-
730666
#-----------------------------------------------------------------------# Moments
731667
"""
732668
Moments(; weight=EqualWeight())

test/runtests.jl

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,6 @@ end
390390
o2 = fit!(LinReg(), OnlineStatsBase.eachrow(ymat[:,[4,1]], ymat[:,3]))
391391
@test coef(o, [.2,.4]; y=3, x = [4,1], bias=false) coef(o2, [.2, .4])
392392
end
393-
#-----------------------------------------------------------------------# Mean
394-
@testset "Mean" begin
395-
o = fit!(Mean(), y)
396-
@test value(o) mean(y)
397-
@test mean(o) mean(y)
398-
@test (mergevals(Mean(), y, y2)...)
399-
end
400393
#-----------------------------------------------------------------------# ML
401394
@testset "ML" begin
402395
o = OnlineStats.preprocess(OnlineStatsBase.eachrow(ymat))
@@ -577,23 +570,6 @@ end
577570
@test (mergevals(Sum(), y, y2)...)
578571
@test ==(mergevals(Sum(Int), z, z2)...)
579572
end
580-
#-----------------------------------------------------------------------# Variance
581-
@testset "Variance" begin
582-
o = fit!(Variance(), y)
583-
@test mean(o) mean(y)
584-
@test var(o) var(y)
585-
@test std(o) std(y)
586-
587-
@test (mergevals(Variance(), x, x2)...)
588-
@test (mergevals(Variance(), y, y2)...)
589-
@test (mergevals(Variance(Float32), Float32.(y), Float32.(y2))...; atol=.001)
590-
@test (mergevals(Variance(), z, z2)...)
591-
# Issue 116
592-
@test std(Variance()) == 1
593-
@test std(fit!(Variance(), 1)) == 1
594-
@test std(fit!(Variance(), [1, 2])) == sqrt(.5)
595-
end
596-
597573

598574
include("test_kahan.jl")
599575

0 commit comments

Comments
 (0)