mahdyfo/rotifer
Composer 安装命令:
composer require mahdyfo/rotifer
包简介
A genetic AI framework that evolves its own neural network architecture through biologically-inspired neuroevolution (AutoML)
关键字:
README 文档
README
A genetic AI framework that evolves its own neural networks - modelled on how life actually evolves.
Rotifer doesn't train networks with backpropagation. It evolves them: a population of organisms, each a neural network described entirely by its genome, competes and reproduces over generations. Topology, neuron count, and weights are all discovered automatically (AutoML / neuroevolution). On top of plain genetic search, Rotifer models the messy, powerful machinery of real evolution - geographic islands, epigenetic trauma, self-tuning mutation, and lifetime learning that children inherit.
Pure PHP. Watch it evolve live in your terminal or in a browser dashboard. Reproducible to the bit. Parallel across CPU cores.
composer install php bin/rotifer run xor # evolve XOR live in the terminal php bin/rotifer list # see all built-in problems
Why it's different
| Traditional deep learning | Rotifer |
|---|---|
| Fixed architecture you design | Architecture is discovered by evolution |
| Gradient descent / backprop | Genetic operators: crossover + mutation |
| One global model | A world of islands, each its own gene pool |
| Weights are everything | The genome is the network - one array of connection genes |
| A black box | Watch every generation evolve, in terminal or browser |
Core ideas
- Genome = network. A genome is just a list of connection genes (
from → to, weight). There are no separate weight matrices; the genome is the network. (src/Genome/) - Organism. A genome compiled into a runnable
Brainplus the things evolution cares about - fitness, age, and anEpigenome. (src/Organism/) - World of islands. The
Worldruns several semi-isolatedIslands ("villages"). Each evolves on its own and periodically migrates its best individuals to neighbours - spreading breakthroughs while preserving diversity. (src/Evolution/) - One seeded RNG tree. Every random choice flows through a seedable
Rng; the master seed derives an independent stream per island. Same seed ⇒ identical run, which makes evolution testable and parallel-safe. (src/Runtime/Rng.php) - Events, not print statements. The engine emits events; reporters render them - a terminal dashboard, a JSON stream for the web UI, or nothing at all. (
src/Observe/)
The biology
Every mechanism is independently switchable in a problem's config; turned off, it's a no-op.
- Epigenetic trauma - hardship leaves a heritable, decaying stress marker that makes a lineage's offspring mutate harder for a few generations, then fades. Inherited trauma that washes out over time.
- Adaptive mutation - each island raises mutation when it stalls (explore) and lowers it when improving (exploit).
- Lifetime learning - an organism refines its own weights during its life (the Baldwin effect). A configurable fraction of what it learns is written back into its genome and inherited (Lamarckian).
- Islands & migration - different demes drift toward different solutions and trade their best on a ring.
Run it
php bin/rotifer run xor # live terminal dashboard php bin/rotifer run weather_forecast # multi-class classification php bin/rotifer run flappy_bird # a game, learned with no training data php bin/rotifer run xor --seed=42 --quiet # reproducible, silent php bin/rotifer run auto_encoder --parallel=8 # evaluate across 8 worker processes
See it in the browser
# terminal 1 - stream the run to disk php bin/rotifer run flappy_bird --web # terminal 2 - serve the live dashboard, then open http://localhost:8080 php bin/rotifer serve flappy_bird
The web dashboard shows a live fitness chart, the champion's network graph (excitatory/inhibitory connections, weights on hover, changed wiring flashing before it settles), and an island map with mutation and trauma levels. From the control panel you can pick a problem, tune it, toggle each biology mechanism (every option has a hover description), and start/stop runs. When a run finishes the champion predictions table reports a success rate, you can feed the champion a custom input and watch each neuron light up by how strongly it fires, and you can build a brand-new problem ("+ New problem") just by typing in example inputs and the outputs you expect - the engine adapts to it with defaults recommended for that data.
Built-in problems
| Name | Kind | Shows off |
|---|---|---|
xor |
logic | evolving topology from scratch |
memory_recall |
sequence | recurrent memory networks |
phone_recall |
memory | recall a phone number from a constant input - pure recurrence |
auto_encoder |
unsupervised | compression through a bottleneck |
house_price |
regression | ordinary tabular data |
weather_forecast |
classification | multi-class output + islands/migration |
flappy_bird |
game | emergent control, no training data |
Teaching it your own task
A new task is one class. Define the data, the fitness, and the tuning - that's the entire surface.
namespace Rotifer\Problems; use Rotifer\Network\Activation\Sigmoid; use Rotifer\Network\Shape; use Rotifer\Organism\Organism; use Rotifer\Runtime\EvolutionConfig; use Rotifer\Runtime\Fitness\Problem; final class XorProblem implements Problem { public function name(): string { return 'xor'; } public function shape(): Shape { return new Shape(inputs: 3, outputs: 1); } public function data(): array { return [ [[1, 0, 0], [0]], [[1, 0, 1], [1]], [[1, 1, 0], [1]], [[1, 1, 1], [0]], ]; } public function fitness(Organism $organism, array $row): float { return 1.0 - abs($organism->outputs()[0] - $row[1][0]); } public function config(): EvolutionConfig { return EvolutionConfig::default() ->population(150)->islands(2)->generations(80) ->activation(new Sigmoid()) ->mutation(weight: 0.85, addNeuron: 0.05, addConnection: 0.12) ->adaptiveMutation(true) ->migration(everyGenerations: 8, topK: 2) ->seed(1234); } }
Drop it in problems/, then php bin/rotifer run xor. A row of [] in data() resets network memory between sequences. For episodic tasks (games), run the whole episode inside fitness() - see problems/FlappyBirdProblem.php.
Testing
composer test # all suites vendor/bin/phpunit --testsuite Unit
Because runs are reproducible, evolution itself is unit-tested (same seed ⇒ identical champion), alongside each genetic and biological mechanism.
On Windows, run the suite from PowerShell - the parallel tests spawn
php.exeworkers.
Project layout
src/
Genome/ NodeType, NodeRef, Gene, Genome (+distance), Weight
Network/ Brain (forward pass), GenomePruner, Activation/, Shape, NetworkSpec
Organism/ Organism, Epigenome
Evolution/ World, Island, OrganismFactory, IdSequence,
Reproduction/ Selection/
Adaptation/ Epigenetics/ Learning/ Migration/
Runtime/ EvolutionConfig, Rng, Fitness/ (Problem, evaluators, Scorer), Parallel/
Observe/ EventDispatcher, Event/, Reporter/ (terminal + JSON-stream)
Persistence/ Codec/ (Json, Binary, Hex), SnapshotStore
Web/ server.php + public/ (vanilla-JS dashboard)
Cli/ Console, ProblemRegistry
problems/ one class per task
bin/rotifer the command-line entry point
The original (pre-2.0) implementation is preserved in git history under the
v1.0.0-v1.1.0 tags.
Requirements
- PHP ≥ 8.2
- Composer
amphp/parallel(pulled in automatically) for--parallel
License
Apache-2.0
mahdyfo/rotifer 适用场景与选型建议
mahdyfo/rotifer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「neat」 「machine learning」 「ai」 「neuroevolution」 「Deep learning」 「neural networks」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mahdyfo/rotifer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mahdyfo/rotifer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mahdyfo/rotifer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
Neat HTTP components
Neat Service components
Automatically translate and review your content via Lokalise.
Neat HTTP server components
Simple and elegant tools for build web application.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2023-09-06