runningvariance

package module
v0.0.0-...-fd8c026 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 1 Imported by: 2

README

runningvariance

A package for accurately computing running (online) mean, variance, and standard deviation. Based on code by John D Cook.

go get github.com/carbocation/runningvariance

To test (100% coverage)

go test -cover

Demo:

import "fmt"

import "github.com/carbocation/runningvariance"

func main() {
    var rv runningvariance.Stat

    rv.Push(1)
    rv.Push(2)
    rv.Push(3)
    rv.Push(4)
    rv.Push(5)

    fmt.Printf("Mean: %.4f | SD %.4f", rv.Mean(), rv.StandardDeviation())
}

Documentation

Overview

runningvariance computes accurate running mean, variance, and standard deviation

It is based on code by John D Cook: http://www.johndcook.com/blog/standard_deviation/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RunningStat

type RunningStat struct {
	N    uint
	NewM float64
	OldM float64
	NewS float64
	OldS float64
}

func NewRunningStat

func NewRunningStat() *RunningStat

func (*RunningStat) Mean

func (r *RunningStat) Mean() float64

func (*RunningStat) NumDataValues

func (r *RunningStat) NumDataValues() uint

func (*RunningStat) Push

func (r *RunningStat) Push(x float64)

func (*RunningStat) StandardDeviation

func (r *RunningStat) StandardDeviation() float64

func (*RunningStat) Variance

func (r *RunningStat) Variance() float64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL