Giter Club home page Giter Club logo

pgmpy's Introduction

pgmpy Build Status Coverage Status

Python Library for Probabilistic Graphical Models
Documentation: pgmpy
Mailing List: [email protected]
irc: #pgmpy on freenode.net

Dependencies:

  • Python 3.3
  • NetworkX 1.8.1
  • Scipy 0.12.1
  • Numpy 1.7.1
  • Cython 0.19 (optional)

Installation:

pgmpy is installed using distutils. If you have the tools installed to build a python extension module:

sudo python3 setup.py install

Example:

from pgmpy import BayesianModel as bm
student = bm.BayesianModel()
# instantiates a new Bayesian Model called 'student'

student.add_nodes_from(['diff', 'intel', 'grade'])
# adds nodes labelled 'diff', 'intel', 'grade' to student

student.add_edges_from([('diff', 'grade'), ('intel', 'grade')])
# adds directed edges from 'diff' to 'grade' and 'intel' to 'grade'

student.set_states({'diff': ['hard', 'easy']})
student.set_rule_for_states('diff', ['easy', 'hard'])
student.set_cpd('diff', [[0.2],[0.8]])
#easy=0.2
#hard=0.8

student.set_states({'intel': ['avg', 'dumb', 'smart']})
student.set_rule_for_states('intel', ['dumb', 'avg', 'smart'])
student.set_cpd('intel', [[0.5], [0.3], [0.2]]) 
#dumb=0.5
#avg=0.3
#smart=0.2

student.set_states({'grade': ['A','C','B']})
student.set_rule_for_parents('grade', ['diff', 'intel'])
student.set_rule_for_states('grade', ['A', 'B', 'C'])
student.set_cpd('grade',
                [[0.1,0.1,0.1,0.1,0.1,0.1],
                [0.1,0.1,0.1,0.1,0.1,0.1], 
                [0.8,0.8,0.8,0.8,0.8,0.8]]
                )

#diff:       easy                 hard
#intel: dumb   avg   smart    dumb  avg   smart
#gradeA: 0.1    0.1    0.1     0.1  0.1    0.1  
#gradeB: 0.1    0.1    0.1     0.1  0.1    0.1
#gradeC: 0.8    0.8    0.8     0.8  0.8    0.8

student.set_observations({'intel': 'smart', 'diff': 'easy'})
# observed parameters are that intel of student is smart and
# difficulty is easy

student.reset_observations('intel')
# reset observations for intel

active_trail = student.is_active_trail('grade', 'intel')
# returns True if active trail exists between grade and intel

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.