Official Documentation
Dive deeper into pyAgrum with the documentation for detailed guides, tutorials, and API references.
pyAgrum is a versatile Python library for creating and reasoning with Probabilistic Graphical Models (PGMs), such as Bayesian Networks and Markov Random Fields. Whether you’re a data scientist, researcher, or Python developer, pyAgrum offers an intuitive interface to model uncertainty and perform probabilistic inference. This guide will help you run your first pyAgrum example and explore its capabilities.
Below is a simple example of creating a Bayesian Network with pyAgrum and performing inference. This example demonstrates how to model two variables and compute probabilities based on evidence.
import pyAgrum as gum
# Create a Bayesian Networkbn = gum.BayesNet('SimpleBN')bn.add(gum.LabelizedVariable('A', 'Cloudy', ['yes', 'no']))bn.add(gum.LabelizedVariable('B', 'Rain', ['yes', 'no']))bn.addArc("A", "B")
# There is also a faster compact syntaxbn = gum.fastBN("A{yes|no}->B{yes|no}")
# Set Conditional Probability Tables (CPTs)bn.cpt("A").fillWith([0.4, 0.6]) # P(Cloudy=yes)=0.4, P(Cloudy=no)=0.6bn.cpt("B")[{"A": "yes"}] = [0.8, 0.2] # P(Rain=yes|Cloudy=yes)=0.8bn.cpt("B")[{"A": "no"}] = [0.1, 0.9] # P(Rain=yes|Cloudy=no)=0.1
# Perform inferenceie = gum.LazyPropagation(bn)ie.setEvidence({"A": "yes"})ie.makeInference()print(ie.posterior("B")) # Output: Posterior probabilities for RainSimpleBN is created
with two variables: Cloudy (A) and Rain (B).Cloudy to Rain, indicating
that Rain depends on Cloudy.Cloudy and Rain.LazyPropagation algorithm computes the posterior
probability of Rain given evidence that Cloudy=yes.This example is a great starting point to understand how pyAgrum models dependencies and performs probabilistic reasoning.
Official Documentation
Dive deeper into pyAgrum with the documentation for detailed guides, tutorials, and API references.
PyPI Page
Download the latest version of pyAgrum from PyPI.
FAQs
Find answers to common questions in our FAQ section.
Installation Guide
Need help setting up? Visit our Installation Guide for step-by-step instructions.
Join our vibrant community to ask questions, share your projects, or contribute to pyAgrum! Connect with other users and developers on our Discord server.
Join Our Discord
Ready to build your own Probabilistic Graphical Models? Try modifying the example above or explore the Official Documentation for advanced use cases. We can’t wait to see what you create with pyAgrum!