Skip to content

asiffer/gospot

Repository files navigation

gospot

Test Go Report Card Coverage Status GoDoc

gospot is a pure golang implementation of libspot. This module roughly follows the same structure.

Caution

The last version (v0.2) includes many breaking changes. If your project cannot be migrated, you can still points to the previous one: go get github.com/asiffer/gospot@v0.1.1

Download

$ go get github.com/asiffer/gospot

Usage

Once gospot is imported, you can create a Spot object and feed some data.

package main

import (
	"math/rand"

	"github.com/asiffer/gospot"
)

func gaussian(size uint64) <-chan float64 {
	out := make(chan float64, 1)
	go func() {
		for i := uint64(0); i < size; i++ {
			out <- rand.NormFloat64()
		}
		close(out)
	}()
	return out
}

func gaussianBatch(size uint64) []float64 {
	out := make([]float64, size)
	k := 0
	for x := range gaussian(size) {
		out[k] = x
		k++
	}
	return out
}

func main() {
	s, err := gospot.NewSpot(1e-5, false, true, 0.99, 2000)
	if err != nil {
		panic(err)
	}
	data := gaussianBatch(10_000)
	s.Fit(data)

	A := 0
	E := 0
	N := 0

	for x := range gaussian(1_000_000) {
		switch s.Step(x) {
		case gospot.ANOMALY:
			A++
		case gospot.EXCESS:
			E++
		default:
			N++
		}
	}

	fmt.Printf("ANOMALY:%d EXCESS:%d NORMAL:%d\n", A, E, N)
}

About

Go implementation of libspot

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages