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-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 LGPL3 license, see https://www.gnu.org/licenses/lgpl-3.0.en.html.
Maintainers
Lionel Torti
Gaspard Ducamp
Project details
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
Built Distributions
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd4e7f18d337559e7c6d062cc634ff7e275a9e11760225cbc46288c81271cdf |
|
MD5 | e9992fa7aba721f52f221db5821e15f5 |
|
BLAKE2b-256 | b9edcdf4526436f1310995ea7603d84d30a0715f6286f289b9358557e8f52615 |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc6435dbef6fdd300d89364c0def7b7b2b5e13f7b15109ce93492b71f0f5cb04 |
|
MD5 | 53fad661a4c5ca1699d584f74c07b7a9 |
|
BLAKE2b-256 | 11125879c7c9458791f3004124b2e2266e0f27b3e0e57b09d808d2cf5a8f0767 |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a0d52b51cca3db3a6be08730d1e8c883216ea141ef407f81733781da7cb7109 |
|
MD5 | 8caae8ecc6506aaa7383d26591ee633c |
|
BLAKE2b-256 | 55934b5ea0c89f923fe9686a14c68c3cbcb6eb38ceaad50026bbc6a8db4125ec |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp310-cp310-manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57821942bfeb5ba4d3bc13104327f8cc60b361f805823c567b034a899079dbdf |
|
MD5 | 5921cf4a474a0525c4449a6496eb07a6 |
|
BLAKE2b-256 | c92ec0908ef3f409d5c8ebcc44444c5cd49a85597ebd2becfc815e71f6d02a04 |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp310-cp310-manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40a2188edea8ea89e6d8bc31c50e376d3933eeac1b62dc84c332d0f2118961d9 |
|
MD5 | 9ac3c1cddd987aa040028cd33885a468 |
|
BLAKE2b-256 | 93e0562c8334a4f1c5fd31fc7ec4c2729d689df82c0578a9983c1c5fe36362ca |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cefd44b1ad9e843541a8665a6b8d96e278b4bdbc69fabf0aa568beb68f5a4987 |
|
MD5 | 63accafff38ea42a7e0dcfc04411e6b8 |
|
BLAKE2b-256 | 03b28d44f9ad8671cb2bbc41c74d7c03e176671281178fe314a650daa45ab4ca |
Hashes for pyAgrum_nightly-1.14.0.9.dev202406221718113029-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d3b2953f1b1858fe929e4c9a9c16b84cbe5cc7a9c8f15aaf1eca5ff62dddf3b |
|
MD5 | 15bbd15a68798611698b9227e771e74d |
|
BLAKE2b-256 | 5dfde351eae4f870fafcb34e0ab6a393eeb11f8d94253a5575f5fe29f82bd77f |