@@ -13,46 +13,6 @@ function print_stat_tree(io::IO, stats)
1313 end
1414end
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
704664end
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())
0 commit comments