Code Monkey home page Code Monkey logo

go-bayes's Introduction

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

go-bayes's People

Contributors

dependabot[bot] avatar keinos avatar

Stargazers

 avatar

Watchers

 avatar  avatar

go-bayes's Issues

use xxhash instead of blake3

The hash, BLAKE3, in this package is used to label the class which is not necessary to be cryptographically secure.

Use xxHash3 which is faster and lesser overhead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.