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 ¶
- func HWInitialSeasonalFactors(data []float64, slen int) ([]float64, error)
- func HWInitialTrendFactor(data []float64, slen int) (float64, error)
- func HWMinimizeSSE(data []float64, slen int, trend float64, seasonal []float64, nPred int) (smooth, dev []float64, α, β, γ float64, k, e int)
- func HWTripleExponentialSmoothing(data []float64, slen int, trend float64, seasonal []float64, nPredictions int, ...) ([]float64, []float64, float64)
- func Quantile(list []float64, p float64) float64
- type RLocker
- type RRASeries
- func (s *RRASeries) Alias(a ...string) string
- func (s *RRASeries) Close() error
- func (s *RRASeries) CurrentTime() time.Time
- func (s *RRASeries) CurrentValue() float64
- func (s *RRASeries) GroupBy(td ...time.Duration) time.Duration
- func (s *RRASeries) Latest() time.Time
- func (s *RRASeries) MaxPoints(n ...int64) int64
- func (s *RRASeries) Next() bool
- func (s *RRASeries) Step() time.Duration
- func (s *RRASeries) TimeRange(t ...time.Time) (time.Time, time.Time)
- type Series
- type SeriesSlice
- func (sl SeriesSlice) Align()
- func (sl SeriesSlice) Avg() float64
- func (sl SeriesSlice) Close() error
- func (sl SeriesSlice) CurrentTime() time.Time
- func (sl SeriesSlice) Diff() float64
- func (sl SeriesSlice) First() float64
- func (sl SeriesSlice) GroupBy(ms ...time.Duration) time.Duration
- func (sl SeriesSlice) Latest() time.Time
- func (sl SeriesSlice) Max() float64
- func (sl SeriesSlice) MaxPoints(n ...int64) int64
- func (sl SeriesSlice) Min() float64
- func (sl SeriesSlice) Next() bool
- func (sl SeriesSlice) Prod() (result float64)
- func (sl SeriesSlice) Quantile(p float64) float64
- func (sl SeriesSlice) Range() float64
- func (sl SeriesSlice) Step() time.Duration
- func (sl SeriesSlice) Sum() (result float64)
- func (sl SeriesSlice) TimeRange(t ...time.Time) (time.Time, time.Time)
- type SliceSeries
- func (s *SliceSeries) Alias(a ...string) string
- func (s *SliceSeries) Close() error
- func (s *SliceSeries) CurrentTime() time.Time
- func (s *SliceSeries) CurrentValue() float64
- func (s *SliceSeries) GroupBy(...time.Duration) time.Duration
- func (s *SliceSeries) Latest() time.Time
- func (s *SliceSeries) MaxPoints(...int64) int64
- func (s *SliceSeries) Next() bool
- func (s *SliceSeries) Step() time.Duration
- func (s *SliceSeries) TimeRange(...time.Time) (time.Time, time.Time)
- type SummarySeries
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HWInitialSeasonalFactors ¶
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 ¶
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.
Types ¶
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) CurrentTime ¶
func (*RRASeries) CurrentValue ¶
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) 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.
type SliceSeries ¶
type SliceSeries struct {
// contains filtered or unexported fields
}
SliceSeries is a Series based on a simple []float64.
func NewSliceSeries ¶
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) 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
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.