Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/axiomhq/welford" ) func main() { stats1 := welford.New() stats1.Add(1) stats1.Add(1) stats1.Add(1) stats1.Add(0) stats1.Add(0) stats1.Add(0) fmt.Println( stats1.Mean(), stats1.Variance(), stats1.StandardDeviation(), stats1.VariancePopulation(), stats1.StandardDeviationPopulation(), stats1.NumDataValues(), ) stats2 := welford.New() stats2.Add(3) // Merge the values of stats2 into stats1. stats1.Merge(stats2) // Reset the values in stats2. stats2.Clear() }
Output: 0.5 0.3 0.5477225575051661 0.25 0.5 6
Index ¶
- type Stats
- func (sts *Stats) Add(x float64)
- func (sts *Stats) AddWeighted(val, weight float64)
- func (sts *Stats) Clear()
- func (sts *Stats) Clone() *Stats
- func (sts *Stats) Mean() float64
- func (sts *Stats) Merge(other *Stats)
- func (sts *Stats) NumDataValues() uint
- func (sts *Stats) ReadFrom(r io.Reader) (int64, error)
- func (sts *Stats) StandardDeviation() float64
- func (sts *Stats) StandardDeviationPopulation() float64
- func (sts *Stats) Variance() float64
- func (sts *Stats) VariancePopulation() float64
- func (sts *Stats) WriteTo(w io.Writer) (int64, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Stats of welford's algorithm for computing the mean and variance.
func New ¶
func New() *Stats
New returns new Welford's algorithm stats. The stats are initialized to their respective zero values.
func (*Stats) AddWeighted ¶
AddWeighted adds a new weighted value to the stats.
func (*Stats) NumDataValues ¶
NumDataValues returns the number of data values in the stats.
func (*Stats) StandardDeviation ¶
StandardDeviation returns the standard deviation of the data, which is the square root of the variance.
func (*Stats) StandardDeviationPopulation ¶
StandardDeviationPopulation returns the standard deviation of the data, which is the square root of the variance of the sampled data.
func (*Stats) Variance ¶
Variance returns the variance of the data, assuming the data added was sampled.
func (*Stats) VariancePopulation ¶
VariancePopulation returns the variance of the data, assuming the data added was not sampled.