quantile

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package quantile provides a library of data structures/algorithms for calculating online quantiles from a stream of data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeapMedian

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

HeapMedian keeps track of the median of an entire stream using heaps.

func NewGlobalHeapMedian

func NewGlobalHeapMedian() *HeapMedian

NewGlobalHeapMedian instantiates a global HeapMedian struct. This is equivalent to calling NewHeapMedian(0).

func NewHeapMedian

func NewHeapMedian(window int) (*HeapMedian, error)

NewHeapMedian instantiates a HeapMedian struct.

func (*HeapMedian) Clear

func (m *HeapMedian) Clear()

Clear resets the metric.

func (*HeapMedian) Push

func (m *HeapMedian) Push(x float64) error

Push adds a number for calculating the median.

func (*HeapMedian) String

func (m *HeapMedian) String() string

String returns a string representation of the metric.

func (*HeapMedian) Value

func (m *HeapMedian) Value() (float64, error)

Value returns the value of the median.

type IQR

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

IQR keeps track of the interquartile range of a stream using order statistics.

func NewGlobalIQR

func NewGlobalIQR(options ...Option) (*IQR, error)

NewGlobalIQR instantiates a global IQR struct. This is equivalent to calling NewIQR(0, options...).

func NewIQR

func NewIQR(window int, options ...Option) (*IQR, error)

NewIQR instantiates an IQR struct.

func (*IQR) Clear

func (i *IQR) Clear()

Clear resets the metric.

func (*IQR) Push

func (i *IQR) Push(x float64) error

Push adds a number for calculating the interquartile range.

func (*IQR) String

func (i *IQR) String() string

String returns a string representation of the metric.

func (*IQR) Value

func (i *IQR) Value() (float64, error)

Value returns the value of the interquartile range.

type Impl

type Impl int

Impl represents an enum that enumerates the currently supported implementations for the order.Statistic interface.

const (
	// AVL represents the AVL tree implementation for the order.Statistic interface
	AVL Impl = iota
	// RedBlack represents the red black tree implementation for the order.Statistic interface
	RedBlack
	// SkipList represents the skip list implementation for the order.Statistic interface
	SkipList
)

func (Impl) Valid

func (i Impl) Valid() bool

Valid returns whether or not the Impl value is a valid value.

type Interpolation

type Interpolation int

Interpolation represents an enum that enumerates the different interpolation methods that can be chosen when retrieving quantile metrics. In particular, if φ is the quantile value and n is the number of elements, then the raw estimated index for the φ-quantile element is i' = φ * (n - 1). However, this is not guaranteed to be an integer value. Thus, if the quantile of a window of elements actually lies in between two elements, this determines how the returned value will be calculated (depending on those two elements).

const (
	// Linear performs linear interpolation between the two elements.
	// If the φ-quantile i' lies between i and i + 1, then we return
	// (1 - (i' - i)) * a_i + (i' - i) * a_(i + 1).
	Linear Interpolation = iota
	// Lower chooses the lower of the two elements.
	Lower
	// Higher chooses the higher of the two elements.
	Higher
	// Nearest chooses the element whose index is closest to i'. If
	// i' is the midpoint between i and i + 1, then ties are broken
	// based on the parity of i; if i is even, then we choose a_i, and
	// otherwise choose a_(i + 1).
	Nearest
	// Midpoint performs the average of the two elements.
	Midpoint
)

func (Interpolation) Valid

func (i Interpolation) Valid() bool

Valid returns whether or not the Interpolation value is a valid value.

type Median

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

Median keeps track of the median of a stream using order statistics.

func NewGlobalMedian

func NewGlobalMedian(options ...Option) (*Median, error)

NewGlobalMedian instantiates a global Median struct. This is equivalent to calling NewMedian(0, options...).

func NewMedian

func NewMedian(window int, options ...Option) (*Median, error)

NewMedian instantiates a Median struct. The implementation of the underlying data structure for tracking order statistics can be configured by passing in a constant of type Impl.

func (*Median) Clear

func (m *Median) Clear()

Clear resets the metric.

func (*Median) Push

func (m *Median) Push(x float64) error

Push adds a number for calculating the median.

func (*Median) String

func (m *Median) String() string

String returns a string representation of the metric.

func (*Median) Value

func (m *Median) Value() (float64, error)

Value returns the value of the median.

type Option

type Option func(*Quantile) error

Option is an optional argument for creating quantile-based metrics, which sets an optional field for creating a Quantile.

func ImplOption

func ImplOption(impl Impl, options ...order.Option) Option

ImplOption creates an option that sets the implementation for the underlying data structure.

func InterpolationOption

func InterpolationOption(i Interpolation) Option

InterpolationOption creates an option that sets the interpolation method.

type Quantile

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

Quantile keeps track of the quantile of a stream using order statistics.

func New

func New(window int, options ...Option) (*Quantile, error)

New instantiates a Quantile struct.

func NewGlobalQuantile

func NewGlobalQuantile(options ...Option) (*Quantile, error)

NewGlobalQuantile instantiates a global Quantile struct. This is equivalent to calling New(0, options...).

func (*Quantile) Clear

func (q *Quantile) Clear()

Clear resets the metric.

func (*Quantile) Push

func (q *Quantile) Push(x float64) error

Push adds a number for calculating the quantile.

func (*Quantile) RLock

func (q *Quantile) RLock()

RLock locks the quantile for reading.

func (*Quantile) RUnlock

func (q *Quantile) RUnlock()

RUnlock undoes an RLock call.

func (*Quantile) String

func (q *Quantile) String() string

String returns a string representation of the metric.

func (*Quantile) Value

func (q *Quantile) Value(quantile float64) (float64, error)

Value returns the value of the quantile.

Directories

Path Synopsis
Package heap provides the implementation for heaps.
Package heap provides the implementation for heaps.
Package order contains the interfaces for various implementations of order statistics-based data structures.
Package order contains the interfaces for various implementations of order statistics-based data structures.
ost
Package ost provides the interfaces for order statistic trees, which are binary trees with the ability to perform log(n) time searches for elements in the tree with a specified rank, as well as log(n) time retrieval for the rank of a specified element in the tree.
Package ost provides the interfaces for order statistic trees, which are binary trees with the ability to perform log(n) time searches for elements in the tree with a specified rank, as well as log(n) time retrieval for the rank of a specified element in the tree.
avl
Package avl provides the implementation for an AVL tree, which satisfies the ost package interfaces, as well as the order package interfaces.
Package avl provides the implementation for an AVL tree, which satisfies the ost package interfaces, as well as the order package interfaces.
rb
Package rb provides the implementation for a red black tree, which satisfies the ost package interfaces, as well as the order package interfaces.
Package rb provides the implementation for a red black tree, which satisfies the ost package interfaces, as well as the order package interfaces.
Package skiplist provides the implementation for skiplists.
Package skiplist provides the implementation for skiplists.

Jump to

Keyboard shortcuts

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