Skip to main content

pyAgrum is a Python wrapper for the C++ aGrUM library

Project description

pyAgrum

pyAgrum is a Python wrapper for the Agrum library, to make flexible and scalable probabilistic graphical models for inference and diagnosis.

Sample code:

import pyAgrum as gum

bn=gum.BayesNet('WaterSprinkler')
print(bn)

Example

import pyAgrum as gum

# Creating BayesNet with 4 variables
bn=gum.BayesNet('WaterSprinkler')
print(bn)
# Adding nodes the long way
c=bn.add(gum.LabelizedVariable('c','cloudy ?',2))
print(c)
# Adding nodes the short way
s, r, w = [ bn.add(name, 2) for name in "srw" ]
print (s,r,w)
print (bn)
# Addings arcs c -> s, c -> r, s -> w, r -> w
bn.addArc(c,s)
for link in [(c,r),(s,w),(r,w)]:
  bn.addArc(*link)
print(bn)
# Filling CPTs
bn.cpt(c).fillWith([0.5,0.5])
bn.cpt(s)[0,:]=0.5 # equivalent to [0.5,0.5]
bn.cpt(s)[1,:]=[0.9,0.1]
bn.cpt(w)[0,0,:] = [1, 0] # r=0,s=0
bn.cpt(w)[0,1,:] = [0.1, 0.9] # r=0,s=1
bn.cpt(w)[1,0,:] = [0.1, 0.9] # r=1,s=0
bn.cpt(w)[1,1,:] = [0.01, 0.99] # r=1,s=1
bn.cpt(r)[{'c':0}]=[0.8,0.2]
bn.cpt(r)[{'c':1}]=[0.2,0.8]
# Saving BN as a BIF file
gum.saveBN(bn,"WaterSprinkler.bif")
# Loading BN from a BIF file
bn2=gum.loadBN("WaterSprinkler.bif")
# Inference
ie=gum.LazyPropagation(bn)
ie.makeInference()
print (ie.posterior(w))
# Adding evidence
ie.setEvidence({'s': 1, 'c': 0})
ie.makeInference()
print(ie.posterior(w))
ie.setEvidence({'s': [0, 1], 'c': [1, 0]})
ie.makeInference()
print(ie.posterior(w))

LICENSE

Copyright (C) 2005,2019 by Pierre-Henri WUILLEMIN et Christophe GONZALES {prenom.nom}_at_lip6.fr

The aGrUM/pyAgrum library and all its derivatives are distributed under the LGPL3 license, see https://www.gnu.org/licenses/lgpl-3.0.en.html.

Authors

  • Pierre-Henri Wuillemin

  • Christophe Gonzales

Maintainers

  • Lionel Torti

  • Gaspard Ducamp

Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyAgrum-0.15.0-cp37-cp37m-win_amd64.whl (2.5 MB view hashes)

Uploaded CPython 3.7m Windows x86-64

pyAgrum-0.15.0-cp37-cp37m-win32.whl (1.8 MB view hashes)

Uploaded CPython 3.7m Windows x86

pyAgrum-0.15.0-cp37-cp37m-manylinux1_x86_64.whl (4.3 MB view hashes)

Uploaded CPython 3.7m

pyAgrum-0.15.0-cp37-cp37m-manylinux1_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.7m

pyAgrum-0.15.0-cp37-cp37m-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

pyAgrum-0.15.0-cp36-cp36m-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.6m Windows x86-64

pyAgrum-0.15.0-cp36-cp36m-win32.whl (1.7 MB view hashes)

Uploaded CPython 3.6m Windows x86

pyAgrum-0.15.0-cp36-cp36m-manylinux1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.6m

pyAgrum-0.15.0-cp36-cp36m-manylinux1_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.6m

pyAgrum-0.15.0-cp36-cp36m-macosx_10_7_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.6m macOS 10.7+ x86-64

pyAgrum-0.15.0-cp35-cp35m-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.5m Windows x86-64

pyAgrum-0.15.0-cp35-cp35m-win32.whl (1.7 MB view hashes)

Uploaded CPython 3.5m Windows x86

pyAgrum-0.15.0-cp35-cp35m-manylinux1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.5m

pyAgrum-0.15.0-cp35-cp35m-manylinux1_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.5m

pyAgrum-0.15.0-cp35-cp35m-macosx_10_6_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.5m macOS 10.6+ x86-64

pyAgrum-0.15.0-cp34-cp34m-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 3.4m Windows x86-64

pyAgrum-0.15.0-cp34-cp34m-win32.whl (1.7 MB view hashes)

Uploaded CPython 3.4m Windows x86

pyAgrum-0.15.0-cp34-cp34m-manylinux1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 3.4m

pyAgrum-0.15.0-cp34-cp34m-manylinux1_i686.whl (4.2 MB view hashes)

Uploaded CPython 3.4m

pyAgrum-0.15.0-cp34-cp34m-macosx_10_6_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 3.4m macOS 10.6+ x86-64

pyAgrum-0.15.0-cp27-cp27mu-manylinux1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 2.7mu

pyAgrum-0.15.0-cp27-cp27mu-manylinux1_i686.whl (4.1 MB view hashes)

Uploaded CPython 2.7mu

pyAgrum-0.15.0-cp27-cp27m-win_amd64.whl (2.4 MB view hashes)

Uploaded CPython 2.7m Windows x86-64

pyAgrum-0.15.0-cp27-cp27m-win32.whl (1.7 MB view hashes)

Uploaded CPython 2.7m Windows x86

pyAgrum-0.15.0-cp27-cp27m-manylinux1_x86_64.whl (4.2 MB view hashes)

Uploaded CPython 2.7m

pyAgrum-0.15.0-cp27-cp27m-manylinux1_i686.whl (4.1 MB view hashes)

Uploaded CPython 2.7m

pyAgrum-0.15.0-cp27-cp27m-macosx_10_6_x86_64.whl (3.4 MB view hashes)

Uploaded CPython 2.7m macOS 10.6+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page