Code Monkey home page Code Monkey logo

bayesiannetwork's Introduction

GoBayesianNetwork

BayesianNetwork

Example

Building an example graph:

package main

import (
  . "github.com/paddie/BayesianNetwork"
  "fmt"
)

e := NewRootNode("E", 0.3)
i := NewRootNode("I", 0.7)
d := NewRootNode("D", 0.2)

pDist := map[string]float64{
  "TTT": 0.9,
  "TFF": 0.2,
	"TTF": 0.5,
	"TFT": 0.7,
	"FTT": 0.8,
	"FFF": 0.07,
	"FTF": 0.6,
	"FFT": 0.7,
}

p := NewNode("P", []string{"E", "I", "D"}, pDist)

rDist := map[string]float64{
	"TT": 0.9,
	"FF": 0.2,
	"TF": 0.6,
	"FT": 0.9,
}

r := NewNode("R", []string{"I", "D"}, rDist)

jDist := map[string]float64{
	"T": 0.7,
	"F": 0.3,
}
j := NewNode("J", []string{"P"}, jDist)

uDist := map[string]float64{
	"TT": 0.9,
	"FF": 0.3,
	"TF": 0.6,
	"FT": 0.8,
}

u := NewNode("U", []string{"P", "R"}, uDist)

bn := NewBayesianNetwork(e, i, d, p, r, j, u)

stats := bn.AncestralSampling(10000)
fmt.Println(stats)

Output:

map[E:[0.3007 0.6993] I:[0.7044 0.2956] D:[0.2054 0.7946] P:[0.5013 0.4987] R:[0.5601 0.4399] J:[0.4988 0.5012] U:[0.6611 0.3389]]

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.