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 by Pierre-Henri WUILLEMIN et Christophe GONZALES {prenom.nom}_at_lip6.fr
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Maintainers
Lionel Torti
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-0.11.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6754b3b704c440ea76e6cfc17165017be1dc17b7f37d531e010e5988712b2d69 |
|
MD5 | 6a9ede707e5d773b368257c9f00f6137 |
|
BLAKE2b-256 | 746840a11e242008c50e84f62b3c6744345575aaa1dab44be4ec36e1652b9975 |
Hashes for pyAgrum-0.11.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44270c919ac2542684cf4389b9c51b0b8ed15e323d41e11ed4ff8f79ac9df82b |
|
MD5 | d6118cb9fa440a3bbbedc76ddf8035ea |
|
BLAKE2b-256 | 22c62afefecbe545e8b004b2a3bbb29f356e00fe6aa2003ee709171df8787878 |
Hashes for pyAgrum-0.11.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b2f53d58359faa6bc5d04290b0ed0649cf643dd1c41a6fc86a4cfe0ca9358d6 |
|
MD5 | e76aa6ef315f721107d16a3493d56832 |
|
BLAKE2b-256 | 5d9b24a9562f16e630665b911ade4f415c690ee7a7b60f2f77d79ebecd65cf30 |
Hashes for pyAgrum-0.11.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b16ed95f09b690ce392afb8599c34d929a6b90570907a329232cdf4636e7290 |
|
MD5 | 98dc605910031a3362a8a16312ecac17 |
|
BLAKE2b-256 | 4c23cf9c9cd04748438ab88b629115c6e6871742c8f7bda89e0c3fe1fd1c300a |
Hashes for pyAgrum-0.11.2-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e8c4308a79a3ca99f5d82369819935b7fca8e393a70c6e062e5988b027023f8 |
|
MD5 | 2d35b2c9cc69edd9ff5b389f0109019b |
|
BLAKE2b-256 | 11c0547ed66fcfe14a13fa34ad166e342b49e027526e19bf5b2cddf4e2bf51cc |
Hashes for pyAgrum-0.11.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c98dd314e7623bd9fc400c05e5cf29188592436216c47ffa363b2844659b66e |
|
MD5 | 256569315ea50571c4d16f1e933aa1d4 |
|
BLAKE2b-256 | 115956ee9bb029725b3587c28764d72a2e108f073489fe58f4e2d3b8c7695133 |
Hashes for pyAgrum-0.11.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b872629a50278d6685485d2a49b615c8713b1d8955cc4a430299084f3c51fb84 |
|
MD5 | 1e687e5faf4dafc7e8245ebbfc7c4cad |
|
BLAKE2b-256 | e3886457a2cef3ff67fb78b4e9cbe0f359003d231e9a2ef4c8d4b0ee71e4af35 |
Hashes for pyAgrum-0.11.2-cp27-cp27m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5a3dddd813e57b43f20570b711dac0eb833715d81c4650ffafa0655fc16ff2a |
|
MD5 | cb125721a048984ebac5b181a169c2eb |
|
BLAKE2b-256 | 9c3ce5906c68758d8c328dcfee1296c45f91d6332fc233b95c69dc631f91a094 |
Hashes for pyAgrum-0.11.2-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8410a8dbc745d581421eac263d8a93db181808e82b299061759ad1fcdc7e7ea4 |
|
MD5 | 9cf47b730fbf709c31160ec13d21c368 |
|
BLAKE2b-256 | e9de30aab7193d07281008780145237881ba3fc6dab36d8246d4fb7c54b5befb |
Hashes for pyAgrum-0.11.2-cp27-cp27m-macosx_10_12_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7018fe05a67abf399ddc8638236bf9aa5c1a0c4ff51c708f5bf32792eb1314bf |
|
MD5 | 91efde4050dae98dd6fced2a70e7afe4 |
|
BLAKE2b-256 | 4d71a73653be1ea73d4be7e94cae840aea126352b2a9d967d732e53c9177cf45 |