Skip to content

About

Educational Jupyter notebooks exploring probabilistic and active inference with RxInfer.jl: Beta-Bernoulli coin-bias inference and variational message passing, from the Active Inference Institute.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Active Inference Implementations

License: CC BY 4.0 Made with Julia

Educational notebooks exploring probabilistic inference and active inference implementations, maintained by the Active Inference Institute.

This repository collects working computational implementations — currently a set of RxInfer.jl tutorials demonstrating Bayesian inference on factor graphs by message passing. The notebooks are intended as hands-on learning material: each one is self-contained, seeded for reproducibility, and builds on the previous one.

Contents

Repository contents

Notebook Topic
RxInfer.jl/00_intro.ipynb Getting started with RxInfer.jl: inferring the bias of a coin with a Beta–Bernoulli model, building the same posterior by hand from individual messages, and scaling up the dataset
RxInfer.jl/01_message_passing.ipynb Exploring message-passing schemes: mean-field variational message passing (VMP) for the mean and the precision of a Normal model, read from its Generalized Notation Notation document
Path Contents
specs/normal_vmp.gnn.md Generalized Notation Notation (GNN) document declaring the mean-field VMP model: the single source of truth for the priors, the data statistics, the observation count, the iteration count, and the seed
specs/gnn-pin.json The upstream GNN revision the document is validated against (tag, commit, and SHA-256 digests of the parser files)
src/spec_reader.jl Dependency-free reader of the committed GNN document, used by the notebook, the test suite, and the validation gate
scripts/validate_gnn_spec.py Validation gate: parses the document with the pinned GNN parser and compares the three readers of the declarations
scripts/gnn_parser_probe.py The pinned-parser probe run in a subprocess by the validation gate
test/runtests.jl Test suite: declared scalars, data reproducibility, and the recovered posterior statistics
Project.toml The notebook environment
docs/README.md Documentation index: repository layout, notebook guide, and the GNN conformance gate

Canonical models elsewhere in the fleet

RxInfer.jl/00_intro.ipynb uses the Beta-Bernoulli coin model. Its canonical GNN document is specs/coin_flip.gnn.md in the ActInf_RxInfer repository, which also implements that model as a Julia package. This repository keeps the walkthrough and does not declare a second copy of that model; the notebook links to the canonical document, and the file declaring the model is validated there.

GNN maintains a downstream adoption guide for repositories that consume the notation. The guide is on GNN main; it is not present at the revision pinned in specs/gnn-pin.json (v5.0.3), so read it as current upstream guidance rather than as part of the pinned parser.

Prerequisites

  • Julia 1.13 — the notebooks were refreshed against RxInfer 6 and are executed on Julia 1.13 in CI. The [compat] bounds in Project.toml follow the notebook dependencies (RxInfer 6 supports Julia 1.10 and newer).
  • Jupyter with the IJulia kernel.
  • The Julia packages in Project.toml: RxInfer.jl, Distributions, Random, and Plots.

Getting started

git clone https://github.com/ActiveInferenceInstitute/ActiveInferenceImplementations.git
cd ActiveInferenceImplementations
julia --project=. -e 'using Pkg; Pkg.instantiate()'

Register the kernel the notebooks declare, once per machine:

using Pkg
Pkg.add("IJulia")
using IJulia
IJulia.installkernel("julia-1.13", "--project=@.", specname="julia-1.13")

The specname argument keeps the installed kernelspec named exactly julia-1.13, which is what the notebooks request; without it IJulia appends the Julia version to the kernel name (julia-1.13-1.13). The --project=@. option keeps the repository's Project.toml active inside the kernel, so the notebooks run against the committed environment. Then launch Jupyter from the repository root and open the notebooks under RxInfer.jl/:

julia -e 'using IJulia; jupyterlab()'

Each notebook is designed to run top to bottom with a fresh kernel. No environment variables or configuration are required.

Verification

run.sh is the single gate entry point. Every arm is separately runnable, and .github/workflows/ci.yml calls the same arms, so a local run and CI cannot diverge:

./run.sh setup        # Julia environment, notebook runtime, IJulia kernel
./run.sh lint         # Julia parse, Python compile, JSON validity, shell syntax
./run.sh test-fast    # static gates only; no RxInfer, no inference (default arm)
./run.sh test         # full suite, includes the static gates
./run.sh docs         # relative links + the generated gate table
./run.sh gnn          # GNN conformance against specs/gnn-pin.json
./run.sh contract     # Education bundle, using the canonical courses checker
./run.sh notebooks    # execute both notebooks into _build/executed
./run.sh gate         # every gate arm, failures aggregated

./run.sh with no argument runs test-fast. The measured wall time and test count of each arm live in docs/operations/gate-timings.md, which python3 scripts/measure_gates.py generates and ./run.sh docs checks.

The GNN validation needs a runtime with the pinned GNN distribution (GNN_RUNTIME_PYTHON), a GNN git checkout (GNN_ROOT with GNN_PYTHON), or network access so ./run.sh gnn can provision one from the pin into _build/gnn-runtime. Without a source it exits 2 and prints that the check was not run; that is not a pass. The pin is recorded in specs/gnn-pin.json (schema gnn-importer-pin/v1), and bumping it is a deliberate change followed by a fresh validation run.

The Education contract arm uses the canonical checker in a sibling courses checkout, or the checkout named by EDUCATION_ROOT. CI checks out the pinned revision declared in .github/workflows/ci.yml under _build/courses and sets that variable explicitly. The arm exits 2 if the checker is unavailable; it does not silently skip validation. See specs/README.md for the bundle's source-backed objectives and prerequisite policy.

Two environment notes from running the gates on macOS:

  • If GR (the default Plots.jl backend) cannot load libssl.3.dylib, export DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/opt/openssl@3/lib:/usr/lib before starting Jupyter. ./run.sh notebooks does this itself when the Homebrew OpenSSL directory exists, which is what makes the arm reproducible on macOS.
  • Saving a notebook in Jupyter updates its tracked outputs. ./run.sh notebooks writes executed copies to _build/executed/ and preserves the tracked notebooks.

Documentation

docs/README.md is the documentation hub, and docs/documentation-index.md is the flat index of every long-lived page. The hub links:

Folder-level guides live next to the material they describe: RxInfer.jl/README.md, specs/README.md, src/README.md, scripts/README.md, and test/README.md.

Contributing

Contributions are welcome — see CONTRIBUTING.md for guidelines on notebook and documentation contributions.

Citation

If you use or reference this repository in your work, please cite it via the metadata in CITATION.cff.

License

This repository is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0). See the human-readable summary and the full legal code.

InstituteOS sidecar

This repository carries a committed .aii/ sidecar with curated InstituteOS metadata (aii-sidecar/v1): category, maturity, ecosystem relations, key artifacts, provenance, and portable tasks. It is read by InstituteOS tooling and does not affect the project's build or runtime.

About

Educational Jupyter notebooks exploring probabilistic and active inference with RxInfer.jl: Beta-Bernoulli coin-bias inference and variational message passing, from the Active Inference Institute.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages