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.

Important

Since pyAgrum 2.0.0, the package name follows PEP8 rules and is now pyagrum (lowercase). Please use import pyagrum instead of import pyAgrum in your code.

See the CHANGELOG for more details.

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-2024 by Pierre-Henri WUILLEMIN et Christophe GONZALES {prenom.nom}_at_lip6.fr

The aGrUM/pyAgrum library and all its derivatives are distributed under the dual LGPLv3+MIT license, see LICENSE.LGPL and LICENSE.MIT.

You can therefore integrate this library into your software solution but it will remain covered by either the LGPL v.3 license or the MIT license or, as aGrUM itself, by the dual LGPLv3+MIT license at your convenience. If you wish to integrate the aGrUM library into your product without being affected by this license, please contact us (info@agrum.org).

This library depends on different third-party codes. See src/aGrUM/tools/externals for specific COPYING and explicit permission of the authors, if needed.

If you use aGrUM/pyAgrum as a dependency of your own project, you are not contaminated by the GPL license of some of these third-party codes as long as you use only their aGrUM/pyAgrum interfaces and not their native interfaces.

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

If you're not sure about the file name format, learn more about wheel file names.

pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-win_amd64.whl (4.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_11_0_arm64.whl (7.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_10_13_x86_64.whl (8.1 MB view details)

Uploaded CPython 3.10+macOS 10.13+ x86-64

File details

Details for the file pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6713fa4f59395cb2062d13597e407507e9fac32d353cb26940fbd2a77add72ac
MD5 4d8b0277460fffd0bb27cfb0af6806a9
BLAKE2b-256 011cd234d46011c3c0598f297be29a82833fae39f43ca4ba9969bd4cad4bdcd7

See more details on using hashes here.

File details

Details for the file pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d648aa48e03858bf377edcf6e06d0ba4726d9d83e3a59fa78df3c2833c6aaa96
MD5 76fdf4f8ac0d3269cd9706e5fc461395
BLAKE2b-256 912e294789cb56bc895fdcdcb7e11294f8f8d57634d5519924a42b875be786e7

See more details on using hashes here.

File details

Details for the file pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4118b5ba55b6dbfebfe3a75fb44dbd41106131fb8e8cfe0a62b3f98da125f9e6
MD5 548d89d0ee8e3d989749f3fb04037534
BLAKE2b-256 d3c927fe4360d9f977a5c90a55b8e63a5da109c6aaaa1fcd07d2db477432019f

See more details on using hashes here.

File details

Details for the file pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97d1892a5a30646d4e2380e77385e9a6cc54624fd39bc2baca66bac3f3fd58a2
MD5 5a941b8eae6a36fc01cfb9203a185613
BLAKE2b-256 e7768fa3c8f312326ba4cec7376366382a4fe85dd4ffc57e4355ec2a3a033175

See more details on using hashes here.

File details

Details for the file pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for pyagrum_nightly-2.0.1.dev202505011743172129-cp310-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 a5fa78e6bae754bf1439789ba97f2671b765a689fa7aeb5aba82ad1511f06438
MD5 7e4f1b70bc158250b1e3c5bdf370be10
BLAKE2b-256 8cf8964dfc3afd02b2eca06f849504725aa77b504c45200b29eb5ca5a033c1df

See more details on using hashes here.

Supported by

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