Git Product home page Git Product logo

inference-engine-with-bayesian-networks's Introduction

Inference Engine with Bayesian Networks

Generic inference engine using inference by enumeration with Bayesian networks. Implemented in Python using the Pomegranate framework.

Authors

Table of Contents

Overview

A Bayesian network is a probabilistic model that represents a set of variables and their conditional dependencies through a directed acyclic graph. Given an event, the likelihood that such an event occurred as a result of one or more known causes can be inferred from a Bayesian network. For example, Bayesian networks could represent the probabilistic relationships between diseases and symptoms: given symptoms S1, ..., Sn, a model can be used to calculate the probability of the presence of a disease D as a query Q = P(D | S1, ..., Sn).

This project provides a generic inference engine using inference by enumeration with Bayesian networks. It receives a JSON file with the probabilities associated with each node on the network as input, and then writes the probability assigned to the query to an output JSON file.

Installation

Install from this repository:

git clone https://github.com/hreyesm/inference-engine-with-bayesian-networks

The script was tested in an Anaconda environment running on MacOS.

Requirements

Usage

After cloning the repository, enter the following terminal command to run the Python script:

python3 engine.py <input JSON file>

Please note that <input JSON file> should be replaced with a JSON file that contains a valid Bayesian network topology (see example).

Example

Consider a Bayesian network from which the probability assigned to the query Q = P(G|R-S) is to be inferred, that is, the probability that the grass is wet (G) given that it rained (R) and there was no sprinkler (-S):

Example input

For the above topology, a valid input JSON file would look like the following:

[
  {
    "R": 0.2
  },

  {
    "S|R": 0.01,
    "S|-R": 0.4
  },

  {
    "G|RS": 0.99,
    "G|R-S": 0.8,
    "G|-RS": 0.9,
    "G|-R-S": 0.0
  },

  {
    "BELIEF": "R"
  },

  {
    "BELIEF": "-S"
  },

  {
    "QUERY": "G"
  }
]

The example_input.json file already contains this topology, so when the command python3 engine.py example_input.json is run, the probability assigned to the query Q = P(G|R-S) would be written to an output JSON file "G|R-S.json" as follows:

{"-G": 0.20000000000000007, "G": 0.7999999999999999}

Thus, the probability that the grass is wet (G) given that it rained (R) and there was no sprinkler (-S) is 80%.

License

The code of this repository was implemented by Héctor Reyes and Daniela Vignau. Released under the MIT license.

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.