added distinction between population and sample statistic

This commit is contained in:
sm
2013-12-29 00:48:20 -08:00
parent e7e174530e
commit d2fef9128a
2 changed files with 124 additions and 24 deletions
+12 -2
View File
@@ -13,12 +13,22 @@ type OnlineStat struct {
m2 float64
Max float64
Min float64
typ int64
}
func NewOnlineStat() *OnlineStat {
func NewSampleStat() *OnlineStat {
return &OnlineStat{
Min: math.Inf(1),
Max: math.Inf(-1),
typ: 1,
}
}
func NewPopulationStat() *OnlineStat {
return &OnlineStat{
Min: math.Inf(1),
Max: math.Inf(-1),
typ: 0,
}
}
@@ -47,7 +57,7 @@ func (os *OnlineStat) Variance() (float64, error) {
if os.n == 0 {
return 0.0, errors.New("no data")
}
return os.m2 / float64(os.n-1), nil
return os.m2 / float64(os.n-os.typ), nil
}
func (os *OnlineStat) StdDev() (float64, error) {