asiffer / gospot

Go implementation of libspot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

gospot Build Test Go Report Card Coverage Status GoDoc

gospot does not provide Go bindings to libspot anymore. It is merely a pure golang implementation of libspot.

Download

$ go get github.com/asiffer/gospot

Usage

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

// example.go

package main

import (
    "fmt"
    "math/rand"
    "time"

    "github.com/asiffer/gospot"
)

func gaussianSample(N int) []float64 {
	rand.Seed(time.Now().UTC().UnixNano())
	data := make([]float64, N)
	for i := 0; i < N; i++ {
		data[i] = rand.NormFloat64()
	}
	return data
}

func main() {
    config := gospot.SpotConfig{
		Q:         1e-4,
		Ninit:     5000,
		Level:     0.99,
		Up:        true,
		Down:      true,
		Alert:     false,
		Bounded:   true,
		MaxExcess: 200}

    spot := gospot.NewSpotFromConfig(config)
    
    N := 80000
    data := gaussianSample(N)

    for i := 0; i < N; i++ {
	    spot.Step(data[i])
    }
    
    fmt.Println(spot.Status())
}

This example outputs the status of the Spot instance after 80000 gaussian observations. Here the alert mode is not activated, so no alarm is raised.

$ go run example.go
       n 80000
   ex_up 200
 ex_down 200
   Nt_up 816
 Nt_down 774
   al_up 0
 al_down 0
    t_up 2.317529
  t_down -2.352898
    z_up 3.834334
  z_down -3.831503

About

Go implementation of libspot

License:GNU General Public License v3.0


Languages

Language:Go 100.0%