Tensegrity: A Non-Gradient Cognitive Architecture
No backpropagation. No gradient descent. No optimizer state.
Tensegrity is a cognitive architecture where structural integrity comes from the tension between competing causal models, not from gradient-based optimization. It implements the actual mathematics of Friston, Pearl, Markov, Bayes, and Zipf β not as metaphors, but as computational machinery.
The Core Idea
Instead of minimizing a loss function via SGD, Tensegrity minimizes variational free energy via fixed-point iteration (belief propagation on factor graphs). Multiple structural causal models compete to explain observations, and the tension between them drives learning and exploration.
F = D_KL[q(s) || p(s)] - E_q[ln p(o | s)]
βββββββββββββββββ βββββββββββββββββ
Complexity Accuracy
This is minimized by coordinate ascent β each step is a matrix multiply + softmax normalization. The entire system converges without computing a single gradient.
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MARKOV BLANKET β
β ββββββββββββ ββββββββββββ β
β β SENSORY β Morton-coded input β ACTIVE β β
β β STATES β ββββββββββββββββββββββ β STATES β β
β ββββββββββββ β ββββββ¬ββββββ β
β β β β β
β βΌ β β β
β ββββββββββββββββββββββββββββ β β β
β β BELIEF STATES β β β β
β β Q(s) over hidden states ββββββββ β β
β β Updated via VFE min β β β
β βββββββββββ¬βββββββββββββββββ β β
β β β β
β βΌ β β
β ββββββββββββββββββββββββββββ β β
β β CAUSAL ARENA β β β
β β Mβ vs Mβ vs ... vs Mβ ββββββββββββββββββ β
β β SCMs compete via F β β
β βββββββββββ¬βββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββββββββββββββββ β
β β MEMORY SYSTEMS β β
β β Epistemic β Episodic β Associative β β
β β (beliefs) β (traces) β (Hopfield) β β
β β Zipf-weighted access priority β β
β ββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Components
1. Morton-Coded Sensory Input
Any modality (image, audio, text, sensor data) is encoded via Z-order curves (Morton codes) into a single integer that preserves spatial locality. The system literally doesn't know what modality it's processing β it's all just Morton codes.
2. Free Energy Engine (Friston)
Implements the discrete POMDP active inference loop:
- Perception: Fixed-point iteration on
q(s)until convergence (~16 iterations, no gradients) - Planning: Expected Free Energy
G_Ο = ambiguity + riskfor each policy - Action: Softmax over
-Ξ³Β·G_Ο(Boltzmann policy selection)
3. Causal Arena (Pearl)
Multiple Structural Causal Models compete to explain observations:
- Rung 1 β Association:
P(Y | X=x)via standard conditioning - Rung 2 β Intervention:
P(Y | do(X=x))via graph surgery (mutilated DAG) - Rung 3 β Counterfactual:
P(Y_x | X=x', Y=y')via abduction β intervention β prediction
The tension is the entropy of the posterior over models: high entropy = competing explanations, low entropy = one model dominates.
4. Belief Propagation (Markov/Bayes)
Sum-product algorithm on factor graphs with loopy BP + damping for cyclic structures. This is the shared computational primitive for:
- State inference (perception)
- Policy evaluation (planning)
- Model comparison (arena)
5. Memory Systems (Zipf)
| Memory | What it stores | Update rule | Retrieval |
|---|---|---|---|
| Epistemic | Dirichlet-parameterized beliefs (A, B, C, D matrices) | Bayesian counting | Zipf-weighted by access frequency |
| Episodic | Temporal experience traces with context vectors | Context drift (TCM) | Cosine similarity + recency + Zipf |
| Associative | Modern Hopfield network (exponential capacity) | Pattern append | Energy minimization (no gradients) |
All three follow Zipf's law: frequently accessed memories are cheapest to retrieve, creating self-reinforcing power-law access patterns.
Quick Start
from tensegrity import TensegrityAgent
import numpy as np
# Create agent
agent = TensegrityAgent(
n_states=16,
n_observations=32,
n_actions=4,
sensory_dims=4, # 4D input (any modality)
sensory_bits=8, # 256 levels per dimension
precision=4.0, # Inverse temperature
zipf_exponent=1.0, # Power-law steepness
)
# Perception-action loop
for t in range(100):
raw_observation = np.random.randn(4) # Any modality, any shape
# Perceive: Morton encode β Free energy minimize β Update beliefs
result = agent.perceive(raw_observation)
# Act: Expected free energy β Policy selection
action = agent.act()
print(f"t={t}: F={result['free_energy']:.2f}, "
f"tension={result['arena']['tension']:.3f}, "
f"surprise={result['surprise']:.2f}")
# Introspect
state = agent.introspect()
print(f"Arena winner: {state['arena']['current_winner']}")
print(f"Epistemic entropy: {state['epistemic_memory']['entropy']}")
# Counterfactual reasoning
cf = agent.counterfactual(
evidence={'state': 0, 'observation': 5},
intervention={'state': 3},
query=['observation']
)
What "Tension" Means Here
The tension is not a metaphor. It's a measurable quantity:
tension = H[P(Mβ, Mβ, ..., Mβ | data)] / log(K)
Where H is Shannon entropy and K is the number of competing causal models.
- Tension = 1.0: All models equally likely. Maximum uncertainty about causal structure.
- Tension = 0.0: One model dominates. The system has "decided" which causal story is correct.
- Tension > 0.5: The system should explore (epistemic actions) to resolve the competition.
The tension drives the system to choose experiments that would maximally discriminate between competing models. This is the epistemic component of Expected Free Energy β it's information-seeking behavior emerging from pure logic.
What's NOT Here
- β No neural networks
- β No backpropagation
- β No gradient descent
- β No loss functions
- β No optimizer state (Adam, SGD, etc.)
- β No learned weights
- β No training epochs
What IS Here
- β Variational free energy minimization (coordinate ascent)
- β Bayesian belief updating (Dirichlet counting)
- β Belief propagation (sum-product algorithm)
- β Structural causal models (Pearl's do-calculus)
- β Counterfactual reasoning (abduction β intervention β prediction)
- β Modern Hopfield networks (energy-based associative memory)
- β Temporal Context Model (episodic memory)
- β Morton codes (space-filling curve encoding)
- β Zipf-distributed memory access (power-law priority)
Theoretical Foundations
| Component | Theory | Key Paper |
|---|---|---|
| Free Energy Engine | Active Inference / FEP | Friston et al., "Active Inference" (arXiv:2006.04120) |
| Causal Arena | Structural Causal Models | Pearl, "Causality" (2009) |
| Belief Propagation | Sum-Product Algorithm | Kschischang et al. (2001) |
| Associative Memory | Modern Hopfield Networks | Ramsauer et al. (arXiv:2008.02217) |
| Episodic Memory | Temporal Context Model | Howard & Kahana (2002) |
| Morton Encoding | Z-Order Curves | Morton (1966) |
| Zipf Priority | Power-Law Access | Anderson & Schooler (1991) |
Dependencies
numpyβ Array operationsscipyβ Softmax, digamma, special functionsnetworkxβ Graph operations for causal DAGs
License
Apache 2.0