buffer

package
v0.0.0-...-31ccac1 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 4 Imported by: 0

README

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inp

func Inp(s xmath.Matrix) xmath.Matrix

Inp keeps all rows of a matrix except the last.

func Outp

func Outp(s xmath.Matrix) xmath.Matrix

Outp keeps all rows of a matrix except for the first.

func Sum

func Sum(s, v float64) float64

Types

type Bucket

type Bucket struct {
	// contains filtered or unexported fields
}

Bucket groups together objects with the same Index it keeps track of statistical quantities relating to the collection by using the stats

func NewBucket

func NewBucket(id int64, dim int) Bucket

NewBucket creates a new bucket

func (Bucket) Index

func (b Bucket) Index() int64

Index returns the bucket index.

func (*Bucket) Push

func (b *Bucket) Push(index int64, v ...float64) bool

Push adds an element to the bucket for the given index. it returns true if the bucket has the right index, false otherwise. This allows to build higher level abstractions i.e. window etc ...

func (Bucket) Size

func (b Bucket) Size() int

Size returns the number of elements in the bucket.

func (Bucket) Values

func (b Bucket) Values() StatsCollector

Stats returns the current Stats for the bucket.

type BucketRing

type BucketRing struct {
	// contains filtered or unexported fields
}

BucketRing acts like a ring buffer keeping the last x elements

func NewBucketRing

func NewBucketRing(size int) *BucketRing

NewBucketRing creates a new ring with the given buffer size.

func (*BucketRing) Get

func (r *BucketRing) Get(transform Transform) []interface{}

Get returns an ordered slice of the ring elements

func (*BucketRing) Push

func (r *BucketRing) Push(v *Bucket)

Push adds an element to the ring.

func (*BucketRing) Size

func (r *BucketRing) Size() int

Size returns the number of non-nil elements within the ring.

type Func

type Func func(p, v float64) float64

func Pow

func Pow(p float64) Func

type HistoryWindow

type HistoryWindow struct {
	// contains filtered or unexported fields
}

HistoryWindow keeps the last x buckets based on the window interval given

func NewHistoryWindow

func NewHistoryWindow(duration time.Duration, size int) *HistoryWindow

NewHistoryWindow creates a new history window.

func (*HistoryWindow) Get

func (h *HistoryWindow) Get(transform Transform) []interface{}

Get returns the transformed bucket value at the corresponding index.

func (*HistoryWindow) Push

func (h *HistoryWindow) Push(t time.Time, v ...float64) (time.Time, *Bucket, bool)

Push adds an element to the given time index. It will return true, if there was a new bucket completed at the last operation

type Ring

type Ring struct {
	// contains filtered or unexported fields
}

Ring acts like a ring buffer keeping the last x elements

func NewRing

func NewRing(size int) *Ring

NewRing creates a new ring with the given buffer size.

func (*Ring) Aggregate

func (r *Ring) Aggregate(process Func) float64

Get returns an ordered slice of the ring elements

func (*Ring) Get

func (r *Ring) Get() []float64

Get returns an ordered slice of the ring elements

func (*Ring) Push

func (r *Ring) Push(v float64)

Push adds an element to the ring.

func (*Ring) Size

func (r *Ring) Size() int

Size returns the number of non-nil elements within the ring.

type SizeWindow

type SizeWindow struct {
	// contains filtered or unexported fields
}

SizeWindow is a window indexed by the current time.

func NewSizeWindow

func NewSizeWindow(size int) *SizeWindow

NewSizeWindow creates a new SizeWindow with the given duration.

func (*SizeWindow) Push

func (sw *SizeWindow) Push(v float64) (*Bucket, bool)

Push adds an element to the time window.

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats is a set of statistical properties of a set of numbers.

func NewStats

func NewStats() *Stats

NewStats creates a new Stats.

func (Stats) Avg

func (s Stats) Avg() float64

Avg returns the average value of the set.

func (Stats) Count

func (s Stats) Count() int

Count returns the number of elements.

func (Stats) Diff

func (s Stats) Diff() float64

Diff returns the difference of max and min.

func (*Stats) Push

func (s *Stats) Push(v float64)

Push adds another element to the set.

func (Stats) SampleStDev

func (s Stats) SampleStDev() float64

SampleStDev is the sample standard deviation of the set.

func (Stats) SampleVariance

func (s Stats) SampleVariance() float64

SampleVariance is the sample variance of the set.

func (Stats) StDev

func (s Stats) StDev() float64

StDev is the standard deviation of the set.

func (Stats) Sum

func (s Stats) Sum() float64

Avg returns the average value of the set.

func (Stats) Variance

func (s Stats) Variance() float64

Variance is the mathematical variance of the set.

type StatsCollector

type StatsCollector struct {
	// contains filtered or unexported fields
}

StatsCollector is a collection of Stats variables. This enabled multi-dimensional tracking.

func NewStatsCollector

func NewStatsCollector(dim int) *StatsCollector

NewStatsCollector creates a new Stats collector.

func (*StatsCollector) Push

func (sc *StatsCollector) Push(v ...float64)

Push pushes each value to the corresponding dimension.

func (*StatsCollector) Size

func (sc *StatsCollector) Size() int

Push pushes each value to the corresponding dimension.

func (StatsCollector) Stats

func (sc StatsCollector) Stats() []*Stats

type TimeWindow

type TimeWindow struct {
	// contains filtered or unexported fields
}

TimeWindow is a window indexed by the current time.

func NewTimeWindow

func NewTimeWindow(duration time.Duration) *TimeWindow

NewTimeWindow creates a new TimeWindow with the given duration.

func (*TimeWindow) Next

func (tw *TimeWindow) Next(iterations int64) time.Time

Next returns the next timestamp for the coming window.

func (*TimeWindow) Push

func (tw *TimeWindow) Push(t time.Time, v ...float64) (time.Time, *Bucket, bool)

Push adds an element to the time window. It will return true, if the last addition caused a bucket to close.

type Transform

type Transform func(bucket *Bucket) interface{}

Transform is a operation acting on a bucket and returning a float. It is used to get the relevant bucket metric, without the need to make repeated iterations.

type VectorRing

type VectorRing struct {
	// contains filtered or unexported fields
}

VectorRing is a temporary cache of vectors it re-uses a slice of vectors (matrix) and keeps track of the starting index. In that sense it s effectively a ring. A major differentiating factor is the (+1) logic, where the last element is handled separately.

func NewSplitVectorRing

func NewSplitVectorRing(n int) *VectorRing

func NewVectorRing

func NewVectorRing(n int) *VectorRing

func (VectorRing) Copy

func (w VectorRing) Copy() VectorRing

func (*VectorRing) Push

func (w *VectorRing) Push(v xmath2.Vector) (xmath2.Matrix, bool)

Push adds an element to the window.

func (VectorRing) Size

func (w VectorRing) Size() int

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is a helper struct allowing to retrieve buckets of Stats from a streaming data set. the bucket indexing is based on the time.

func NewWindow

func NewWindow(size int64) *Window

NewWindow creates a new window of the given window size e.g. the index range for each bucket.

func (*Window) Current

func (w *Window) Current() int64

Current returns the current index the window accumulates data on.

func (*Window) Get

func (w *Window) Get() Bucket

Get returns the last complete Bucket.

func (*Window) Next

func (w *Window) Next() int64

Next is the next index at which a new bucket will be created

func (*Window) Push

func (w *Window) Push(index int64, value ...float64) (int64, bool)

Push adds an element to a window at the given index. returns if the window closed, e.g. if last element initiated a new bucket. (Note that based on this logic we ll only know when a window closed only on the initiation of a new one) and the index of the closed window.

Jump to

Keyboard shortcuts

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