Categorygithub.com/KEINOS/go-bayes
modulepackage
0.0.3
Repository: https://github.com/keinos/go-bayes.git
Documentation: pkg.go.dev

# README

Go Version Go Reference

go-bayes

github.com/KEINOS/go-bayes is a Go package for Bayesian inference.

Usage

# Download the module
go get github.com/KEINOS/go-bayes
// Import the package
import "github.com/KEINOS/go-bayes"
package main

import (
	"fmt"
	"log"

	"github.com/KEINOS/go-bayes"
)

func Example() {
    // "Happy Birthday", the train data. The types of slices available for the
    // training are as follows:
    //   bool, int, int16-int64, uint, uint16-uint64, float32, float64, string.
    score := []string{
        "So", "So", "La", "So", "Do", "Si",
        "So", "So", "La", "So", "Re", "Do",
        "So", "So", "So", "Mi", "Do", "Si", "La",
        "Fa", "Fa", "Mi", "Do", "Re", "Do",
    }

    // Reset the trained model
    bayes.Reset()

    // Train
    if err := bayes.Train(score); err != nil {
        log.Fatal(err)
    }

    // Predict the next note from the introduction notes
    for _, intro := range [][]string{
        {"So", "So", "La", "So", "Do", "Si"},             // --> So
        {"So", "So", "La", "So", "Do", "Si", "So", "So"}, // --> La
        {"So", "So", "La"},                               // --> So
        {"So", "So", "So"},                               // --> Mi
    } {
        nextNoteID, err := bayes.Predict(intro)
        if err != nil {
            log.Fatal(err)
        }

        // Print the predicted next note
        nextNoteString := bayes.GetClass(nextNoteID)

        fmt.Printf("Next is: %v (Class ID: %v)\n", nextNoteString, nextNoteID)
    }

    // Output:
    // Next is: So (Class ID: 10062876669317908741)
    // Next is: La (Class ID: 17627200281938459623)
    // Next is: So (Class ID: 10062876669317908741)
    // Next is: Mi (Class ID: 6586414841969023711)
}

Examples

Contribute

unit-test golangci-lint codecov CodeQL Go Report Card

  • Any PullRequest for improvement are welcome!
  • Branch to PR: main
    • Draft PR before full implementation is recommended.
  • We will merge any PR for the better, as long as it passes the CIs and not a prank-kind commit. ;-)

License


Wishlist/Todo

  • 100% code coverage for the current implementation
  • fix all golangci-lint issues for the current implementation
  • vulnerability scanning with CodeQL
  • feat CIs with GitHub Actions
  • feat benchmarking
  • feat dumping the trained model to a file
  • testdata with big sized data
  • SQLite3 as a storage backend (implementation of NodeLogger with SQLite3)
  • more examples of use cases
  • simple command tool to train and predict

# Packages

No description provided by the author

# Functions

GetClass returns the original value of the given class ID.
HashTrans returns a unique hash from the input transitions.
New returns a new NodeLogger instance.
Predict returns the next class ID inferred from the given items.
Reset resets the train object.
SetStorage sets the storage used by the predictor.
Train trains the predictor with the given items.

# Constants

MemoryStorage represents the in-memory storage.
ScopeIDDefault is the default scope ID on creating an instance of the predictor.
SQLite3Storage represents the SQLite3 as a storage.
StorageDefault is the default storage used by the predictor.
UnknwonStorage represents the unknown storage.

# Interfaces

NodeLogger is an interface to log the node's state.

# Type aliases

Storage is the type of storage to log the accesses.