{"id":8467,"library":"pyagrum-nightly","title":"pyAgrum-nightly: Probabilistic Graphical Models","description":"pyAgrum-nightly is a Python wrapper for the scientific C++ aGrUM library, providing a high-level interface for Bayesian networks, Markov Networks, Influence Diagrams, and other Probabilistic Graphical Models. As a nightly build, it offers the latest features and bug fixes from the development branch. It is actively maintained with frequent updates reflecting ongoing development.","status":"active","version":"2.3.2.9.dev202604161770834561","language":"en","source_language":"en","source_url":"https://github.com/aGrUM/aGrUM","tags":["bayesian networks","probabilistic graphical models","PBN","inference","machine learning","AI","graphical models"],"install":[{"cmd":"pip install pyAgrum-nightly","lang":"bash","label":"Install latest nightly build"}],"dependencies":[{"reason":"Runtime environment","package":"Python","optional":false}],"imports":[{"note":"Since pyAgrum 2.0.0, the package name follows PEP8 rules and is lowercase. Using 'pyAgrum' will result in an ImportError.","wrong":"import pyAgrum as gum","symbol":"pyagrum","correct":"import pyagrum as gum"}],"quickstart":{"code":"import pyagrum as gum\n\n# Create a Bayesian Network\nbn = gum.BayesNet(\"WaterSprinkler\")\n\n# Add variables\nid_c = bn.add(gum.LabelizedVariable(\"c\", \"cloudy ?\", 2))\nid_s = bn.add(gum.LabelizedVariable(\"s\", \"sprinkler ?\", 2))\nid_r = bn.add(gum.LabelizedVariable(\"r\", \"rain ?\", 2))\nid_w = bn.add(gum.LabelizedVariable(\"w\", \"wet grass ?\", 2))\n\n# Add arcs (dependencies)\nbn.addArc(id_c, id_s)\nbn.addArc(id_c, id_r)\nbn.addArc(id_s, id_w)\nbn.addArc(id_r, id_w)\n\n# Define Conditional Probability Tables (CPTs) using dictionaries\nbn.cpt(\"c\").fillWith([0.5, 0.5])\nbn.cpt(\"s\")[{\"c\": 0}] = [0.5, 0.5]\nbn.cpt(\"s\")[{\"c\": 1}] = [0.9, 0.1]\nbn.cpt(\"r\")[{\"c\": 0}] = [0.8, 0.2]\nbn.cpt(\"r\")[{\"c\": 1}] = [0.2, 0.8]\nbn.cpt(\"w\")[{\"s\": 0, \"r\": 0}] = [1, 0]\nbn.cpt(\"w\")[{\"s\": 0, \"r\": 1}] = [0.1, 0.9]\nbn.cpt(\"w\")[{\"s\": 1, \"r\": 0}] = [0.1, 0.9]\nbn.cpt(\"w\")[{\"s\": 1, \"r\": 1}] = [0.01, 0.99]\n\n# Perform inference\nie = gum.LazyPropagation(bn)\nie.setEvidence({\"w\": 1}) # Wet grass is true\nie.makeInference()\n\n# Get posterior probabilities\nposterior_c = ie.posterior(\"c\")\nprint(f\"P(c|w=1): {posterior_c}\")","lang":"python","description":"This quickstart demonstrates how to create a simple Bayesian network (the 'Water Sprinkler' example), define its topology and conditional probability tables, and perform inference with evidence. It highlights the use of `pyagrum` (lowercase) for imports and dictionary-based CPT assignments."},"warnings":[{"fix":"Update all `import pyAgrum` statements to `import pyagrum`.","message":"The main package import name changed from `pyAgrum` to `pyagrum` (all lowercase) starting from version 2.0.0. Older code using `import pyAgrum as gum` will fail.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always use dictionary-based assignments for CPTs (e.g., `bn.cpt(\"s\")[{\"c\": 0}] = [0.5, 0.5]`) instead of direct list assignment, unless you are absolutely sure of the indexing order.","message":"When defining Conditional Probability Tables (CPTs), especially for complex networks, directly assigning values can lead to indexing errors. pyAgrum recommends using dictionaries for clarity and to prevent common mistakes when introducing data.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure that the directory path provided to save functions (e.g., `gum.saveBN(bn, 'path/to/directory/filename.bif')`) exists before calling the function. Create the directory if it doesn't exist.","cause":"This error often occurs when attempting to save a Bayesian network or other graphical model to a file, but the specified output directory does not exist.","error":"IOError: [pyAgrum] I/O Error: Stream states flags are not all unset"},{"fix":"Consider using 'smoothing' or adding 'priors' during the learning phase (e.g., using `BNLearner.useAprioriSmoothing()`) to handle unseen combinations. Also, evaluate the representativeness of your dataset and data splitting strategy.","cause":"This error typically arises during Bayesian network learning or inference when using data, especially with small datasets or specific data splits, where a particular combination of variable values (a 'conditioning set') exists in the query/test set but was never observed in the training data.","error":"DatabaseError: [pyAgrum] Database error: The conditioning set <COL=0, RA=4, INC=0> for target node PARTNER never appears in the database."}]}