joint

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: 9 Imported by: 0

Documentation

Overview

Package joint provides a library of data structures/algorithms for calculating online joint distribution statistics from a stream of data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(wrapper CoreWrapper) error

Init sets a CoreWrapper up with a core for consuming.

Types

type Autocorr

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

Autocorr is a metric that tracks the sample autocorrelation. It does not satisfy the JointMetric interface, but rather the univariate Metric interface (SimpleMetric in particular), since it only tracks a single variable.

func NewAutocorr

func NewAutocorr(lag int, window int) (*Autocorr, error)

NewAutocorr instantiates an Autocorr struct.

func NewGlobalAutocorr

func NewGlobalAutocorr(lag int) (*Autocorr, error)

NewGlobalAutocorr instantiates a global Autocorr struct. This is equivalent to calling NewAutocorr(lag, 0).

func (*Autocorr) Clear

func (a *Autocorr) Clear()

Clear resets the metric.

func (*Autocorr) Config

func (a *Autocorr) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*Autocorr) IsSetCore

func (a *Autocorr) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*Autocorr) Push

func (a *Autocorr) Push(x float64) error

Push adds a new value for Autocorr to consume. Autocorr only takes one value, because we're calculating the lagged correlation of a series of data against itself.

func (*Autocorr) SetCore

func (a *Autocorr) SetCore(c *Core)

SetCore sets the Core.

func (*Autocorr) String

func (a *Autocorr) String() string

String returns a string representation of the metric.

func (*Autocorr) Value

func (a *Autocorr) Value() (float64, error)

Value returns the value of the sample autocorrelation.

type Autocov

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

Autocov is a metric that tracks the sample autocovariance. It does not satisfy the JointMetric interface, but rather the univariate Metric interface (SimpleMetric in particular), since it only tracks a single variable.

func NewAutocov

func NewAutocov(lag int, window int) (*Autocov, error)

NewAutocov instantiates an Autocov struct.

func NewGlobalAutocov

func NewGlobalAutocov(lag int) (*Autocov, error)

NewGlobalAutocov instantiates a global Autocov struct. This is equivalent to calling NewAutocov(lag, 0).

func (*Autocov) Clear

func (a *Autocov) Clear()

Clear resets the metric.

func (*Autocov) Config

func (a *Autocov) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*Autocov) IsSetCore

func (a *Autocov) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*Autocov) Push

func (a *Autocov) Push(x float64) error

Push adds a new value for Autocov to consume. Autocov only takes one value, because we're calculating the lagged covelation of a series of data against itself.

func (*Autocov) SetCore

func (a *Autocov) SetCore(c *Core)

SetCore sets the Core.

func (*Autocov) String

func (a *Autocov) String() string

String returns a string representation of the metric.

func (*Autocov) Value

func (a *Autocov) Value() (float64, error)

Value returns the value of the sample autocovelation.

type Core

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

Core is a struct that stores fundamental information for multivariate moments of a stream.

func NewCore

func NewCore(config *CoreConfig) (*Core, error)

NewCore instantiates a Core struct based on a provided config.

func (*Core) Clear

func (c *Core) Clear()

Clear clears all stats being tracked.

func (*Core) Count

func (c *Core) Count() int

Count returns the number of values seen seen globally.

func (*Core) Lock

func (c *Core) Lock()

Lock locks the Core internals for writing.

func (*Core) Mean

func (c *Core) Mean(i int) (float64, error)

Mean returns the mean of values seen for a given variable.

func (*Core) Push

func (c *Core) Push(xs ...float64) error

Push adds a new value for a Core object to consume.

func (*Core) RLock

func (c *Core) RLock()

RLock locks the Core internals for reading.

func (*Core) RUnlock

func (c *Core) RUnlock()

RUnlock undoes a single RLock call.

func (*Core) Sum

func (c *Core) Sum(xs ...int) (float64, error)

Sum returns the joint centralized sum of values seen for a provided exponent Tuple. In other words, for a Tuple m = (m_1, ..., m_k), this returns the sum of (x_i1 - μ_1)^m_1 * ... * (x_ik - μ_k)^m_k over all joint data points (x_i1, ..., x_ik).

func (*Core) Unlock

func (c *Core) Unlock()

Unlock undoes a Lock call.

func (*Core) UnsafeClear

func (c *Core) UnsafeClear()

UnsafeClear clears all stats being tracked, but does not lock. This should only be used if the user plans to make use of the Lock()/Unlock() Core methods.

func (*Core) UnsafeCount

func (c *Core) UnsafeCount() int

UnsafeCount returns the number of values seen seen globally, but does not lock. This should only be used if the user plans to make use of the [R]Lock()/[R]Unlock() Core methods.

func (*Core) UnsafeMean

func (c *Core) UnsafeMean(i int) (float64, error)

UnsafeMean returns the mean of values seen for a given variable, but does not lock. This should only be used if the user plans to make use of the [R]Lock()/[R]Unlock() Core methods.

func (*Core) UnsafePush

func (c *Core) UnsafePush(xs ...float64) error

UnsafePush adds a new value for a Core object to consume, but does not lock. This should only be used if the user plans to make use of the Lock()/Unlock() Core methods.

func (*Core) UnsafeSum

func (c *Core) UnsafeSum(xs ...int) (float64, error)

UnsafeSum returns the joint centralized sum of values seen for a provided exponent Tuple, but does not lock. This should only be used if the user plans to make use of the [R]Lock()/[R]Unlock() Core methods.

type CoreConfig

type CoreConfig struct {
	Sums   SumsConfig // sums tracked must be positive, and must track > 1 variables
	Window *int       // must be 0 if decay is set, must be nonnegative in general
	Vars   *int       // must be inferrable from Sums if not set; otherwise must be > 1
	Decay  *float64   // optional, must lie in the interval (0, 1)
}

CoreConfig is the struct containing configuration options for instantiating a Core object.

func MergeConfigs

func MergeConfigs(configs ...*CoreConfig) (*CoreConfig, error)

MergeConfigs merges CoreConfig objects.

type CoreWrapper

type CoreWrapper interface {
	SetCore(*Core)
	Config() *CoreConfig
}

CoreWrapper is the interface for an entity that wraps around a Core for stats. The methods below are required for setting up a Core for the wrapper.

type Corr

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

Corr is a metric that tracks the sample Pearson correlation coefficient.

func NewCorr

func NewCorr(window int) *Corr

NewCorr instantiates a Corr struct.

func NewGlobalCorr

func NewGlobalCorr() *Corr

NewGlobalCorr instantiates a global Corr struct. This is equivalent to calling NewCorr(0).

func (*Corr) Clear

func (corr *Corr) Clear()

Clear resets the metric.

func (*Corr) Config

func (corr *Corr) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*Corr) IsSetCore

func (corr *Corr) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*Corr) Push

func (corr *Corr) Push(xs ...float64) error

Push adds a new pair of values for Corr to consume.

func (*Corr) SetCore

func (corr *Corr) SetCore(c *Core)

SetCore sets the Core.

func (*Corr) String

func (corr *Corr) String() string

String returns a string representation of the metric.

func (*Corr) Value

func (corr *Corr) Value() (float64, error)

Value returns the value of the sample Pearson correlation coefficient.

type Cov

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

Cov is a metric that tracks the sample covariance.

func NewCov

func NewCov(window int) *Cov

NewCov instantiates a Cov struct.

func NewGlobalCov

func NewGlobalCov() *Cov

NewGlobalCov instantiates a global Cov struct. This is equivalent to calling NewCov(0).

func (*Cov) Clear

func (cov *Cov) Clear()

Clear resets the metric.

func (*Cov) Config

func (cov *Cov) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*Cov) IsSetCore

func (cov *Cov) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*Cov) Push

func (cov *Cov) Push(xs ...float64) error

Push adds a new pair of values for Cov to consume.

func (*Cov) SetCore

func (cov *Cov) SetCore(c *Core)

SetCore sets the Core.

func (*Cov) String

func (cov *Cov) String() string

String returns a string representation of the metric.

func (*Cov) Value

func (cov *Cov) Value() (float64, error)

Value returns the value of the sample covariance.

type EWMCorr

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

EWMCorr is a metric that tracks the sample Pearson correlation coefficient.

func NewEWMCorr

func NewEWMCorr(decay float64) *EWMCorr

NewEWMCorr instantiates a EWMCorr struct.

func (*EWMCorr) Clear

func (corr *EWMCorr) Clear()

Clear resets the metric.

func (*EWMCorr) Config

func (corr *EWMCorr) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*EWMCorr) IsSetCore

func (corr *EWMCorr) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*EWMCorr) Push

func (corr *EWMCorr) Push(xs ...float64) error

Push adds a new pair of values for EWMCorr to consume.

func (*EWMCorr) SetCore

func (corr *EWMCorr) SetCore(c *Core)

SetCore sets the Core.

func (*EWMCorr) String

func (corr *EWMCorr) String() string

String returns a string representation of the metric.

func (*EWMCorr) Value

func (corr *EWMCorr) Value() (float64, error)

Value returns the value of the sample Pearson correlation coefficient.

type EWMCov

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

EWMCov is a metric that tracks the sample exponentially weighted covariance.

func NewEWMCov

func NewEWMCov(decay float64) *EWMCov

NewEWMCov instantiates a EWMCov struct.

func (*EWMCov) Clear

func (cov *EWMCov) Clear()

Clear resets the metric.

func (*EWMCov) Config

func (cov *EWMCov) Config() *CoreConfig

Config returns the CoreConfig needed.

func (*EWMCov) IsSetCore

func (cov *EWMCov) IsSetCore() bool

IsSetCore returns if the core has been set.

func (*EWMCov) Push

func (cov *EWMCov) Push(xs ...float64) error

Push adds a new pair of values for EWMCov to consume.

func (*EWMCov) SetCore

func (cov *EWMCov) SetCore(c *Core)

SetCore sets the Core.

func (*EWMCov) String

func (cov *EWMCov) String() string

String returns a string representation of the metric.

func (*EWMCov) Value

func (cov *EWMCov) Value() (float64, error)

Value returns the value of the sample exponentially weighted covariance.

type Metric

type Metric interface {
	stream.SimpleJointMetric
	CoreWrapper
}

Metric is the interface for a metric that tracks joint statistics of a stream. Any Metric that will actually be consuming values (i.e. will have its Push method called) needs to be passed into the Init() method, which sets it up with a Core for consuming values and keeping track of centralized sums.

type SumsConfig

type SumsConfig []Tuple

SumsConfig is an alias for a slice of Tuples; this configures the multinomial sums that a Core object will track.

type Tuple

type Tuple []int

Tuple represents a vector of integers, which for the purpose of this package represents a vector of exponents for multivariate moments.

Jump to

Keyboard shortcuts

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