Skip to main content

Bayesian networks and other Probabilistic Graphical Models.

Project description

pyAgrum

pyAgrum is a scientific C++ and Python library dedicated to Bayesian Networks and other Probabilistic Graphical Models. It provides a high-level interface to the part of aGrUM allowing to create, model, learn, use, calculate with and embed Bayesian Networks and other graphical models. Some specific (python and C++) codes are added in order to simplify and extend the aGrUM API.

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 ?',["Yes","No"]))
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)

# or, equivalenlty, creating the BN with 4 variables, and the arcs in one line
bn=gum.fastBN("w<-r<-c{Yes|No}->s->w")

# 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")[{"c":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")[{"r":1,"s":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 hard evidence
ie.setEvidence({"s": 1, "c": 0})
ie.makeInference()
print(ie.posterior("w"))

# Adding soft and hard evidence
ie.setEvidence({"s": [0.5, 1], "c": 0})
ie.makeInference()
print(ie.posterior("w"))

LICENSE

Copyright (C) 2005,2023 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-1.13.2-cp312-cp312-win_amd64.whl (2.7 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

pyAgrum-1.13.2-cp312-cp312-manylinux2014_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.12

pyAgrum-1.13.2-cp312-cp312-manylinux2014_aarch64.whl (5.4 MB view hashes)

Uploaded CPython 3.12

pyAgrum-1.13.2-cp312-cp312-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

pyAgrum-1.13.2-cp312-cp312-macosx_10_9_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

pyAgrum-1.13.2-cp311-cp311-win_amd64.whl (2.7 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyAgrum-1.13.2-cp311-cp311-manylinux2014_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.11

pyAgrum-1.13.2-cp311-cp311-manylinux2014_aarch64.whl (5.4 MB view hashes)

Uploaded CPython 3.11

pyAgrum-1.13.2-cp311-cp311-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pyAgrum-1.13.2-cp311-cp311-macosx_10_9_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

pyAgrum-1.13.2-cp310-cp310-win_amd64.whl (2.7 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyAgrum-1.13.2-cp310-cp310-manylinux2014_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.10

pyAgrum-1.13.2-cp310-cp310-manylinux2014_aarch64.whl (5.4 MB view hashes)

Uploaded CPython 3.10

pyAgrum-1.13.2-cp310-cp310-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pyAgrum-1.13.2-cp310-cp310-macosx_10_9_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

pyAgrum-1.13.2-cp39-cp39-win_amd64.whl (2.7 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyAgrum-1.13.2-cp39-cp39-manylinux2014_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.9

pyAgrum-1.13.2-cp39-cp39-manylinux2014_aarch64.whl (5.4 MB view hashes)

Uploaded CPython 3.9

pyAgrum-1.13.2-cp39-cp39-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pyAgrum-1.13.2-cp39-cp39-macosx_10_9_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

pyAgrum-1.13.2-cp38-cp38-win_amd64.whl (2.7 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyAgrum-1.13.2-cp38-cp38-manylinux2014_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.8

pyAgrum-1.13.2-cp38-cp38-manylinux2014_aarch64.whl (5.4 MB view hashes)

Uploaded CPython 3.8

pyAgrum-1.13.2-cp38-cp38-macosx_11_0_arm64.whl (4.2 MB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pyAgrum-1.13.2-cp38-cp38-macosx_10_9_x86_64.whl (4.7 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ 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