Documentation ¶
Overview ¶
Package timeseries provides utilities to manipulate and analyze timeseries data. For compatability with Gonum, a Timeseries is simply a pair of float64 slices, representing the X and the Y axis. You can manipulate them as you wish, but ensure two things:
- Many of the methods in this library assume that the data is sorted. If you do not insert in sorted order, ensure that you call Sort()
- Ensure that Timeseries.Xs and Timeseries.Ys is always of equal length if you manipulate them without the accessors provided
Index ¶
- type Timeseries
- func (t Timeseries) After(x float64) Timeseries
- func (t *Timeseries) Append(x float64, y float64)
- func (t Timeseries) At(i int) (x, y float64)
- func (t Timeseries) Before(x float64) Timeseries
- func (t Timeseries) Between(x1, x2 float64) Timeseries
- func (t Timeseries) Difference() (ret Timeseries)
- func (t Timeseries) Equal(other Timeseries) bool
- func (t Timeseries) First() (x, y float64)
- func (t Timeseries) Last() (x, y float64)
- func (t Timeseries) Len() int
- func (t Timeseries) Less(i, j int) bool
- func (t Timeseries) LinearRegression() (alpha, beta, rmse float64)
- func (t Timeseries) MovingAverage(window int) (ret Timeseries)
- func (t Timeseries) Slice(start, end int) Timeseries
- func (t Timeseries) Sort()
- func (t Timeseries) Swap(i, j int)
- func (t Timeseries) WeightedLinearRegression(weights []float64) (alpha, beta, rmse float64)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Timeseries ¶
func (Timeseries) After ¶
func (t Timeseries) After(x float64) Timeseries
After - Return a shallow copy of the items in the time series having Xs >= x The series must be sorted.
func (*Timeseries) Append ¶
func (t *Timeseries) Append(x float64, y float64)
Append - Append value @ time to the timeseries Note that you might need a sort if you're inserting points out-of-order
func (Timeseries) At ¶
func (t Timeseries) At(i int) (x, y float64)
At - return the x, y pair at index i If i does not represent a valid index, At panics
func (Timeseries) Before ¶
func (t Timeseries) Before(x float64) Timeseries
Before - Return a shallow copy of the items in the time series having Xs < x. The series must be sorted.
func (Timeseries) Between ¶
func (t Timeseries) Between(x1, x2 float64) Timeseries
Between - Return a shallow copy of the items in the time series between [x1, x2)
func (Timeseries) Difference ¶
func (t Timeseries) Difference() (ret Timeseries)
Difference the timeseries N, returning a new series of length len(N)-1
func (Timeseries) Equal ¶
func (t Timeseries) Equal(other Timeseries) bool
Equal - Return true if t and other represent the same time series
func (Timeseries) First ¶
func (t Timeseries) First() (x, y float64)
First - Return the first x, y value of the timeseries. If the timeseries contains no items, First() panics.
func (Timeseries) Last ¶
func (t Timeseries) Last() (x, y float64)
Last - Return the last x, y value of the timeseries. If the timeseries contains no items, Last() panics.
func (Timeseries) Len ¶
func (t Timeseries) Len() int
Len - return the lenght of the timeseries. If len(Timeseries.Xs) != len(Timeseries.Ys), Len() panics
func (Timeseries) Less ¶
func (t Timeseries) Less(i, j int) bool
func (Timeseries) LinearRegression ¶
func (t Timeseries) LinearRegression() (alpha, beta, rmse float64)
SimpleLinearRegression performs a simple linear regression of the series computing the best fit line
y = alpha + beta*x
such that rmse is minimized
func (Timeseries) MovingAverage ¶
func (t Timeseries) MovingAverage(window int) (ret Timeseries)
MovingAverage returns a time series representing the window-sized moving average over t
func (Timeseries) Slice ¶
func (t Timeseries) Slice(start, end int) Timeseries
Slice slices the Timeseries equivalently to t[start:end]
func (Timeseries) Sort ¶
func (t Timeseries) Sort()
func (Timeseries) Swap ¶
func (t Timeseries) Swap(i, j int)
func (Timeseries) WeightedLinearRegression ¶
func (t Timeseries) WeightedLinearRegression(weights []float64) (alpha, beta, rmse float64)
WeightedLinearRegression performs a weighted linear regression of the series computing the best fit line
y = alpha + beta*x
such that rmse is minimized