series

package
v0.0.0-...-116b634 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package series provides fundamental series operations. At its core is the Series interface, which describes a Series. A Series is an object which can be iterated over with Next(). The idea is that the underlying data could be large and fetched as needed from a database or some other storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HWInitialSeasonalFactors

func HWInitialSeasonalFactors(data []float64, slen int) ([]float64, error)

HWInitialSeasonalFactors returns a list of best initial seasonal factor so that we can start forecasting.

See http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm "Initial values for the Seasonal Indices"

func HWInitialTrendFactor

func HWInitialTrendFactor(data []float64, slen int) (float64, error)

HWInitialTrendFactor returns a list of best initial trend factor so that we can start forecasting.

See http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm "Initial values for the trend factor"

func HWMinimizeSSE

func HWMinimizeSSE(data []float64, slen int, trend float64, seasonal []float64, nPred int) (smooth, dev []float64, α, β, γ float64, k, e int)

HWMinimizeSSE repeatedly executes hwTripleExponentialSmoothing over data, season, slen, trend and nPred with varying α, β and γ using the Nelder-Mead algorithm to minimize SSE. It returns the final (best) smooth and dev returned by hwTripleExponentialSmoothing, as well as the resulting α, β, γ (which can be reused later), k (number of passes) and e (evocation count for hwTripleExponentialSmoothing).

func HWTripleExponentialSmoothing

func HWTripleExponentialSmoothing(data []float64, slen int, trend float64, seasonal []float64, nPredictions int, α, β, γ float64) ([]float64, []float64, float64)

HWTripleExponentialSmoothing performs triple exponential smoothing (multiplicative) on data given season length slen (in number of data points per season), initial trend, slice of initial seasonal factors, the number of forecasted points and smoothing factors α, β, γ. It returns a new slice of smoothed and forcasted data points, a slice of deviations such that y±y*d could be used as "confidence bands" as well as SSE (Sum of Squared Errors).You can obtain trend and seasonal from hwInitialTrendFactor and hwInitialSeasonalFactors. Best α, β and γ can be calculated by repeatedly calling hwTripleExponentialSmoothing to find the combination with the smallest SSE, you can use hwMinimiseSSE for this.

func Quantile

func Quantile(list []float64, p float64) float64

Given a series as a []float64, returns the value below which p fraction of all the values falls. (0 < p < 1).

Types

type RLocker

type RLocker interface {
	RLock()
	RUnlock()
}

type RRASeries

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

RRASeries transforms a rrd.RoundRobinArchiver into a Series.

func NewRRASeries

func NewRRASeries(rra rrd.RoundRobinArchiver) *RRASeries

func (*RRASeries) Alias

func (s *RRASeries) Alias(a ...string) string

func (*RRASeries) Close

func (s *RRASeries) Close() error

func (*RRASeries) CurrentTime

func (s *RRASeries) CurrentTime() time.Time

func (*RRASeries) CurrentValue

func (s *RRASeries) CurrentValue() float64

func (*RRASeries) GroupBy

func (s *RRASeries) GroupBy(td ...time.Duration) time.Duration

func (*RRASeries) Latest

func (s *RRASeries) Latest() time.Time

func (*RRASeries) MaxPoints

func (s *RRASeries) MaxPoints(n ...int64) int64

func (*RRASeries) Next

func (s *RRASeries) Next() bool

func (*RRASeries) Step

func (s *RRASeries) Step() time.Duration

func (*RRASeries) TimeRange

func (s *RRASeries) TimeRange(t ...time.Time) (time.Time, time.Time)

type Series

type Series interface {
	// Advance to the next data point in the series. Returns false if
	// no further advancement is possible.
	Next() bool

	// Resets the internal cursor and closes all underlying
	// cursors. After Close(), Next() should start from the beginning.
	Close() error

	// The current data point value. If called before Next(), or after
	// Next() returned false, should return a NaN.
	CurrentValue() float64

	// The time on which the current data point ends. The next slot begins
	// immediately after this time.
	CurrentTime() time.Time

	// The step of the series.
	Step() time.Duration

	// Signals the underlying storage to group rows by this interval,
	// resulting in fewer (and longer) data points. The values are
	// aggregated using average. By default it is equal to Step.
	// Without arguments returns the value, with an argument sets and
	// returns the previous value.
	GroupBy(...time.Duration) time.Duration

	// Restrict the series to (a subset of) its span. Without
	// arguments returns the value, with arguments sets and returns
	// the previous value. In the ideal case a series should be
	// iterable over the set range regardless of whether underlying
	// storage has data, i.e. when there is no data, we get a value of
	// NaN, but Next returns true over the entire range.
	TimeRange(...time.Time) (time.Time, time.Time)

	// Timestamp of the last data point in the series.
	// TODO is series.Latest() necessary even?
	Latest() time.Time

	// Alternative to GroupBy(), with a similar effect but based on
	// the maximum number of points we expect to receive. MaxPoints is
	// ignored if GroupBy was set.
	// Without arguments returns the value, with an argument sets and
	// returns the previous value.
	MaxPoints(...int64) int64
}

type SeriesSlice

type SeriesSlice []Series

A slice of series which implements the Series interface (almost). SeriesSlice is an "abstract" Series because it purposely does not implement CurrentValue(). It is used for bunching Series together for cross-series aggregation. A call to Next(), Close() etc will call respective methods on all series in the slice.

func (SeriesSlice) Align

func (sl SeriesSlice) Align()

Computes the least common multiple of the steps of all the series in the slice and calls GroupBy with this value thereby causing all series to be of matching resolution (i.e. aligned on data point timestamps). Generally you should always Align() the series slice before iterting over it.

func (SeriesSlice) Avg

func (sl SeriesSlice) Avg() float64

Returns the simple average of all the current values in the series in the slice.

func (SeriesSlice) Close

func (sl SeriesSlice) Close() error

Closes all series in the slice. First error encountered is returned and the rest of the series is not closed.

func (SeriesSlice) CurrentTime

func (sl SeriesSlice) CurrentTime() time.Time

Returns CurrentTime of the first series in the slice or zero time if slice is empty.

func (SeriesSlice) Diff

func (sl SeriesSlice) Diff() float64

Starting with the current value of the series, subtract the remaining values and return the result.

func (SeriesSlice) First

func (sl SeriesSlice) First() float64

Returns the current value of the first series in the slice. (The ordering of series is up to the implementation).

func (SeriesSlice) GroupBy

func (sl SeriesSlice) GroupBy(ms ...time.Duration) time.Duration

func (SeriesSlice) Latest

func (sl SeriesSlice) Latest() time.Time

Returns Latest() for the first series in the slice or zero time if slice is empty.

func (SeriesSlice) Max

func (sl SeriesSlice) Max() float64

Returns the max of all the current values in the series in the slice.

func (SeriesSlice) MaxPoints

func (sl SeriesSlice) MaxPoints(n ...int64) int64

With argument sets MaxPoints on all series in the slice, without argument returns MaxPoints of the first series in the slice or 0 if slice is empty.

func (SeriesSlice) Min

func (sl SeriesSlice) Min() float64

Returns the min of all the current values in the series in the slice.

func (SeriesSlice) Next

func (sl SeriesSlice) Next() bool

func (SeriesSlice) Prod

func (sl SeriesSlice) Prod() (result float64)

Returns the product of all the current values in the series in the slice.

func (SeriesSlice) Quantile

func (sl SeriesSlice) Quantile(p float64) float64

Returns the p-th quantile (0 < p < 1) of the current values of the series in the slice.

func (SeriesSlice) Range

func (sl SeriesSlice) Range() float64

Returns the difference between max and min of all the current values of the series in the slice.

func (SeriesSlice) Step

func (sl SeriesSlice) Step() time.Duration

Returns the step of the first series in the slice or 0 if slice is empty.

func (SeriesSlice) Sum

func (sl SeriesSlice) Sum() (result float64)

Returns the arithmetic sum of all the current values in the series in the slice.

func (SeriesSlice) TimeRange

func (sl SeriesSlice) TimeRange(t ...time.Time) (time.Time, time.Time)

type SliceSeries

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

SliceSeries is a Series based on a simple []float64.

func NewSliceSeries

func NewSliceSeries(data []float64, start time.Time, step time.Duration) *SliceSeries

func (*SliceSeries) Alias

func (s *SliceSeries) Alias(a ...string) string

func (*SliceSeries) Close

func (s *SliceSeries) Close() error

func (*SliceSeries) CurrentTime

func (s *SliceSeries) CurrentTime() time.Time

func (*SliceSeries) CurrentValue

func (s *SliceSeries) CurrentValue() float64

func (*SliceSeries) GroupBy

func (s *SliceSeries) GroupBy(...time.Duration) time.Duration

func (*SliceSeries) Latest

func (s *SliceSeries) Latest() time.Time

func (*SliceSeries) MaxPoints

func (s *SliceSeries) MaxPoints(...int64) int64

func (*SliceSeries) Next

func (s *SliceSeries) Next() bool

func (*SliceSeries) Step

func (s *SliceSeries) Step() time.Duration

func (*SliceSeries) TimeRange

func (s *SliceSeries) TimeRange(...time.Time) (time.Time, time.Time)

type SummarySeries

type SummarySeries struct {
	Series
}

SummarySeries provides some whole-series summary functions, e.g. Max(), Avg(), StdDev(), etc. (Not to be confused with the cross-series aggregation SeriesSlice provides). Note that all of these function require iterating over the entire series.

func (*SummarySeries) Avg

func (f *SummarySeries) Avg() float64

Returns the simple average of all the values in the series.

func (*SummarySeries) Last

func (f *SummarySeries) Last() (last float64)

Returns the last value in the series.

func (*SummarySeries) Max

func (f *SummarySeries) Max() (max float64)

Returns the max of all the values in the series.

func (*SummarySeries) Min

func (f *SummarySeries) Min() (min float64)

Returns the min of all the values in the series.

func (*SummarySeries) StdDev

func (f *SummarySeries) StdDev(avg float64) float64

Returns the standard deviation of all the values in the series.

Jump to

Keyboard shortcuts

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