tgres: github.com/tgres/tgres/series Index | Files

package series

import "github.com/tgres/tgres/series"

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

Package Files

holtwinters.go neldermead.go rra_series.go series.go seriesslice.go slice_series.go summaryseries.go

func HWInitialSeasonalFactors Uses

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 Uses

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 Uses

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 Uses

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 Uses

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).

type RRASeries Uses

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

RRASeries transforms a rrd.RoundRobinArchiver into a Series.

func NewRRASeries Uses

func NewRRASeries(rra rrd.RoundRobinArchiver) *RRASeries

func (*RRASeries) Alias Uses

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

func (*RRASeries) Close Uses

func (s *RRASeries) Close() error

func (*RRASeries) CurrentTime Uses

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

func (*RRASeries) CurrentValue Uses

func (s *RRASeries) CurrentValue() float64

func (*RRASeries) GroupBy Uses

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

func (*RRASeries) Latest Uses

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

func (*RRASeries) MaxPoints Uses

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

func (*RRASeries) Next Uses

func (s *RRASeries) Next() bool

func (*RRASeries) Step Uses

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

func (*RRASeries) TimeRange Uses

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

type Series Uses

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.
    TimeRange(...time.Time) (time.Time, time.Time)

    // Timestamp of the last data point in the series.
    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 Uses

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 Uses

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 Uses

func (sl SeriesSlice) Avg() float64

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

func (SeriesSlice) Close Uses

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 Uses

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 Uses

func (sl SeriesSlice) Diff() float64

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

func (SeriesSlice) First Uses

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 Uses

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

func (SeriesSlice) Latest Uses

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 Uses

func (sl SeriesSlice) Max() float64

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

func (SeriesSlice) MaxPoints Uses

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 Uses

func (sl SeriesSlice) Min() float64

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

func (SeriesSlice) Next Uses

func (sl SeriesSlice) Next() bool

func (SeriesSlice) Quantile Uses

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 Uses

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 Uses

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 Uses

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

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

func (SeriesSlice) TimeRange Uses

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

type SliceSeries Uses

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

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

func NewSliceSeries Uses

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

func (*SliceSeries) Alias Uses

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

func (*SliceSeries) Close Uses

func (s *SliceSeries) Close() error

func (*SliceSeries) CurrentTime Uses

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

func (*SliceSeries) CurrentValue Uses

func (s *SliceSeries) CurrentValue() float64

func (*SliceSeries) GroupBy Uses

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

func (*SliceSeries) Latest Uses

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

func (*SliceSeries) MaxPoints Uses

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

func (*SliceSeries) Next Uses

func (s *SliceSeries) Next() bool

func (*SliceSeries) Step Uses

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

func (*SliceSeries) TimeRange Uses

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

type SummarySeries Uses

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 Uses

func (f *SummarySeries) Avg() float64

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

func (*SummarySeries) Last Uses

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

Returns the last value in the series.

func (*SummarySeries) Max Uses

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

Returns the max of all the values in the series.

func (*SummarySeries) Min Uses

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

Returns the min of all the values in the series.

func (*SummarySeries) StdDev Uses

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

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

Package series imports 5 packages (graph) and is imported by 2 packages. Updated 2017-03-23. Refresh now. Tools for package owners.