Skip to content

GNN format reference

Status. COGANT targets the Active Inference Institute GNN reference format. Its header block is checked against the optional, commit-pinned generalized-notation-notation package (GNN v5.1.0 release, import package gnn); the GNN v2.0.0 header value is COGANT's own schema identifier. This page is a working reference for the upstream-required header plus COGANT's extended provenance, evidence, and visualization sections emitted by cogant translate --layout-output. For the short version see gnn_format.md. The canonical upstream spec lives in the AII GNN repo.

File layout

A cogant translate ... --layout-output run produces a gnn_package/ directory:

gnn_package/
├── manifest.json             # package metadata, file inventory, SHA256 checksums
├── model.gnn.md              # bracket-notation model (human-readable)
├── model.gnn.json            # machine-readable twin of model.gnn.md
├── A.json                    # likelihood matrix
├── B.json                    # transition tensor
├── C.json                    # preference vector
├── D.json                    # prior vector
├── ontology_annotation.json  # node_id <-> variable_name map
├── provenance.json           # per-variable source spans (file:line:col)
├── diagrams/
│   ├── model.mmd             # mermaid state-space diagram
│   ├── model.png             # rendered version
│   └── blanket.mmd           # mermaid blanket diagram
└── reports/
    ├── gnn_score.json        # validator score and warnings
    └── drift.json            # diff against the previous run (if any)

All files are canonical JSON or UTF-8 markdown; no binary formats except the rendered PNGs.

Required upstream sections and COGANT extensions

model.gnn.md begins with the upstream-required header sections below, then appends COGANT extension sections such as repository metadata, source coverage, state-space details, Markov-blanket evidence, confidence scores, rendering hints, and validation notes. The validator (py/cogant/gnn/validator.py) checks that every required upstream section is present and well-formed; missing sections count against the 0 – 100 score.

# Section Required Purpose
1 ModelName yes Unique identifier for this model instance
2 ModelAnnotation yes Free-text description + provenance line
3 StateSpaceBlock yes Variable declarations with shape and type
4 Connections yes Directed edges between variables
5 InitialParameterization yes Numeric values for A, B, C, D
6 Equations no LaTeX-rendered equations relating variables
7 Time yes Discrete / Continuous, ModelTimeHorizon
8 ActInfOntologyAnnotation yes Variable → Active Inference ontology term
9 GNNSection no Meta-notes about the generative model
10 GNNVersionAndFlags yes GNN v2.0.0, feature flags
11 ModelParameters no Hyperparameters (learning rates, temperatures)
12 ObservationModalities no Rich metadata for each observation channel
13 ControlFactors no Rich metadata for each action factor
14 MarkovBlanket no Internal / sensory / active / external node lists
15 MarkovBlanketNetwork no Collapsed four-role aggregate network
16 Evidence no Rule-firing evidence for each mapping
17 Provenance no Per-variable source span references
18 Footer yes Generation timestamp, tool version
19 Signature no Optional cryptographic hash of the model

COGANT's current emitter populates the required upstream header unconditionally, then emits COGANT extension sections when the corresponding evidence exists.

Bracket notation at a glance

## ModelName
cogant_flask_app_current

## ModelAnnotation
Generated by COGANT v0.7.0 from examples/real_world/flask_app/; COGANT schema GNN v2.0.0, checked against the pinned generalized-notation-notation 5.1.0 release line.
98 graph nodes, 597 edges, 51 semantic mappings kept after conflict resolution.

## StateSpaceBlock
s_f0[3,1,type=int]        # observation: request.method, db_connected, response_code
u_f0[3,1,type=int]        # action id: validate_input, query_database, format_response
x_f0[6,1,type=float]      # hidden state: Application + Request/Response + db_connected

## Connections
x_f0 > s_f0               # hidden state emits observation
u_f0 > x_f0               # action updates hidden state
x_f0 > x_f0               # persistence (identity-biased)

## InitialParameterization
A_m0 = [[0.9, 0.05, 0.05],
        [0.05, 0.9, 0.05],
        [0.05, 0.05, 0.9]]

B_f0 = identity_per_action      # no WRITES edges; identity fallback
C_m0 = [0.0, 0.0, 0.0]          # uniform: no CONSTRAINT mappings
D_f0 = uniform(6)               # uniform: no CONFIGURATION nodes

## Time
Discrete
ModelTimeHorizon=Unbounded

## ActInfOntologyAnnotation
s_f0 = HiddenStateFactor0
u_f0 = PolicyVector
x_f0 = HiddenStateFactor0

## GNNVersionAndFlags
GNN v2.0.0
Flags=identity_B_fallback,uniform_C,uniform_D

Bracket syntax

Each variable declaration uses the form:

name[dim1,dim2,...,type=int|float|bool]   # optional comment

Naming conventions (enforced by the validator):

  • s_* — observation (sensory) variables. First index is the modality (s_f0, s_f1, ...).
  • u_* — action / control input variables.
  • x_* — hidden (latent) state variables. First index is the factor.
  • pi_* — policies (distributions over action sequences).

The dimensions specify the domain size per factor, not the number of factors. A variable s_f0[3,1,type=int] is a single observation factor with a 3-valued domain.

Connections syntax

A > B means "A is an input to B" or equivalently "B depends on A." Typical connections:

Connection Meaning Matrix
x > s hidden state emits observation A
u > x action updates hidden state B
x > x state persistence B (diagonal)
s > pi observation informs policy planning
pi > u policy selects action planning

Matrix JSON schema

Each of A.json, B.json, C.json, D.json has the same envelope:

{
  "matrix": [[0.9, 0.05, 0.05], [0.05, 0.9, 0.05], [0.05, 0.05, 0.9]],
  "shape": [3, 3],
  "n_states": 3,
  "n_obs": 3,
  "n_actions": 1,
  "state_names": ["display", "accumulator", "history_len"],
  "observation_names": ["get_display", "get_history", "assert_display"],
  "action_names": ["_execute_operation"],
  "fallback_flags": ["direct_mass_0.9"],
  "provenance": {
    "builder": "GNNMatrices.compute_A",
    "cogant_version": "0.7.0",
    "source_bundle": "output/calculator/bundle.json"
  }
}

B.json carries a rank-3 matrix (list of lists of lists, indexed [action][from_state][to_state]). C.json and D.json carry a rank-1 vector field instead of matrix.

Validation

cogant validate <gnn_package> runs GNNValidator, which checks:

  1. Structural — all required sections present, no unknown sections.
  2. Shape — A is [n_obs × n_states], B is [n_states × n_states × n_actions], C is [n_obs], D is [n_states].
  3. Normalization — A columns sum to 1.0 ± ε, B action-slices are column-stochastic ± ε, D sums to 1.0 ± ε.
  4. Ontology — every variable in StateSpaceBlock appears in ActInfOntologyAnnotation with a known Active Inference term.
  5. Fallback flags — every fallback (identity_B, uniform_C, etc.) is disclosed in the GNNVersionAndFlags section.

Score formula: 100 − 5 × errors − 1 × warnings, clamped to [0, 100]. The three control-positive fixtures (calculator, event_pipeline, flask_mini) currently score 100.0 each.

Known fallbacks

When the program graph lacks direct evidence for a matrix entry, COGANT emits documented fallbacks and surfaces them in gnn_score.json as warnings:

Fallback Trigger Surfaced as
A_direct_0.9 A hidden-state column has at least one direct READS hit Silent (default)
A_uniform_column A hidden-state column has zero READS hits Warning A_column_uniform
B_identity_per_action an action has zero WRITES targeting hidden state Warning B_identity_fallback
C_uniform no CONSTRAINT/PREFERENCE mappings Warning C_uniform
D_uniform no CONFIGURATION nodes Warning D_uniform

These are honest defaults, not learned parameters. Downstream consumers should treat a matrix with many fallback warnings as uninformative rather than authoritative.

See also