runningstat

package
v0.0.0-...-1e60831 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: NIST-PD-fallback Imports: 7 Imported by: 0

README

ndn-dpdk/core/runningstat

This package implements Knuth and Welford's method for computing the standard deviation. Compared to the original RunningStats C++ class, this implementation does not support skewness and kurtosis, adds tracking of the minimum and maximum values, and can be configured to periodically sample the input instead of sampling every input.

To add an input, use the C function RunningStat_Push, or RunningStat_Push1 when minimum and maximum are unnecessary. To compute the average and standard deviation, use the Go type RunningStat.

Documentation

Overview

Package runningstat implements Knuth and Welford's method for computing the standard deviation.

Index

Constants

This section is empty.

Variables

View Source
var GqlSnapshotType = graphql.NewObject(graphql.ObjectConfig{
	Name:   "RunningStatSnapshot",
	Fields: gqlserver.BindFields[Snapshot](nil),
})

GqlSnapshotType is the GraphQL type for Snapshot.

Functions

This section is empty.

Types

type IntStat

type IntStat C.RunningStatI

func IntFromPtr

func IntFromPtr(ptr unsafe.Pointer) (s *IntStat)

IntFromPtr converts *C.RunningStatI to IntStat.

func (*IntStat) Init

func (s *IntStat) Init(sampleInterval int)

Init initializes the instance and clears existing data. sampleInterval: how often to collect sample, will be adjusted to nearest power of two and truncated between 1 and 2^30.

func (*IntStat) Push

func (s *IntStat) Push(x uint64)

Push adds an input.

func (*IntStat) Read

func (s *IntStat) Read() Snapshot

Read returns current counters as Snapshot.

type RunningStat

type RunningStat C.RunningStat

RunningStat collects statistics and allows computing mean and variance. Algorithm comes from https://www.johndcook.com/blog/standard_deviation/ .

func FromPtr

func FromPtr(ptr unsafe.Pointer) (s *RunningStat)

FromPtr converts *C.RunningStat to RunningStat.

func (*RunningStat) Init

func (s *RunningStat) Init(sampleInterval int)

Init initializes the instance and clears existing data. sampleInterval: how often to collect sample, will be adjusted to nearest power of two and truncated between 1 and 2^30.

func (*RunningStat) Push

func (s *RunningStat) Push(x float64)

Push adds an input.

func (*RunningStat) Read

func (s *RunningStat) Read() Snapshot

Read returns current counters as Snapshot.

type Snapshot

type Snapshot struct {
	Count    uint64  `json:"count" gqldesc:"Number of input values."`
	Len      uint64  `json:"len" gqldesc:"Number of collected samples."`
	Mean     float64 `json:"mean" gqldesc:"Mean value. Valid if count>0."`
	Variance float64 `json:"variance" gqldesc:"Variance of samples. Valid if count>1."`
	Stdev    float64 `json:"stdev" gqldesc:"Standard deviation of samples. Valid if count>1."`
	M1       float64 `json:"m1"`
	M2       float64 `json:"m2"`
	Min      *uint64 `json:"min" gqldesc:"Minimum value. Valid if count>0."`
	Max      *uint64 `json:"max" gqldesc:"Maximum value. Valid if count>0."`
}

Snapshot contains a snapshot of RunningStat reading.

func (Snapshot) Add

func (s Snapshot) Add(o Snapshot) Snapshot

Add combines stats with another instance.

func (Snapshot) Scale

func (s Snapshot) Scale(ratio float64) Snapshot

Scale multiplies every number by a ratio.

func (Snapshot) Sub

func (s Snapshot) Sub(o Snapshot) Snapshot

Sub computes numerical difference.

Jump to

Keyboard shortcuts

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