gosax

package module
v0.0.0-...-9d66e60 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: Apache-2.0 Imports: 4 Imported by: 0

README

GoSax

High performance golang implementation of Symbolic Aggregate approXimation
Time Series Classification and Clustering with Golang

Based on the paper A Symbolic Representation of Time Series, with Implications for Streaming Algorithms

A Symbolic Representation of Time Series, with Implications for
Streaming Algorithms
Jessica Lin Eamonn Keogh Stefano Lonardi Bill Chiu
University of California - Riverside
Computer Science & Engineering Department
Riverside, CA 92521, USA
{jessica, eamonn, stelo, bill}@cs.ucr.edu

Keywords
Time Series, Data Mining, Data Streams, Symbolic, Discretize

Usage


package main

import "github.com/artpar/gosax"


func main(){
  long_arr := []float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 10, 100}
  // sax, _ := gosax.NewSax(wordSize, alphabetSize, epsilon)
  sax, err := gosax.NewSax(6, 5, 1e-6)
  // check for error before proceding

  letters, _ := sax.ToLetterRepresentation(long_arr)
  t.Logf("%v == bbbbce", letters)
}

Benchmark

BenchmarkLongToLetterRep-4   	  500000	      3586 ns/op
BenchmarkSlidingWindow-4       	  200000	     11074 ns/op

Parameters

  • WordSize
  • AlphabetSize
  • Epsilon

If you want to compare x1 and x2 (lists of values):

x1String, x1Indices = sax.ToLetterRepresentation(x1)
x2String, x2Indices = sax.ToLetterRepresentation(x2)

x1x2ComparisonScore = s.CompareStrings(x1String, x2String)

If you want to use the sliding window functionality:

(say you want to break x3 into a lot of subsequences)

can optionally specify the number of subsequences and how much each subsequence overlaps with the previous subsequence

x3Strings, x3Indices = sax.SlidingWindow(x3, numSubsequences, overlappingFraction)

Then if you wanted to compare each subsequence to another string (say x2):

x3x2ComparisonScores = s.BatchCompare(x3,x2)
Note:

If you haven't generated the strings through the same SAX object, the scaling factor (square root of the length of the input vector over the word size) will be incorrect, you can correct it using:

sax.SetScalingFactor(scalingFactor)
Tests
go test
Benchmark:
go test -bench=.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDictionarySizeIsNotSupported = errors.New("Dictionary size not supported")
View Source
var ErrOverlapSpecifiedIsNotSmallerThanWindowSize = errors.New("OverlapSpecifiedIsNotSmallerThanWindowSize")
View Source
var ErrStringsAreDifferentLength = errors.New("StringsAreDifferentLength")

Functions

This section is empty.

Types

type Sax

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

func NewSax

func NewSax(wordSize int, alphabetSize int, epsilon float64) (*Sax, error)

func (*Sax) BatchCompare

func (self *Sax) BatchCompare(xStrings []string, refString string) []float64

func (*Sax) CompareStrings

func (self *Sax) CompareStrings(list_letters_a, list_letters_b []byte) (float64, error)

Compares two strings based on individual letter distance Requires that both strings are the same length

func (*Sax) SetScalingFactor

func (self *Sax) SetScalingFactor(scalingFactor float64)

func (*Sax) SetWindowSize

func (self *Sax) SetWindowSize(windowSize int)

func (*Sax) SlidingWindow

func (self *Sax) SlidingWindow(x []float64, numSubsequences int, overlappingFraction float64) (string, [][]int, error)

func (*Sax) ToLetterRepresentation

func (self *Sax) ToLetterRepresentation(x []float64) (string, [][]int)

Function takes a series of data, x, and transforms it to a string representation

Jump to

Keyboard shortcuts

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