cadence README

项目的 README,来自 github.com/muellerberndt/cadence。合并为一个 markdown 文件:README.md。

Cadence: a continuing brain with local state, memory and repair. Try the brains live at cadence.floatingpragma.ai

Cadence

Live demos · Pragma Research · Documentation · Application demos · Paper · PyPI · Contact

CI License: GPL v3

One continuing equilibrium brain: learn a world, act in it, repair what fails.

Cadence is a Python library for brains that learn while they live. Animal and human brains learn from experience and not by backpropagation with gradient descent. Cadence is designed the same way: its connections change locally while the brain keeps running.

Install

python -m pip install cadence-net==0.104.3

Python 3.11 or later and NumPy. "cadence-net[fast]==0.104.3" adds Numba and SciPy for speed (recommended); [apple] adds MLX for Apple silicon GPUs and [accel] PyTorch for NVIDIA GPUs.

A first brain

import numpy as np
from cadence import Brain

brain = Brain.compose(inputs=4, actions=2, arousal=True)  # 4 senses, 2 possible actions
observation = np.array([[1.0, 0.0, 0.0, 0.0]])            # what it senses at this moment
action = brain.live(observation)                          # it settles and chooses an action
reward = (action == 0).astype(float)                      # your world scores that action
next_observation = np.array([[0.0, 1.0, 0.0, 0.0]])
action = brain.live(next_observation, reward=reward)      # it learns from the score, acts again

The brain settles: its neurons drive each other until their activity comes to rest, the action is read from that state, and every synapse learns from the difference between two settles. There is no backward pass and no switch between training and use.

Guide What it gives you
1 Start here: your first brain the brain above, line by line: settling, lessons and rewards, the state it carries, saving
2 Assemble a brain senses by name, a map of things, memories, attention, an ear and a voice, in four whole brains
3 Space: tracking what is where a map that keeps things out of view and follows a hidden thing that moves
4 Sounds as symbols a sound heard alone brings its thing back, a voice says it, a reward makes it the answer
Live demos brains that see, move, play and keep learning, in the browser
API reference every public name, with its signature and refusals

More guides: a continuing life, train a brain, learning from reward, memory, tune and read a living brain, backends; the documentation index lists them all. The released documentation describes the installed package. Integrated learned world prediction, repair localized to what failed and cheap stable operation are work in progress; Cadence is alpha research software.

Cadence live demos: one brain design that sees, moves, plays and keeps learning. Robot arm, robot arena, Atari, Castlevania, Patch World and Tron, all running live in the browser. 363 of 400 games won against the perfect Connect Four solver.

▶ Try the brains live: cadence.floatingpragma.ai

Start with System 1

Brain.compose builds one association region of 64 neurons between the senses and the motor choice, and four memories: a working trace, a heard history, a recall memory and an associative store (the default brain). Under live the brain learns while young (its first 100 moments) or aroused by an outcome's surprise or by want, and otherwise answers greedily from one settle; under step it learns from every outcome and from teacher= labels. Everything else is opt-in (assemble a brain).

live takes the preceding action's measured reward, then chooses the next action for one continuing stream; supply one observation row per call. It needs arousal=True (the founder arousal settings). The working trace advances at every accepted moment, and so do the recall memory's slots. Tune named settings with compose or brain.retune(...) and inspect them with brain.describe() (tune and read). Continuous interaction covers arousal, resets and saved continuation.

For explicit teaching, batched streams or learning from every outcome, use the lower-level step loop, which works with or without arousal=True; its teacher= labels the current observation. The continuing brain example runs that loop through changed conditions and saved continuation.

A teacher label changes graph parameters. The default associative memory ignores labels. Add memory_choice=True when remembered demonstrations and outcomes should vote in the choice. Add learned_code=units, attention=True when the brain should retrieve a relevant recent context and its successor, and recall_heads=k when one answer needs several witnessed facts at once. The options can be used together. Memory starts with these common cases before giving the complete reference. A brain trained without a recall memory gets one later: brain.grow(recall=True), or new output slots with brain.grow(slots=...), returns a new brain, the trained one with the part added, settling as the trained one did until learning gives the part weight. brain.graft(donor, ...) puts trained regions of another brain into a larger one, such as a trained visual system, or a whole connectome as one region of a larger anatomy (grow and combine brains).

phases = brain.imagine([observation, next_observation])
assert phases  # Inspect phase.qualified before using an imagined response.

Imagination carries a private trace without changing live memory, random state or pending feedback; the composed brain builds no model of the world's consequences.

Each action solve reports its residual, qualification, sweeps and check counts in read-only brain.last_settlement, as start a continuing brain shows. An action whose settle exhausts its budget is refused without changing live state; qualification and refusal says when to retry live(observation) without resubmitting the reward.

To work from source, install the library repository root as an editable package:

python -m pip install -e .

Add optional System 2

recursive = Brain.compose(
    inputs=4, actions=2, modules=(16, 8), observers=(8,), seed=7,
    arousal=True,
)

Observer regions read and return influence to the base, motor regions and earlier observers. They join the same settlement and use the same interaction interface. Whether recursive feedback helps on a task is a question for experience and evaluation.

How a Cadence brain differs from a feed-forward network

Brain.compose(inputs=4, actions=2, modules=(64, 32, 16)) builds reciprocal regions whose activity settles together, so later regions shape earlier ones while an answer forms, and the action comes from the qualified neural state. The learner compares local activities in a free and a nudged phase, without a backward differentiation pass. The relevant comparison with a recurrent backprop network is acquired behavior and total work on the same task, as the comparison below sets out; the contracts state what each part guarantees.

Why Cadence

The library puts continuing state, reciprocal interpretation, local plasticity and memory behind one small interface. A saved brain resumes an action that awaits its actual outcome, and private imagination inspects responses without rewriting live experience. These are mechanisms for testing acquisition, retention and recovery through a life. Biological names describe functional software roles; one continuing equilibrium brain states the design direction.

The target includes full-sentence language and reusable world understanding; a small fixed-label task is a control.

For machine-learning readers

This section maps Cadence onto models you know: which brain corresponds to which familiar model, where each one's learning signal comes from, what the arrays look like and what the words mean. The application interface is Brain.compose(..., arousal=True), then brain.live(observation, reward=...) for each real outcome (tune and read, start a continuing brain); the families below are the numerical mechanisms underneath and beside it.

The picture

A Cadence brain is a set of patches joined by ports. A patch holds a bounded local state (the potentials of a group of neurons, or one context vector), reads its inputs through ports and updates by its declared equations. Graph models qualify a settled state and learn from detuned phases. The contract guide separates these cases.

Idealized equilibrium contrast under a symmetric energy model

Against models you know

Cadence Nearest familiar model What is different
Settling brain (Genome, develop, NeuralGraph, Learner) A continuous Hopfield or energy-based recurrent network trained by equilibrium propagation: rate neurons relax to a fixed point, and the gradient is the contrast of a free and a nudged fixed point. Any wiring, including a measured connectome. Reciprocal learning ties paired weights; an arbitrary directed import need not satisfy the gradient contract. A certificate says when settling is a contraction and how far the answer is from the equilibrium. Reward learns through eligibility traces and one broadcast prediction error.

The composed brain's memories key on the observation, on the fixed sparse code code=units (the observation code), or, opt-in, on a code the brain learns while it lives (learned_code=units, the learned code), both described under Code in the glossary. evolve mutates and selects genomes across lives (evolution). The opt-in Brain.compose(..., learned_code=units, attention=True) recipe uses that learned code as a two-moment Recall address and holds one selected memory read through the shared settle; with recall_heads=k it reads the same memories through k heads, each learning its own address (several heads). No read revises its query during that settle (memory guide).

Where the learning signal comes from

Compared with a backprop network

A network trained by backprop A Cadence brain
Reading an answer Evaluate the layers Settle to a fixed point with a residual check
State between inputs A cache or a separate memory A settled state, a carried context, a trace or a memory store, each explicit
Credit Reverse-mode differentiation Free and nudged contrasts for the settling brain; delta-rule writes for the memory stores
Exact-gradient conditions A differentiable computation For the contrast: a stable smooth equilibrium, symmetric effective weights, converged phases and a vanishing nudge
Work A forward and a backward pass Every step of the free and nudged phases plus the update
Memory of one event A replay buffer or fine-tuning One write into the store, read back at the same reading
Hardware GPU tensors NumPy float64 on the CPU, with Numba where installed; a new brain takes a CUDA (torch) or Apple (MLX) GPU in float32 where its size makes the device faster; in a web page under Pyodide, the same kernels in WebAssembly (backends)

The table compares update mechanisms. Networks trained by backprop can also be recurrent, online, model-based and memory-using, so a fair comparison measures acquired behaviour and total work on the same task and information.

Shapes

Model Inputs Targets State between calls Checkpoint
Composed Brain (batch, inputs) observations; one row for live step(teacher=...) labels the current observation; reward labels the preceding executed action Neural activity, working trace, optional efference copy, heard history, recall slots and their address map, the associative and episodic stores with the episodic temporal context, pending outcomes Brain.save / Brain.load keep the complete continuation
Neural graph / Learner a drive (batch, n), one column per neuron; features go on the input neurons integer labels (batch,) or (batch, slots) for Learner.step, or a target pattern (batch, n) for the phase calls BrainState per row; pass warm= to continue Learner.save / Learner.load, one .npz

Batch rows are independent streams sharing parameters. imagine is private: it changes no learned parameter, record or live activity, though cost counters may count its work.

Glossary

Reading the numbers

Measure settling, learning and memory maintenance separately on the same held-out data, and compare against the simple control the task admits: the majority outcome, persistence, a linear predictor, the search alone or the algorithmic solver. Evaluate a brain lists the checks and common missteps.

Further reading

The paper states the hypotheses, the theorems and the evidence.

Go further

MANIFESTO.md states the design points, including the language goal of whole consistent sentences from the settled state. Your own anatomy covers custom wiring. cadence-demos contains the application demos.

Documentation · API · Contributing · Changelog · Research tasks

Licensed under GPL-3.0.

Related projects and funding

Observer Patch Holography (OPH) is the related physics project. Its physics evidence is separate from Cadence's capability evidence. Pragma Research brings the projects together.

Cadence has an official memecoin on Solana, deployed by the Solana community. Its token address is 46doJPsSjEVMsNZm4b32UbbvbUXjFTM3TDPBWMM3pump (chart on Dexscreener). Its trading fees are routed to Bernhard Mueller to fund the project. Pragma Research holds none of the token. Cadence itself does not use it, and no integration into the core library is planned. We encourage the crypto community to build interesting projects that integrate it. Any other token using the Cadence name is unrelated to this project. Nothing here is financial advice.

Contact

Questions, collaboration and press: [email protected].

cadence (muellerberndt/cadence)

正在搜索数据库…

这是什么东西?Cadence 是一个面向通用智能的开放研究库:它是一组基于 NumPy 的'大脑',通过 settling 到平衡态来进行计算,再通过微调这个平衡态来学习,目标是像动物和人类那样,从真实经历中习得技能。
它是我写代码时调用的库,还是一个带界面的运行中的系统?它是一个 Python/NumPy 库,你在代码里用它组装大脑,而不是托管服务:没有任何东西托管在云端,也没有检查点文件;五个示例应用则以静态网页的形式在浏览器里运行。
我怎么上手?从 PyPI 安装这个包(链接在 README 开头),然后在 Python 里或浏览器里运行三个快速上手示例——每一个都能在几秒内用一个固定随机种子训练出一个大脑,并且每个神经元和突触都有动画演示。之后可以照着 'Build your own brain' 指南,用自己的数据一路做出一个训练好、评估过并保存下来的大脑。
它成熟吗——我现在能用它做出真正的应用吗?这是研究代码:通用智能是它宣称的目标,目前的库给出的是有边界的记忆、学习和控制方面的结果。五个示例是应用层面的验证,并不是这套架构的定义——某一个示例里的结果并不能证明能力能迁移到其他示例上。
我需要机器学习背景才能看懂它吗?文档是为机器学习从业者写的:每个大脑都会对应到你已经熟悉的模型,学习信号和维度形状都写得明明白白。如果你想先了解思路,浏览器里的快速上手示例不需要任何环境配置,就能讲清楚 equilibrium(平衡态)和 detuning(失谐)的概念。
这些大脑不用反向传播是怎么学习的?学习时会把大脑再 settle 一次,只是把输出朝目标结果方向轻推,然后按照每个突触在两次 settled 状态中自己两端乘积来移动它——这是一个纯局部的规则,所以没有任何东西被反向传播。大脑背后的基因组也可以在多代之间进行突变和选择。
在 record 补丁里 'sleep' 是做什么的?白天,一次写入遍历会把每个结果存进记录存储;夜里,慢权重从存储自己的'梦境'中学习。单次遍历只能得到一个小语法,对从未教过的组合达到 0.8 的成绩,而一晚的学习就能把慢权重单独提升到 1.0。
现在我能看到这些大脑实际做什么?五个浏览器示例:一条线虫在实测的 C. elegans 神经连接组上仅凭食物和痛苦两种结果、一生之内学会行动;Connect Four(四子棋),通过对假想棋盘的搜索读取一个靠观看完美棋手学到的价值函数;Amen,一个从寂静中构建出十六小节鼓、贝斯和音景的作曲器;Patch World,身体和线路在自然选择下不断演化;还有打瞌睡的猫,它能察觉自己的意外,并自己决定什么时候打盹、追捕和学习。
这里的 System 1 和 System 2 是什么意思?System 1 是默认的大脑:感知、记忆、可塑性和行动。System 2 是可选的递归式自我观察——同一种补丁会通过普通的端口读取大脑其余部分的信念、残差和意外,并只调整它够得着的东西:哪些证据算数、某个感觉在哪里采样、一次修复要跑多久。这种选择机制就是该项目所说的 attention(注意力)。
大小
157.3 MB
星标
637
时长
2个月
提交 · 90 天