Code for the computational model in Active Inferants: An Active Inference Framework for Ant Colony Behavior by Daniel Ari Friedman, Alec Tschantz, Maxwell J. D. Ramstead, Karl Friston, and Axel Constant.
The simulation models ant-colony foraging in a 40 × 40 T-maze. Individual simulated ants use a Markov decision process (MDP) to infer local pheromone observations, move through the environment, and deposit trail pheromone while returning from food. The repository contains the implementation used for the paper's in-silico experiments.
- Documentation hub — the folder guide for
docs/. - Documentation index — the flat list of long-lived documents.
- Gate and CI run guide — the gate entry point, its arms, and measured timings.
- Running the simulations — installation, commands, outputs, and runtime notes.
- Model overview — environment, observations, MDP components, and parameters.
- Tests — what the suite covers and how to run it.
- Contributing — scope, tests, and development guidance.
- Review TODO — documentation review findings and status.
The project requires Python 3.12 or later. From the repository root:
python3 -m venv .venv
.venv/bin/python -m pip install -e .
.venv/bin/python figure_1.pyWith uv, the same setup is uv sync --extra dev followed by uv run figure_1.py.
The figure scripts create an imgs/ directory containing PNG snapshots, GIFs, NumPy arrays, text summaries, and (for figure_1.py) path plots. Generated output is ignored by Git. The default experiments are intentionally larger runs; see Running the simulations for the smaller API smoke test and experiment details.
The test suite lives in tests/ and runs under pytest with a 90% coverage floor:
.venv/bin/python -m pip install -e ".[dev]"
.venv/bin/python scripts/gate.py fast # default arm: lint + docs + fast tests
.venv/bin/python scripts/gate.py all # every arm, including the full suiteWith uv, uv sync --extra dev followed by uv run python scripts/gate.py all.
The arms are lint, test-fast, test, docs, and gnn; test runs the full
suite under the 90% coverage floor and gnn re-validates the specification
against the pinned parser. The arm table, measured timings, and the CI job
mapping are in docs/RUN_GUIDE.md and
docs/_generated/gate-metrics.md.
Continuous integration runs the same gate arms on every push and pull request (see .github/workflows/ci.yml).
The ant-colony foraging MDP is specified in
gnn/ant_colony_foraging.gnn.md in
Generalized Notation Notation
(GNN): the 9 focal-cell states, 10 pheromone-level observations, 9 actions, the
environment-driven likelihood, the deterministic transition tensor, the log-preference
vector, and the habit prior.
The specification is validated against the GNN revision pinned in
gnn/upstream.json, read from that pinned commit rather than from
the GNN checkout's working tree. The pin itself is read by gnn.importers, the reader
shipped in that revision — this repository carries no pin reader of its own:
uv run python scripts/gate.py gnn # reader check + strict validator + conformance tests
uv run pytest tests/test_gnn_conformance.py # specification sections and dimensions under pytestThe arm first runs python -m gnn.importers check --repo . from the pinned environment,
which reads the pin and validates the specification with the pinned parser; the gate then
parses the specification with the pinned GNN extractor and checks the extracted matrices
against ants.py. The test module runs the same model checks under pytest and skips only
the pinned-parser half when the GNN checkout is unavailable. When editing the
specification, start from GNN's Start Here,
framework integration guide,
and syntax reference.
For the wider picture (the adoption patterns sibling repositories use, pin discipline, and
the drift guard these checks implement), see GNN's
downstream adoption guide.
- Active_InferAnts — the
multi-language Active Inference framework that grew out of this model. Its framework
agent is specified separately, in that repository's
gnn/directory. - Active_Skillference —
the Active Inference / Free Energy Principle micro-learning platform; its discrete
active-inference agent kernel is specified in that repository's
gnn/directory.
Each concept has one canonical home: this repository owns the 2021 ant-colony foraging MDP; the other two specify their own models.
For the published article:
Friedman DA, Tschantz A, Ramstead MJD, Friston K, Constant A (2021). Active Inferants: An Active Inference Framework for Ant Colony Behavior. Frontiers in Behavioral Neuroscience, 15, 647732. https://doi.org/10.3389/fnbeh.2021.647732
Machine-readable citation metadata is provided in CITATION.cff. The repository's source code is released under the MIT License. See LICENSE. The article is open access under the license specified by its publisher; consult the publication for the article's reuse terms.
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.