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 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.

Authors

  • Pierre-Henri Wuillemin

  • Christophe Gonzales

Maintainers

  • Lionel Torti

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-0.9.3.7-cp35-cp35m-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.5mWindows x86-64

pyagrum-0.9.3.7-cp35-cp35m-win32.whl (4.6 MB view details)

Uploaded CPython 3.5mWindows x86

pyagrum-0.9.3.7-cp35-cp35m-macosx_10_11_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.5mmacOS 10.11+ x86-64

pyagrum-0.9.3.7-cp27-cp27m-macosx_10_12_intel.whl (11.2 MB view details)

Uploaded CPython 2.7mmacOS 10.12+ Intel (x86-64, i386)

File details

Details for the file pyagrum-0.9.3.7-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for pyagrum-0.9.3.7-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 8b030f7eb96ac03648b366ce8a58c9ce368c5a0d1a721316b6a63173326c975f
MD5 75b366675085f2baa3b4434c273c1430
BLAKE2b-256 23c170e2e00420362fe92bb7f5627e7b2646c86b8066bae5cd1293314bd76b30

See more details on using hashes here.

File details

Details for the file pyagrum-0.9.3.7-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for pyagrum-0.9.3.7-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 7baaa0e59d7ef3434f31661c13c56c9b89c12284cd4cb4fa70561474a3c5da5b
MD5 67231a7c3d104080f455c238cd7fd48f
BLAKE2b-256 e6bc06b5dd48c18ff9d4e4b445289225e52d95e8fd3554ae6e76907f03ae45ef

See more details on using hashes here.

File details

Details for the file pyagrum-0.9.3.7-cp35-cp35m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for pyagrum-0.9.3.7-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 f807fd611c72423e0dd6b1cf4cc877cec085e4d0e5c28d3bfb5e80f2a902c830
MD5 379a35b2c36a0aac7a7d930e48eac335
BLAKE2b-256 afd267b46c32f7057edd4dda88cf83a8eebb6d816ff434f5adfb259af999d02a

See more details on using hashes here.

File details

Details for the file pyagrum-0.9.3.7-cp27-cp27m-macosx_10_12_intel.whl.

File metadata

File hashes

Hashes for pyagrum-0.9.3.7-cp27-cp27m-macosx_10_12_intel.whl
Algorithm Hash digest
SHA256 978f68493b1770f9af808fcefcd54d2e2fc3df67177d3789af42222a71160e16
MD5 5f21d6f6bdd22ef119a80a0d0cbb4d02
BLAKE2b-256 50e433249d9b236b2a8fe94c4b0250397002248b32b4e47a84a6995011bb6e70

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