analytics

package module
v0.0.0-...-27445d7 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2016 License: MIT Imports: 7 Imported by: 1

README

analytics

Analytics and curve fitting library in go.
The library provides a Series structure that can be initialized with two []float64 containing x/y data.
Once initialized, functions can be applied to create new Series, or curve fitting can be applied to interpolate or (depending on the algorithm) extrapolate data points.

Simple example usage:

	//Define a small dataset
	x := []float64{1, 2, 3, 4, 5, 6, 7, 8}
	y := []float64{8, 6, 5, 5, 4, 3, 3, 2}
	
	//Use the dataset as a series
	series1 := analytics.NewSeriesFrom(x, y)

	//Get a 3rd Order Polynomial fit for the series
	fit := series1.FitPolynomial(3)

	//Display two interpolated/extrapolated points
	fmt.Println(analytics.Extrapolate(fit, 4))
	fmt.Println(analytics.Extrapolate(fit, 9))

	//Create smoothed version of the dataset
	series2 := series1.Smoother(3)

	//Display the underlying smoothed values
	x1, y1 := series2.ToArrays()
	fmt.Println(series2.x1)
	fmt.Println(series2.y1)

##General Data Manipulation Functions
Smoother - Iterative noise removal algorithm.
Pixelize - Quantization function.
MA - Moving average
EMA - Exponential moving average
LWMA - Linear weighted moving average
TrendChanges - Apex for peaks and troughs for smoothed data.
ApplyOffset - Move a series on x/y axes

##Data Splicing and Combining Functions
RecentTrends - Splices smoothed data into multiple series, each describing a trend.
Last - Extracts a copy of the last n points from the end of a series.
From - Extracts a copy of data points starting from an arbitrary x value.
Append - Joins two series together to form a new series.

##Financial Analysis Based Functions
ITrend - John Ehlers instantaneous trend (iTrend) indicator
CCI - Commodity Channel Index

##Misc Functions ToArrays - Extracts two 1D slices of values, one for x and one for y ToValues - As ToArrays, but takes an offset from the last datapoint

##Curve fit types Linear
Logarithmic
Exponential
Power
Polynomial (n-order)
Gaussian
Parabolic

##Todo Tests! (started) Fix up Gaussian fit (use scaling in addition to the offset) Fix up Parabolic fit (use scaling in addition to the offset)
Implement Cubic Spline
Cache sums for curve fit
Error handling

Documentation

Overview

Package analytics implements a library for the manipulation of x/y data series.

Index

Constants

View Source
const (
	FitTypeLinear = iota
	FitTypeLinearThroughOrigin
	FitTypeLogarithmic
	FitTypePower
	FitTypeExponential
	FitTypePolynomial
	FitTypeGaussian
	FitTypeParabolic
)

Variables

This section is empty.

Functions

func Extrapolate

func Extrapolate(params FitParameters, x float64) float64

Types

type FitParameters

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

type Series

type Series struct {
	Max  float64
	Min  float64
	Mean float64
	Len  int
	// contains filtered or unexported fields
}

func NewSeries

func NewSeries() *Series

Create a new series, and initialize it with a blank backing store

func NewSeriesFrom

func NewSeriesFrom(x []float64, y []float64) *Series

Create a new series from a slice of float64 slices

func (*Series) Add

func (ts *Series) Add(x float64, y float64)

Add a new value to the end of the series

func (*Series) Append

func (ts *Series) Append(toAdd *Series) *Series

Appends one series to another

func (*Series) ApplyOffset

func (ts *Series) ApplyOffset(x float64, y float64) *Series

Shifts a dataset on the x and y axes

func (*Series) Clear

func (ts *Series) Clear()

Clears the series, and initializes it with a blank backing store

func (*Series) CoefficientOfDetermination

func (ts *Series) CoefficientOfDetermination(pred *Series) float64

func (*Series) CommonChannelIndex

func (ts *Series) CommonChannelIndex(periodLength float64, numberOfPeriods int) *Series

func (*Series) Ema

func (ts *Series) Ema(period int) *Series

Exponential moving average

func (*Series) FitExponential

func (ts *Series) FitExponential() (params FitParameters)

func (*Series) FitGaussianParabolic

func (ts *Series) FitGaussianParabolic() (params []FitParameters)

func (*Series) FitLinear

func (ts *Series) FitLinear() (params FitParameters)

*

  • N * Σ(XY) - Σ(X)
  • intercept = ---------------------
  • N * Σ(X^2) - Σ(X)^2 *
  • correlation = N * Σ(XY) - Σ(X) * Σ (Y) / √ ( N * Σ(X^2) - Σ(X) ) * ( N * Σ(Y^2) - Σ(Y)^2 ) ) ) *

func (*Series) FitLinearThroughOrigin

func (ts *Series) FitLinearThroughOrigin() (params FitParameters)

func (*Series) FitLoess

func (ts *Series) FitLoess(bandwidth float64) (points *Series)

func (*Series) FitLogarithmic

func (ts *Series) FitLogarithmic() (params FitParameters)

func (*Series) FitPolynomial

func (ts *Series) FitPolynomial(order int) (params FitParameters)

func (*Series) FitPower

func (ts *Series) FitPower() (params FitParameters)

func (*Series) From

func (ts *Series) From(time float64) *Series

Creates a new series starting from the earliset point a particular time

func (*Series) ITrend

func (ts *Series) ITrend(alpha float64) (itrendSeries *Series)

iTrend

func (*Series) Last

func (ts *Series) Last(n int) *Series

Creates a new series containing the last n values.

func (*Series) Lwma

func (ts *Series) Lwma(period int) *Series

Linear weighted moving average

func (*Series) Ma

func (ts *Series) Ma(period int) *Series

Moving Average

func (*Series) MapReduce

func (ts *Series) MapReduce(mapFunction func(*Series) (float64, float64), reduceFunction func([]float64, []float64) *Series, periodLength float64, numberOfPeriods int) *Series

Applies two functions. The map function recieves a series representing a period, and returns a []float64. The reduce function takes the aggregated results and translates them into a series.

func (*Series) MeanDev

func (ts *Series) MeanDev() float64

Mean deviation

func (*Series) Point

func (ts *Series) Point(ordinal int) (x float64, y float64)

func (*Series) Quantize

func (ts *Series) Quantize(grid int) *Series

Quantization

func (*Series) RecentTrends

func (ts *Series) RecentTrends(n int) []*Series

Recent trends

func (*Series) Save

func (ts *Series) Save(name string)

func (*Series) SavePlot

func (ts *Series) SavePlot(path string, name string)

func (*Series) SearchX

func (ts *Series) SearchX(value float64) int

Uses binary search to find the earliest ordinal occurance of a x value.

func (*Series) Set

func (ts *Series) Set(ordinal int, value float64)

Set a value at the ordinal position in the series. Altering values that are outside the max/min of the existing data will cause the statistics for min, mean and max to be recalculated.

func (*Series) SetCap

func (ts *Series) SetCap(n int)

func (*Series) Slice

func (ts *Series) Slice(start int, end int) *Series

Slices a series - this is equivalent to go's slice

func (*Series) Smoother

func (ts *Series) Smoother(period int) *Series

Iterative Noise Removal

func (*Series) StDev

func (ts *Series) StDev() float64

Standard deviation

func (*Series) StandardError

func (ts *Series) StandardError(pred [][]float64) float64

func (*Series) ToArrays

func (ts *Series) ToArrays() (x []float64, y []float64)

Convert the data to a 1D array

func (*Series) ToValues

func (ts *Series) ToValues(length int, offset int) (x []float64, y []float64)

Extracts the values from the series as a 1 dimensional slice

func (*Series) TrendChanges

func (ts *Series) TrendChanges() *Series

Peak and trough data points

func (*Series) UpdateStats

func (ts *Series) UpdateStats()

Update stats: Min, Max, Mean, Sum

func (*Series) Use

func (ts *Series) Use(x []float64, y []float64)

Assign a new slice to the series, and initialize it.

Jump to

Keyboard shortcuts

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