ewma

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytes

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

Bytes is an estimator for an arbitrary value that is sampled from byte blocks.

Consider a stream of data which is divided into blocks of varying size. We want to estimate a value (like compression ratio) based on the values from recent blocks.

Bytes implements a per-byte exponential moving average (EWMA) estimator: let pos_i and val_i be the position and value of each byte for which we have data; the estimate at position p is the weighted sum:

	Sum_i val_i*(1-alpha)^(p-pos_i)
  -------------------------------
     Sum_i (1-alpha)^(p-pos_i)

func (*Bytes) Estimate

func (b *Bytes) Estimate() float64

Estimate returns the current estimate of the value, based on the recent SampledBlock() calls. Returns NaN if no blocks have been sampled yet.

func (*Bytes) Init

func (b *Bytes) Init(halfLife int64)

Init the estimator such that a block sampled <half-life> bytes ago has half the weight compared to a block sampled now.

Intuitively, half of the estimate comes from the values within the half-life window; and 75% of the estimate comes from values within 2x half-life.

func (*Bytes) NoSample

func (b *Bytes) NoSample(numBytes int64)

NoSample informs the estimator that a block of the given length was not sampled.

func (*Bytes) SampledBlock

func (b *Bytes) SampledBlock(numBytes int64, value float64)

SampledBlock informs the estimator that a block of the given length was sampled.

Jump to

Keyboard shortcuts

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