added distinction between population and sample statistic
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user