math

package
v0.0.0-...-33b6dc5 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Digits

func Digits[T int32 | int64](value T) int

Digits returns the number of digits required to represent value with base 10.

func EstimatedDigitsInt32

func EstimatedDigitsInt32(value int32) int

EstimatedDigitsInt32 returns the estimated number of digits required to represent value with base 10. The returned estimation should always be >= that the actual number of digits, but never lower.

func EstimatedDigitsInt64

func EstimatedDigitsInt64(value int64) int

EstimatedDigitsInt64 returns the estimated number of digits required to represent value with base 10. The returned estimation should always be >= that the actual number of digits, but never lower.

func Log10Func

func Log10Func(factor int) func(value int) int

Log10Func returns a function that produces the Log10 value for some input, scaled for some factor, using cached values when available. Input values for the resulting function are rounded to an int.

func Smooth

func Smooth(oldValue, newValue, factor float64) float64

Smooth returns a value that is decreased by some portion of the oldValue, and increased by some portion of the newValue, based on the factor.

Types

type CorrelationWindow

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

CorrelationWindow can be used to compute correlation for sets of values over a rolling window.

This type is not concurrency safe.

func NewCorrelationWindow

func NewCorrelationWindow(capacity uint, warmupSamples uint8) *CorrelationWindow

func (*CorrelationWindow) Add

func (w *CorrelationWindow) Add(x, y float64) (correlation, cvX, cvY float64)

Add adds the values to the window and returns the current correlation coefficient. Returns a value between 0 and 1 when a correlation between increasing x and y values is present. Returns a value between -1 and 0 when a correlation between increasing x and decreasing y values is present. Returns 0 values if < warmup or low CV (< .01)

type Ewma

type Ewma interface {
	// Add adds a value to the series and updates the moving average.
	Add(float64) float64

	// Value gets the current value of the moving average.
	Value() float64

	// Set sets a value for the moving average.
	Set(float64)
}

Ewma provides an exponentially weighted moving average for some windowed values, without strict time-based adjustments.

This type is not concurrency safe.

func NewEwma

func NewEwma(windowSize uint, warmupSamples uint8) Ewma

NewEwma creates a new exponentially weighted moving average for the windowSize and warmupSamples. windowSize controls how many samples are effectively stored in the Ewma before they decay out. warmupSamples controls how many samples must be recorded before decay begins.

type EwmaRate

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

EwmaRate tracks an exponentially weighted moving average of a per-second rate.

func NewEWMARate

func NewEWMARate(alpha float64, interval time.Duration) *EwmaRate

func (*EwmaRate) Add

func (r *EwmaRate) Add(delta int64)

func (*EwmaRate) Inc

func (r *EwmaRate) Inc()

Inc counts one event.

func (*EwmaRate) Rate

func (r *EwmaRate) Rate() float64

Rate returns the per-second rate.

func (*EwmaRate) Tick

func (r *EwmaRate) Tick()

Tick assumes to be called every r.interval.

type MedianFilter

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

MedianFilter provides the median value over a rolling window.

This type is not concurrency safe.

func NewMedianFilter

func NewMedianFilter(size int) *MedianFilter

func (*MedianFilter) Add

func (f *MedianFilter) Add(value float64) float64

Add adds a value to the filter, sorts the values, and returns the current median.

func (*MedianFilter) Median

func (f *MedianFilter) Median() float64

Median returns the current median, else 0 if the filter isn't full yet.

type RollingSum

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

RollingSum can be used to compute the coefficient of variation over rolling windowed values, along with slope calulation.

This type is not concurrency safe.

func NewRollingSum

func NewRollingSum(capacity uint) *RollingSum

func (*RollingSum) Add

func (r *RollingSum) Add(value float64) (oldValue float64, full bool)

Add adds the value to the window if it's non-zero, updates the sums, and returns the old value along with whether the window is full.

func (*RollingSum) CalculateCV

func (r *RollingSum) CalculateCV() (cv, mean, variance float64)

CalculateCV calculates the coefficient of variation (relative variance), mean, and variance for the sum. Returns NaN values if there are < 2 samples, the variance is < 0, or the mean is 0.

Jump to

Keyboard shortcuts

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