Skip to main content

A patch net: owners hold state, seams carry it both ways, every owner repairs its own patch until the net is at rest

Cadence

Machine learning by patch-net settlement.
Owner-local repair, no backward pass, held-out tests, receipts.

PyPI CI Python License

Docs · Quickstart · How it learns · Examples · Play the demos


A patch net is a set of owners, each holding one patch of state, joined by declared seams. Nothing is computed globally. Every owner repairs its own patch from what arrives over its seams, and the state the net comes to rest in is the answer. Learning is the same settlement run again with the outputs nudged: every seam moves on what its own two ends did. Cadence is the library for building, settling, training, testing, and certifying such nets, from a six-owner toy to a 161,827-owner nervous system read from a connectome.

import cadence as cd

wiring = cd.layered(64, 32, 10, density=1.0, seed=0)        # input, hidden, output owners
learner = cd.Learner(cd.Settlement(wiring, cd.learning_rule()), wiring.sets["output"],
                     cd.LearnerConfig(eta=3.0, beta=0.1, temperature=0.1))
for idx in batches:
    learner.step(drive[idx], labels[idx])                    # settle free, settle nudged, update locally
learner.accuracy(drive_test, labels_test)                    # 0.96 on the 8x8 digits

Why Cadence

  • One rule for answering and learning. A settlement makes the prediction; a nudged settlement teaches. There is no forward pass, no backward pass, no controller that stores activations and transposes weights. The goal enters through the nudge and nowhere else.
  • Every update is local and provably so. A seam reads two activations; an owner reads one. A reference engine settles the net one owner at a time with a message ledger, and conformance certifies that a fast backend computed nothing an owner could not see.
  • It is a gradient. With symmetric seams the settlement descends an energy, and the local contrast is the loss gradient (equilibrium propagation). The tests check it against finite differences.
  • Measured, not claimed. Every example selects on a validation split, reads its test set once, trains the obvious backprop baseline on the same split, and writes a receipt that binds every number to the code and data that produced it.
  • Runs where you are. NumPy float64 with a fused kernel for receipts; torch on CUDA, MLX or torch on Apple silicon for scale, the settled state and the learning contrast staying on the device; a block transport for layered nets and a scatter for connectome-sized ones.

How it learns

Settle free to an equilibrium; tilt the energy with a nudge on the outputs and settle again both ways; every seam moves on the difference of its own two endpoints

  1. Settle free. Clamp the inputs and let every owner repair its own patch until nothing moves. The output owners at rest are the answer; no target has entered.
  2. Tilt, and settle again. Add a small drive on the output owners toward the target (+β) and, from the same rest state, away from it (−β). The net finds a new equilibrium each time, and the change reaches the hidden owners through the very seams the answer used.
  3. Contrast. Each seam moves by η (s⁺ᵢ s⁺ⱼ − s⁻ᵢ s⁻ⱼ) / 2β, each bias by η_b (s⁺ᵢ − s⁻ᵢ) / 2β. For a small nudge that is minus the loss gradient.

Labels, a teacher's moves, and rewards all enter the same way: as the target of the nudge (and, for a reward, its weight). How it learns has every equation and a worked six-owner example with every number; differences sets it against a feed-forward network with backprop.

Install

pip install cadence-net            # NumPy only; the import is `cadence`
pip install "cadence-net[accel]"   # adds torch for CUDA and Apple silicon
pip install "cadence-net[apple]"   # adds MLX, the faster Apple silicon path
pip install "cadence-net[fast]"    # adds the fused CPU kernel (numba)

Python 3.11 or newer.

Sixty seconds

A wiring is n owners plus directed overlaps with a contact count and a sign. Build one from edge lists (a connectome), or let layered build a learnable one.

w = cd.Wiring.from_edges(3, pre=[0, 0, 1], post=[1, 2, 2], count=[80, 20, 80], sign=[1, 1, -1],
                         sets={"input": [0], "output": [2]})

A rule is what an owner does with its inbox. GradedRule is the connectome rule; learning_rule() is the one a net that learns needs; Adaptation adds rhythm.

engine = cd.Settlement(w, cd.GradedRule(gain=0.02), backend="torch")   # or "cpu"
state = engine.settle(w.members("input"), steps=100, trajectory=True)
state.activation, state.trajectory.shape

A protocol declares held-out facts with preconditions, and a shuffled control that keeps every count, sign, and set.

protocol = cd.Protocol(stimuli={"rest": (), "drive": ("input",)},
                       training=[("drive", "output", "active")],
                       rows=[cd.Row("R1", "rest", "output", "inactive", "nothing in, nothing out")])
protocol.score(engine)["passed"], protocol.score(cd.Settlement(cd.shuffled(w, 0), engine.rule))["passed"]

Certify and record.

cd.conformance(engine, w.members("input"))["max_abs_deviation"]           # ~1e-16 on cpu
receipt = cd.Receipt.build("my-lane/v1", {"score": protocol.score(engine)}, sources=[("lane.py", Path("lane.py"))])
receipt.write(Path("receipt.json")); cd.Receipt.verify(Path("receipt.json"), sources=[("lane.py", Path("lane.py"))])

The quickstart does all of this on a connectome, end to end.

Examples

Everything in cadence-examples is a tutorial, a script that trains something and measures the backprop baseline in the same run, a receipt, the trained net, and a page in which the net settles live. The hub links them all; How a patch net learns is the tutorial they build on.

rung what receipt says
01 digits classification, 8×8 digits 0.962 ± 0.003 held-out in 20 epochs; a same-size MLP: 0.967 in 50
02 recall associative recall with no trained parameters: each pair one Hebbian outer product, each query a settlement the value of any key in a context of up to 128 pairs, 1.00 settled and 1.00 in one read; a two-layer transformer given 5,000 Adam steps on the task did not learn it (0.30 at 4 pairs, 0.01 at 128)
03 Connect Four imitates a depth-4 search from self-play positions; play it agrees with the search on 0.527 of positions, the same-size MLP 0.533; 91-0-9 against a random mover
04 Pong a paddle learns from pixels and reward, with an adaptive local step; play it 88% of balls returned against 93% for REINFORCE with Adam on the same rollouts; the same net taught a tracker's moves 96%

Every rung has a page: draw a digit, write a memory and ask it, play Connect Four or Pong against the net. The earlier rungs (MNIST, Shakespeare, the sign writer, cart-pole, the chorale writer, the C. elegans connectome) are at tag v0.5.0 with their receipts, which the docs still cite where they measured something.

What is in the box

module gives you
Wiring owners and overlaps as sorted arrays, named sets, digests; built from edge lists or by layered
GradedRule, Adaptation, learning_rule the owner rule: a graded potential with a rectified sigmoid that emits nothing at rest, an optional leak, and an optional slow variable that turns fixed points into rhythm
Settlement, Nudge the batched engine on NumPy or torch, with a convergence tolerance and a nudge toward a target; dense() for pages
Learner, LearnerConfig the free/nudged rule: two phases, one local contrast, tied seams, labels or advantage-weighted actions
Trace, Echo, Afterglow the memory of the moment before: a decaying trace of a range, clamped into the next settlement; focused on what changed it is an afterimage of the picture
ActorCritic, Valence learning from reward: an eligibility trace over the contrast, times a dopamine that is the reward less its expectation, quiet for the usual, in proportion
conformance the owner-by-owner reference with a message ledger, to certify any backend
blocks the block transport: the overlap matrix as dense blocks between the wiring's owner ranges, a still range's product reused, so a step costs what the moving owners cost
timing the latency of a decision at the median and the tails, the scheduler's context switches, and the machine's state for a receipt
Protocol, Row, shuffled, select_gain declared held-out facts with preconditions, the shuffled control, gain selection under a sparsity cap
Receipt, Source, fetch canonical JSON bound to code and data by digest; pinned public data, downloaded once, verified always

Documentation

concepts what a patch net is, and why the library is shaped as it is
quickstart from a wiring to a verified receipt in seven calls
learning the rule in full: every equation, a worked example, every knob
differences patch net versus feed-forward network with backprop
games imitating a search; learning from reward; setting up credit
child the child's capabilities out of simpler components: one frame and an afterimage, a trace that credits a press paid later, a dopamine quiet for the usual; the small experiments and their numbers
condense the plan for 0.8: five elements and one step, what every public name becomes
tasks recipes for every kind of task the ladder and the Kaggle set have met
pages a trained net settling live in a browser
embodied deploying in a body: the loop, several learners in one net, checkpoints
reward learning from reward: three factors, what the gates measured
protocols predicates, the shuffled control, gain selection
backends CPU and torch, precision, the block transport, timing a decision
receipts what a verified result is
api every public class and function

Against backprop, plainly

Same shape, same count of numbers, same data: on the supervised rungs of the examples the rule reaches the accuracy of the backprop baseline in fewer passes over the data; from reward it learns less than REINFORCE with Adam from the same rollouts (Pong: 88% of balls against 93%). It costs ten to a hundred times the wall-clock on a laptop core, because a settlement is tens of steps where a pass is one. It gives no parameter advantage: a seam is a weight. Every receipt records all three numbers.

Discipline

  1. Owner-local or nothing. The reference engine reads one owner and its inbox at a time and ledgers every delivery; conformance compares any backend against it.
  2. Held out means held out. Selection on training data only; a test set read once; a control that must fail.
  3. A result is a receipt. Canonical JSON, a digest, the digests of the code and data, every pass flag recomputable. A receipt that fails to verify is not a result.

Where it comes from

Cadence consolidates the lanes of the observer patch net programme: a C. elegans connectome scored against classical ablation phenotypes, the FlyWire Drosophila brain and the MANC nerve cord joined by their descending neurons and scored against held-out taste, grooming, escape, olfaction, and motor facts, and that nervous system driving a biomechanical fly in MuJoCo. Every one of those lanes is a wiring, a rule, a protocol, a control, and a receipt; the library is what they had in common. The learning rule is equilibrium propagation (Scellier and Bengio, 2017) written for the graded settlement, with a leak, tied seams, and a centered nudge.

Status

0.7.0: the core (wiring, rule, engine, reference, protocol, receipts, custody), the free/nudged learning rule with labels, teachers, and rewards, the three-factor learners, seams with a life, the block transport and the fused kernel, on NumPy, torch and MLX. Four worked rungs with receipts live in cadence-examples. On the roadmap: closure sub-nets for in-browser settlement of large wirings, environment adapters for embodiment, and connectome loaders. Issues and pull requests are welcome.

MIT licensed.

Release files for cadence-net 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cadence-net 0.8.0
File Size Uploaded
cadence_net-0.8.0.tar.gz 133.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cadence-net 0.8.0
File Interpreter ABI Platform
cadence_net-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 200.7 kB

Release files / cadence_net-0.8.0.tar.gz

Download URL cadence_net-0.8.0.tar.gz
Size 133.0 kB
Tags Source
SHA-256 checksum
How to use checksums
df7b6c9eddf81ff450192847190aa35c04cbcb987af09cfce6d793bcb4642ae3
BLAKE2b-256 checksum
How to use checksums
c82f5f3ad9f0812dbbcf33fbc5f5b5138aa98c0603c22717bced1bc8e1fb7bb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / cadence_net-0.8.0-py3-none-any.whl

Download URL cadence_net-0.8.0-py3-none-any.whl
Size 67.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4cdc379c791c1cfef9cf38a53c995e222f7df2038e8e21497d9ca86af2eb664
BLAKE2b-256 checksum
How to use checksums
a0e6cd4f43445092a75c298e3da4a02efd216ae2e1497010d392075855c48e4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release history Release notifications | RSS feed

0.15.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

This release

0.8.0 This release

2 release files

0.7.1

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page