Skip to content

KEINOS/go-bayes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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