@reicek/neataptic-ts 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/nn.jpg +0 -0
- package/package.json +5 -2
- package/plans/Architecture_Primitives_Node_Group_Layer.md +211 -0
- package/plans/Browser_Build_and_CDN_Distribution.md +158 -0
- package/plans/Construct_From_Parts_Graph_Assembly.md +164 -0
- package/plans/Evolution_Training_Interoperability_Contracts.md +190 -0
- package/plans/HyperEvoDevoMorphoNEAT.md +33 -0
- package/plans/Interactive_Examples_and_Learning_Path.md +111 -0
- package/plans/Network_Visualization_Export_Schema.md +136 -0
- package/plans/Population_Save_Resume_and_Checkpointing.md +188 -0
- package/plans/Preconfigured_Architectures_MLP_LSTM_GRU_NARX.md +148 -0
- package/plans/Roadmap.md +130 -0
- package/plans/Stable_Activation_Ordering_and_Explicit_IO_Roles.md +180 -0
- package/plans/Standalone_Inference_Export.md +164 -0
- package/plans/Turnkey_Multithread_Evaluation_API.md +159 -0
- package/plans/Worker_Friendly_Network_Serialization_Fastpath.md +152 -0
- package/plans/neat.plans.md +97 -68
- package/scripts/assets/nn.jpg +0 -0
- package/scripts/assets/theme.css +34 -0
- package/scripts/copy-examples.mjs +80 -1
- package/scripts/render-docs-html.ts +120 -26
- package/src/README.md +11 -0
- package/src/architecture/README.md +11 -0
- package/src/architecture/network/README.md +30 -0
- package/src/architecture/network/activate/README.md +9 -6
- package/src/architecture/network/activate/network.activate.utils.types.ts +36 -33
- package/src/architecture/network/genetic/README.md +0 -8
- package/src/architecture/network/genetic/network.genetic.setup.utils.ts +2 -17
- package/src/architecture/network/network.types.ts +28 -0
- package/src/architecture/network/network.utils.ts +1 -0
- package/src/architecture/network/serialize/README.md +22 -6
- package/src/architecture/network/serialize/network.serialize.runtime.utils.ts +5 -14
- package/src/architecture/network/serialize/network.serialize.utils.ts +52 -0
- package/src/architecture/network/serialize/network.serialize.utils.types.ts +0 -10
- package/src/architecture/network/topology/README.md +160 -0
- package/src/architecture/network/topology/network.topology.architecture.utils.ts +520 -0
- package/src/architecture/network.ts +33 -0
- package/src/neat/neat.evolve.population.utils.ts +17 -8
- package/test/examples/asciiMaze/evolutionEngine/evolutionLoop.ts +17 -1
- package/test/examples/asciiMaze/index.html +29 -8
- package/test/examples/flappy_bird/README.md +122 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.host.utils.ts +324 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.math.utils.ts +66 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.network-view.utils.ts +399 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.observation.utils.ts +210 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.playback.utils.ts +717 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.render.types.ts +34 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.runtime.types.ts +16 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.simulation.types.ts +55 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.spawn.utils.ts +142 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.stats.types.ts +45 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.stats.utils.ts +119 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.telemetry.utils.ts +90 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.text-frame.utils.ts +286 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.ts +2 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.types.ts +6 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.utils.ts +12 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.viewport.utils.ts +58 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.types.ts +66 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.visualization.utils.ts +900 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.worker-channel.utils.ts +46 -0
- package/test/examples/flappy_bird/browser-entry/browser-entry.worker.types.ts +82 -0
- package/test/examples/flappy_bird/browser-entry/host/host.canvas.service.ts +73 -0
- package/test/examples/flappy_bird/browser-entry/host/host.constants.ts +24 -0
- package/test/examples/flappy_bird/browser-entry/host/host.dom.service.ts +18 -0
- package/test/examples/flappy_bird/browser-entry/host/host.resize.service.ts +295 -0
- package/test/examples/flappy_bird/browser-entry/host/host.stats.service.ts +142 -0
- package/test/examples/flappy_bird/browser-entry/host/host.ts +32 -0
- package/test/examples/flappy_bird/browser-entry/host/host.types.ts +20 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.constants.ts +10 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.draw.service.ts +148 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.labels.utils.ts +68 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.layout.utils.ts +205 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.ts +48 -0
- package/test/examples/flappy_bird/browser-entry/network-view/network-view.types.ts +10 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.constants.ts +12 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.errors.ts +15 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.loop.service.ts +14 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.render.service.ts +116 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.render.utils.ts +60 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.service.ts +149 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.starfield.utils.ts +34 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.trail.utils.ts +86 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.ts +30 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.types.ts +22 -0
- package/test/examples/flappy_bird/browser-entry/playback/playback.worker-channel.utils.ts +123 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.browser-globals.service.ts +52 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.errors.ts +43 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.evolution-loop.service.ts +170 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.telemetry.service.ts +132 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.ts +153 -0
- package/test/examples/flappy_bird/browser-entry/runtime/runtime.types.ts +19 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.colors.utils.ts +328 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.constants.ts +19 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.draw.service.ts +70 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.errors.ts +27 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.legend.utils.ts +17 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.topology.utils.ts +36 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.ts +23 -0
- package/test/examples/flappy_bird/browser-entry/visualization/visualization.types.ts +19 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.errors.ts +39 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.generation.service.ts +28 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.playback.service.ts +34 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.request.service.ts +77 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.ts +5 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.types.ts +30 -0
- package/test/examples/flappy_bird/browser-entry/worker-channel/worker-channel.url.service.ts +18 -0
- package/test/examples/flappy_bird/constants/constants.birds.ts +80 -0
- package/test/examples/flappy_bird/constants/constants.difficulty.ts +84 -0
- package/test/examples/flappy_bird/constants/constants.fitness.ts +41 -0
- package/test/examples/flappy_bird/constants/constants.frame.ts +74 -0
- package/test/examples/flappy_bird/constants/constants.layout.ts +90 -0
- package/test/examples/flappy_bird/constants/constants.network-view.ts +217 -0
- package/test/examples/flappy_bird/constants/constants.network.ts +30 -0
- package/test/examples/flappy_bird/constants/constants.observation.ts +14 -0
- package/test/examples/flappy_bird/constants/constants.palette.ts +95 -0
- package/test/examples/flappy_bird/constants/constants.physics.ts +45 -0
- package/test/examples/flappy_bird/constants/constants.pipe-render.ts +45 -0
- package/test/examples/flappy_bird/constants/constants.pipes.ts +56 -0
- package/test/examples/flappy_bird/constants/constants.rendering.ts +13 -0
- package/test/examples/flappy_bird/constants/constants.runtime.ts +62 -0
- package/test/examples/flappy_bird/constants/constants.starfield.ts +26 -0
- package/test/examples/flappy_bird/constants/constants.stats.ts +90 -0
- package/test/examples/flappy_bird/constants/constants.ts +49 -0
- package/test/examples/flappy_bird/constants/constants.world.ts +43 -0
- package/test/examples/flappy_bird/environment/environment.collision.utils.ts +66 -0
- package/test/examples/flappy_bird/environment/environment.constants.ts +15 -0
- package/test/examples/flappy_bird/environment/environment.observation.utils.ts +104 -0
- package/test/examples/flappy_bird/environment/environment.state.service.ts +59 -0
- package/test/examples/flappy_bird/environment/environment.step.service.ts +210 -0
- package/test/examples/flappy_bird/environment/environment.ts +7 -0
- package/test/examples/flappy_bird/environment/environment.types.ts +88 -0
- package/test/examples/flappy_bird/evaluation/evaluation.constants.ts +53 -0
- package/test/examples/flappy_bird/evaluation/evaluation.fitness.utils.ts +75 -0
- package/test/examples/flappy_bird/evaluation/evaluation.rollout.service.ts +378 -0
- package/test/examples/flappy_bird/evaluation/evaluation.seed.utils.ts +24 -0
- package/test/examples/flappy_bird/evaluation/evaluation.statistics.utils.ts +61 -0
- package/test/examples/flappy_bird/evaluation/evaluation.ts +7 -0
- package/test/examples/flappy_bird/evaluation/evaluation.types.ts +76 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.constants.ts +20 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.errors.ts +48 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.evolution.service.ts +59 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.playback.service.ts +212 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.protocol.service.ts +87 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.runtime.service.ts +48 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.simulation.utils.ts +274 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.snapshot.utils.ts +37 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +488 -0
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.types.ts +161 -0
- package/test/examples/flappy_bird/flappy.simulation.shared.utils.ts +32 -0
- package/test/examples/flappy_bird/flappyEnvironment.ts +46 -0
- package/test/examples/flappy_bird/flappyEvaluation.ts +11 -0
- package/test/examples/flappy_bird/flappyEvolution.worker.ts +3 -0
- package/test/examples/flappy_bird/index.html +106 -0
- package/test/examples/flappy_bird/index.ts +11 -0
- package/test/examples/flappy_bird/rng.ts +70 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.constants.ts +11 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.control.utils.ts +25 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.difficulty.utils.ts +54 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.errors.ts +15 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.math.utils.ts +49 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.memory.utils.ts +129 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.observation.utils.ts +406 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.spawn.utils.ts +126 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.ts +15 -0
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.types.ts +149 -0
- package/test/examples/flappy_bird/trainFlappyBird.ts +16 -0
- package/test/examples/flappy_bird/trainer/trainer.constants.ts +101 -0
- package/test/examples/flappy_bird/trainer/trainer.errors.ts +15 -0
- package/test/examples/flappy_bird/trainer/trainer.evaluation-plan.utils.ts +197 -0
- package/test/examples/flappy_bird/trainer/trainer.fitness.service.ts +131 -0
- package/test/examples/flappy_bird/trainer/trainer.loop.service.ts +67 -0
- package/test/examples/flappy_bird/trainer/trainer.reporting.utils.ts +37 -0
- package/test/examples/flappy_bird/trainer/trainer.setup.service.ts +88 -0
- package/test/examples/flappy_bird/trainer/trainer.signals.service.ts +29 -0
- package/test/examples/flappy_bird/trainer/trainer.statistics.utils.ts +78 -0
- package/test/examples/flappy_bird/trainer/trainer.ts +635 -0
- package/test/examples/flappy_bird/trainer/trainer.types.ts +76 -0
- package/test/neat/neat.offspring.allocation.test.ts +16 -0
- package/test/network/architecture.descriptor.test.ts +111 -0
- package/tsconfig.test.json +2 -0
- package/plans/network-main-utils-split.md +0 -29
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<a href="docs/index.html"><img src="https://img.shields.io/badge/docs-generated-2c3963.svg" alt="Docs"/></a>
|
|
6
6
|
</div>
|
|
7
7
|
|
|
8
|
-
<img src="
|
|
8
|
+
<img src="nn.jpg" width="480"/>
|
|
9
9
|
|
|
10
10
|
> The unofficial modern, typed evolution of **Neataptic**.
|
|
11
11
|
|
package/nn.jpg
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reicek/neataptic-ts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Architecture-free neural network library with genetic algorithm implementations",
|
|
5
5
|
"main": "./dist/neataptic.js",
|
|
6
6
|
"module": "./dist/neataptic.js",
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
"build:ts": "tsc",
|
|
18
18
|
"build:webpack": "webpack --config webpack.config.js",
|
|
19
19
|
"build:ascii-maze": "npx esbuild test/examples/asciiMaze/browser-entry.ts --bundle --outfile=docs/assets/ascii-maze.bundle.js --platform=browser --format=iife --minify --sourcemap --external:fs --external:child_process --external:path",
|
|
20
|
+
"build:flappy-worker": "npx esbuild test/examples/flappy_bird/flappyEvolution.worker.ts --bundle --outfile=docs/assets/flappy-evolution.worker.bundle.js --platform=browser --format=iife --minify --sourcemap --external:fs --external:child_process --external:path",
|
|
21
|
+
"build:flappy-bird": "npx esbuild test/examples/flappy_bird/browser-entry/browser-entry.ts --bundle --outfile=docs/assets/flappy-bird.bundle.js --platform=browser --format=iife --minify --sourcemap --external:fs --external:child_process --external:path",
|
|
22
|
+
"start:local-server": "npx http-server . -p 8080 -c-1",
|
|
20
23
|
"start:ts": "ts-node src/neataptic.ts",
|
|
21
24
|
"test:e2e": "cross-env FORCE_COLOR=true jest e2e.test.ts --no-cache --runInBand",
|
|
22
25
|
"test:e2e:logs": "npx jest e2e.test.ts --verbose --runInBand --no-cache",
|
|
@@ -28,7 +31,7 @@
|
|
|
28
31
|
"prettier": "npm run prettier:tests && npm run prettier:src",
|
|
29
32
|
"prettier:tests": "npx prettier --write test/**/*.ts",
|
|
30
33
|
"prettier:src": "npx prettier --write src/**/*.ts",
|
|
31
|
-
"docs": "npm run build:ascii-maze && npm run docs:examples && npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js && node ./dist-docs/scripts/render-docs-html.js",
|
|
34
|
+
"docs": "npm run build:ascii-maze && npm run build:flappy-worker && npm run build:flappy-bird && npm run docs:examples && npm run docs:build-scripts && node ./dist-docs/scripts/generate-docs.js && node ./dist-docs/scripts/render-docs-html.js",
|
|
32
35
|
"lint": "eslint src/ test/",
|
|
33
36
|
"lint:fix": "eslint src/ --fix",
|
|
34
37
|
"onnx:export": "node scripts/export-onnx.mjs"
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# Architecture Primitives (Node / Group / Layer) Plan
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Introduce a **first-class architecture-building API** that lets users construct networks from composable primitives (nodes, groups, layers), while staying compatible with:
|
|
6
|
+
|
|
7
|
+
- Evolution (topology + weights)
|
|
8
|
+
- Optional gradient fine-tuning
|
|
9
|
+
- Telemetry and reproducibility
|
|
10
|
+
|
|
11
|
+
This plan focuses on **ergonomic graph construction** and **strong typing**, not on changing the core evolutionary algorithms.
|
|
12
|
+
|
|
13
|
+
## Why this matters
|
|
14
|
+
|
|
15
|
+
Many users want to:
|
|
16
|
+
|
|
17
|
+
- Build a custom graph (including gating/modulatory patterns) before evolving.
|
|
18
|
+
- Swap parts of a network (e.g., replace an encoder) without rewriting controllers.
|
|
19
|
+
- Teach the library “this is input / this is output” without relying on fragile indexing.
|
|
20
|
+
|
|
21
|
+
A primitives API also becomes the foundation for:
|
|
22
|
+
|
|
23
|
+
- preconfigured architectures (separate plan)
|
|
24
|
+
- visualization export (separate plan)
|
|
25
|
+
- browser examples (separate plan)
|
|
26
|
+
|
|
27
|
+
## Goals
|
|
28
|
+
|
|
29
|
+
- G1: Provide minimal primitives that can express arbitrary directed graphs.
|
|
30
|
+
- G2: Make input/output designation explicit and robust.
|
|
31
|
+
- G3: Ensure primitives can be compiled into the existing `Network` execution model.
|
|
32
|
+
- G4: Preserve current public API; primitives are additive.
|
|
33
|
+
|
|
34
|
+
## Non-goals
|
|
35
|
+
|
|
36
|
+
- Replacing the existing `Network` class.
|
|
37
|
+
- Designing a full deep-learning layers DSL (Conv/Attention/etc).
|
|
38
|
+
- Introducing any breaking changes in NEAT controller behavior.
|
|
39
|
+
|
|
40
|
+
## Proposed primitives
|
|
41
|
+
|
|
42
|
+
### `NeuronNode` (or `Node`)
|
|
43
|
+
|
|
44
|
+
A lightweight object that represents a neuron-like unit with:
|
|
45
|
+
|
|
46
|
+
- id (stable)
|
|
47
|
+
- type (`input` | `hidden` | `output` | `constant`)
|
|
48
|
+
- bias, activation function, optional metadata
|
|
49
|
+
|
|
50
|
+
### `ConnectionEdge`
|
|
51
|
+
|
|
52
|
+
A connection between nodes:
|
|
53
|
+
|
|
54
|
+
- fromId, toId
|
|
55
|
+
- weight
|
|
56
|
+
- enabled flag
|
|
57
|
+
- optional gating/modulation reference
|
|
58
|
+
|
|
59
|
+
### `NodeGroup`
|
|
60
|
+
|
|
61
|
+
A collection of nodes with helper operations:
|
|
62
|
+
|
|
63
|
+
- create N nodes
|
|
64
|
+
- connect to another group with a connection policy
|
|
65
|
+
- gate a set of edges (optional, if supported)
|
|
66
|
+
|
|
67
|
+
### `Layer`
|
|
68
|
+
|
|
69
|
+
A specialization of group with explicit `inputNodes` and `outputNodes` to simplify connecting composite blocks.
|
|
70
|
+
|
|
71
|
+
## API sketch
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
export type NodeRole = 'input' | 'hidden' | 'output' | 'constant';
|
|
75
|
+
|
|
76
|
+
export interface NodeSpec {
|
|
77
|
+
role: NodeRole;
|
|
78
|
+
bias?: number;
|
|
79
|
+
activation?: Activation;
|
|
80
|
+
label?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class GraphNode {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
role: NodeRole;
|
|
86
|
+
bias: number;
|
|
87
|
+
activation: Activation;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface ConnectOptions {
|
|
91
|
+
weightInit?: WeightInitializer;
|
|
92
|
+
allowSelf?: boolean;
|
|
93
|
+
allowRecurrent?: boolean;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export class NodeGroup {
|
|
97
|
+
readonly nodes: readonly GraphNode[];
|
|
98
|
+
connect(
|
|
99
|
+
target: NodeGroup | GraphNode,
|
|
100
|
+
policy?: ConnectPolicy,
|
|
101
|
+
options?: ConnectOptions,
|
|
102
|
+
): GraphEdge[];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export class Layer extends NodeGroup {
|
|
106
|
+
readonly inputNodes: readonly GraphNode[];
|
|
107
|
+
readonly outputNodes: readonly GraphNode[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface GraphBuildResult {
|
|
111
|
+
network: Network;
|
|
112
|
+
mapping: {
|
|
113
|
+
nodeIdToNetworkIndex: Map<string, number>;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function constructNetwork(
|
|
118
|
+
parts: Array<NodeGroup | Layer | GraphNode>,
|
|
119
|
+
options?: ConstructOptions,
|
|
120
|
+
): GraphBuildResult;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
The library should keep naming consistent with existing exports, but the key is:
|
|
124
|
+
|
|
125
|
+
- stable ids
|
|
126
|
+
- explicit roles
|
|
127
|
+
- a single “construct” function that produces a `Network`.
|
|
128
|
+
|
|
129
|
+
## Implementation steps
|
|
130
|
+
|
|
131
|
+
### Step 1 — Define types and minimal classes
|
|
132
|
+
|
|
133
|
+
- Add new module folder, e.g. `src/architecture/primitives/`.
|
|
134
|
+
- Implement minimal `GraphNode`, `GraphEdge`, `NodeGroup`, and `Layer`.
|
|
135
|
+
|
|
136
|
+
Acceptance:
|
|
137
|
+
|
|
138
|
+
- Can create groups and connect them; edges are produced.
|
|
139
|
+
|
|
140
|
+
### Step 2 — Connection policies
|
|
141
|
+
|
|
142
|
+
Implement a small set of connection policies:
|
|
143
|
+
|
|
144
|
+
- `oneToOne`
|
|
145
|
+
- `allToAll`
|
|
146
|
+
- `allToAllForward` (acyclic-by-construction)
|
|
147
|
+
- `allToElse` (exclude same-node connections)
|
|
148
|
+
|
|
149
|
+
Acceptance:
|
|
150
|
+
|
|
151
|
+
- Policies are deterministic under seeded RNG/weight initializer.
|
|
152
|
+
|
|
153
|
+
### Step 3 — Define role inference rules (conservative)
|
|
154
|
+
|
|
155
|
+
Construction must not guess aggressively.
|
|
156
|
+
|
|
157
|
+
Rules:
|
|
158
|
+
|
|
159
|
+
- If any nodes are explicitly marked `input`/`output`, use those.
|
|
160
|
+
- If not, require the user to specify via options.
|
|
161
|
+
- Provide a helper that can infer only when unambiguous, but default to explicit.
|
|
162
|
+
|
|
163
|
+
Acceptance:
|
|
164
|
+
|
|
165
|
+
- Ambiguous graphs throw descriptive errors.
|
|
166
|
+
|
|
167
|
+
### Step 4 — Compile primitives into a `Network`
|
|
168
|
+
|
|
169
|
+
- Implement `constructNetwork(...)`:
|
|
170
|
+
- resolve nodes in stable order
|
|
171
|
+
- create a `Network` with correct input/output sizes
|
|
172
|
+
- add nodes in the correct order
|
|
173
|
+
- materialize connections and optional gating references
|
|
174
|
+
|
|
175
|
+
Acceptance:
|
|
176
|
+
|
|
177
|
+
- Constructed network activates and produces outputs.
|
|
178
|
+
|
|
179
|
+
### Step 5 — JSDoc + docs map
|
|
180
|
+
|
|
181
|
+
- Document the primitives as an educational feature.
|
|
182
|
+
- Provide 2–3 short examples:
|
|
183
|
+
- MLP via groups
|
|
184
|
+
- custom graph via nodes
|
|
185
|
+
- layer chaining
|
|
186
|
+
|
|
187
|
+
Acceptance:
|
|
188
|
+
|
|
189
|
+
- Docs generator includes the new APIs cleanly.
|
|
190
|
+
|
|
191
|
+
## Testing strategy
|
|
192
|
+
|
|
193
|
+
- Unit tests for policies and construct:
|
|
194
|
+
- builds correct node counts
|
|
195
|
+
- preserves explicit input/output roles
|
|
196
|
+
- rejects ambiguous graphs
|
|
197
|
+
- deterministic construction under seed
|
|
198
|
+
- Typecheck: `npx tsc --noEmit -p tsconfig.json`
|
|
199
|
+
|
|
200
|
+
## Risks and mitigations
|
|
201
|
+
|
|
202
|
+
- Risk: duplicating concepts already in `Network`.
|
|
203
|
+
- Mitigation: primitives compile _into_ `Network`; do not fork execution.
|
|
204
|
+
- Risk: confusion about "graph" vs "genome" semantics.
|
|
205
|
+
- Mitigation: docs clarify: primitives are for building initial phenotypes; NEAT still operates on genomes.
|
|
206
|
+
|
|
207
|
+
## Success criteria
|
|
208
|
+
|
|
209
|
+
- Users can construct non-trivial architectures without touching internal arrays.
|
|
210
|
+
- The constructed network works with evolution and training flows.
|
|
211
|
+
- No breaking changes to existing imports.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Browser Build + CDN Distribution Plan
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Make NeatapticTS effortless to use in the browser:
|
|
6
|
+
|
|
7
|
+
- Provide **official browser bundles** (ESM + IIFE) with a stable public surface.
|
|
8
|
+
- Enable **copy/paste quickstarts** for demos, education, and interactive docs.
|
|
9
|
+
- Preserve Node-first correctness and determinism.
|
|
10
|
+
|
|
11
|
+
This plan is strictly about packaging, compatibility, and documentation—not new algorithms.
|
|
12
|
+
|
|
13
|
+
## Why this matters
|
|
14
|
+
|
|
15
|
+
A library can be technically excellent and still lose adoption if the first run experience is hard. Browser support unlocks:
|
|
16
|
+
|
|
17
|
+
- Interactive documentation and “try it live” examples.
|
|
18
|
+
- Lightweight playgrounds for evolution experiments.
|
|
19
|
+
- Classroom use (no Node install, no build pipeline).
|
|
20
|
+
|
|
21
|
+
## Goals
|
|
22
|
+
|
|
23
|
+
- G1: Produce a **browser ESM build** that works with modern bundlers and native ESM.
|
|
24
|
+
- G2: Produce a **single-file IIFE build** for `<script>` usage.
|
|
25
|
+
- G3: Ensure the browser build has a clearly defined public API entry (no deep imports).
|
|
26
|
+
- G4: Keep Node builds unchanged and fully supported.
|
|
27
|
+
|
|
28
|
+
## Non-goals
|
|
29
|
+
|
|
30
|
+
- Implementing new NEAT features (tracked elsewhere).
|
|
31
|
+
- Supporting legacy browsers requiring heavy polyfills.
|
|
32
|
+
- Guaranteeing identical performance characteristics vs Node.
|
|
33
|
+
|
|
34
|
+
## Compatibility target
|
|
35
|
+
|
|
36
|
+
- Modern evergreen browsers (Chromium, Firefox, Safari) with ES2023-ish features.
|
|
37
|
+
- If a feature requires Node-only APIs (fs, worker_threads), it must be:
|
|
38
|
+
- compiled out of the browser bundle, or
|
|
39
|
+
- behind a runtime capability check with a clear error.
|
|
40
|
+
|
|
41
|
+
## Public API (browser)
|
|
42
|
+
|
|
43
|
+
Provide a stable top-level namespace export.
|
|
44
|
+
|
|
45
|
+
Proposed browser entry exports:
|
|
46
|
+
|
|
47
|
+
- `Neat`
|
|
48
|
+
- `Network`
|
|
49
|
+
- `Architect` (if present)
|
|
50
|
+
- `methods` / activations / cost functions (where applicable)
|
|
51
|
+
- Optional: `version`
|
|
52
|
+
|
|
53
|
+
Avoid exporting internal/private helpers.
|
|
54
|
+
|
|
55
|
+
## Build artifacts
|
|
56
|
+
|
|
57
|
+
Add/standardize these artifacts under `dist/`:
|
|
58
|
+
|
|
59
|
+
- `dist/neataptic.browser.esm.js` (ESM)
|
|
60
|
+
- `dist/neataptic.browser.iife.js` (IIFE)
|
|
61
|
+
- `dist/neataptic.browser.iife.min.js` (minified)
|
|
62
|
+
- Source maps for all where practical
|
|
63
|
+
|
|
64
|
+
Naming can be adjusted to fit current conventions; the key is that we ship both ESM and IIFE.
|
|
65
|
+
|
|
66
|
+
## Implementation steps
|
|
67
|
+
|
|
68
|
+
### Step 1 — Define browser entry module
|
|
69
|
+
|
|
70
|
+
- Create a dedicated browser entry file (example name):
|
|
71
|
+
- `src/browser-entry.ts`
|
|
72
|
+
- Re-export only supported browser-safe symbols.
|
|
73
|
+
- Ensure no Node-only modules are imported transitively.
|
|
74
|
+
|
|
75
|
+
Acceptance:
|
|
76
|
+
|
|
77
|
+
- A simple `import { Neat } from './dist/neataptic.browser.esm.js'` works.
|
|
78
|
+
|
|
79
|
+
### Step 2 — Split Node-only concerns behind environment adapters
|
|
80
|
+
|
|
81
|
+
- Introduce “environment adapter” modules so imports are browser-safe:
|
|
82
|
+
- `src/env/node/*`
|
|
83
|
+
- `src/env/browser/*`
|
|
84
|
+
- `src/env/index.ts` that chooses by build target (compile-time), not runtime.
|
|
85
|
+
|
|
86
|
+
Notes:
|
|
87
|
+
|
|
88
|
+
- If runtime selection is needed, use capability checks, not user-agent sniffing.
|
|
89
|
+
|
|
90
|
+
Acceptance:
|
|
91
|
+
|
|
92
|
+
- Browser bundle has no references to Node built-ins (`fs`, `path`, `worker_threads`).
|
|
93
|
+
|
|
94
|
+
### Step 3 — Add explicit bundling pipeline
|
|
95
|
+
|
|
96
|
+
Use existing tooling already present in repo:
|
|
97
|
+
|
|
98
|
+
- Keep `webpack.config.js` for main dist build if desired.
|
|
99
|
+
- Add a small `esbuild`/webpack target for browser artifacts.
|
|
100
|
+
|
|
101
|
+
Add scripts (names illustrative):
|
|
102
|
+
|
|
103
|
+
- `npm run build:browser`
|
|
104
|
+
- `npm run build:browser:min`
|
|
105
|
+
|
|
106
|
+
Acceptance:
|
|
107
|
+
|
|
108
|
+
- `npm run build` continues to work.
|
|
109
|
+
- `npm run build:browser` produces the expected dist files.
|
|
110
|
+
|
|
111
|
+
### Step 4 — Document browser usage
|
|
112
|
+
|
|
113
|
+
Add a dedicated docs page:
|
|
114
|
+
|
|
115
|
+
- `docs/` content or a `README` section describing:
|
|
116
|
+
- script tag IIFE usage
|
|
117
|
+
- ESM usage
|
|
118
|
+
- limitations (threads, filesystem, perf)
|
|
119
|
+
|
|
120
|
+
Acceptance:
|
|
121
|
+
|
|
122
|
+
- A user can run a minimal evolve loop in the browser with 10–20 lines.
|
|
123
|
+
|
|
124
|
+
### Step 5 — Add a CI smoke check
|
|
125
|
+
|
|
126
|
+
Without introducing heavy browser testing:
|
|
127
|
+
|
|
128
|
+
- Add a small build-time smoke check that:
|
|
129
|
+
- imports the browser ESM output
|
|
130
|
+
- runs a trivial activation on a toy network
|
|
131
|
+
|
|
132
|
+
Acceptance:
|
|
133
|
+
|
|
134
|
+
- Build fails if the browser bundle is broken.
|
|
135
|
+
|
|
136
|
+
## Testing strategy
|
|
137
|
+
|
|
138
|
+
- TypeScript: `npx tsc --noEmit -p tsconfig.json`
|
|
139
|
+
- Build: `npm run build` and `npm run build:browser`
|
|
140
|
+
- Minimal runtime smoke:
|
|
141
|
+
- Node loads `dist/neataptic.browser.esm.js` (as ESM) and runs a simple call.
|
|
142
|
+
- Optional: a headless browser run (Puppeteer exists in dev deps) for a single-page smoke.
|
|
143
|
+
|
|
144
|
+
## Risks and mitigations
|
|
145
|
+
|
|
146
|
+
- Risk: accidental Node-only transitive imports.
|
|
147
|
+
- Mitigation: keep browser entry small; use env adapters.
|
|
148
|
+
- Risk: tree-shaking breaks side-effect assumptions.
|
|
149
|
+
- Mitigation: mark side-effectful modules clearly; add smoke tests.
|
|
150
|
+
- Risk: bundle size grows.
|
|
151
|
+
- Mitigation: export only essentials; avoid large optional modules by default.
|
|
152
|
+
|
|
153
|
+
## Success criteria
|
|
154
|
+
|
|
155
|
+
- `npm run build:browser` produces ESM + IIFE outputs.
|
|
156
|
+
- A minimal browser example works without bundlers.
|
|
157
|
+
- Node build remains unchanged.
|
|
158
|
+
- Documentation includes at least one runnable browser example.
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Construct From Parts (Deterministic Graph Assembly) Plan
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
Provide a deterministic, validated way to build a runnable `Network` from user-defined parts (nodes/groups/layers), with:
|
|
6
|
+
|
|
7
|
+
- explicit input/output handling
|
|
8
|
+
- a stable activation schedule
|
|
9
|
+
- clear error messages for ambiguous/invalid graphs
|
|
10
|
+
|
|
11
|
+
This is the correctness backbone for the primitives API and preconfigured architectures.
|
|
12
|
+
|
|
13
|
+
## Goals
|
|
14
|
+
|
|
15
|
+
- G1: Deterministic construction (same parts + seed ⇒ same built network).
|
|
16
|
+
- G2: Robust validation (fail fast, descriptive errors).
|
|
17
|
+
- G3: Stable activation ordering for acyclic graphs; well-defined handling for recurrence.
|
|
18
|
+
- G4: Constructed networks seamlessly work with evolution/training.
|
|
19
|
+
|
|
20
|
+
## Non-goals
|
|
21
|
+
|
|
22
|
+
- Replacing NEAT genome operators.
|
|
23
|
+
- Fully general static scheduling for arbitrary cyclic graphs without explicit recurrence semantics.
|
|
24
|
+
|
|
25
|
+
## Key design decisions
|
|
26
|
+
|
|
27
|
+
### 1) Input/output nodes must be explicit by default
|
|
28
|
+
|
|
29
|
+
We should not silently guess I/O roles from degree heuristics except behind an explicit opt-in flag.
|
|
30
|
+
|
|
31
|
+
### 2) Two construction modes
|
|
32
|
+
|
|
33
|
+
- **Acyclic mode** (default):
|
|
34
|
+
- require that edges can be topologically sorted
|
|
35
|
+
- compute a stable activation order
|
|
36
|
+
- **Recurrent mode** (opt-in):
|
|
37
|
+
- allow cycles
|
|
38
|
+
- define recurrence handling policy and state reset policy
|
|
39
|
+
|
|
40
|
+
### 3) Stable node identity
|
|
41
|
+
|
|
42
|
+
Construction uses stable node ids (string/number). Internal network indices are derived deterministically.
|
|
43
|
+
|
|
44
|
+
## API sketch
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
export interface ConstructOptions {
|
|
48
|
+
mode?: 'acyclic' | 'recurrent';
|
|
49
|
+
inputNodes?: string[];
|
|
50
|
+
outputNodes?: string[];
|
|
51
|
+
allowIsolatedHiddenNodes?: boolean;
|
|
52
|
+
validate?: {
|
|
53
|
+
forbidDuplicateEdges?: boolean;
|
|
54
|
+
forbidSelfEdges?: boolean;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ConstructDiagnostics {
|
|
59
|
+
nodeCount: number;
|
|
60
|
+
edgeCount: number;
|
|
61
|
+
detectedCycles: boolean;
|
|
62
|
+
activationOrder: number[]; // network indices
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function constructNetwork(
|
|
66
|
+
parts: Array<GraphNode | NodeGroup | Layer>,
|
|
67
|
+
options?: ConstructOptions,
|
|
68
|
+
): { network: Network; diagnostics: ConstructDiagnostics };
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Implementation steps
|
|
72
|
+
|
|
73
|
+
### Step 1 — Canonical graph extraction
|
|
74
|
+
|
|
75
|
+
- Flatten parts into canonical sets:
|
|
76
|
+
- nodes (unique by id)
|
|
77
|
+
- edges (unique by (fromId,toId,kind))
|
|
78
|
+
- Resolve conflicts deterministically:
|
|
79
|
+
- same node id with differing specs ⇒ error (unless exact-equal)
|
|
80
|
+
|
|
81
|
+
Acceptance:
|
|
82
|
+
|
|
83
|
+
- A graph can be built from mixed inputs (nodes + groups + layers).
|
|
84
|
+
|
|
85
|
+
### Step 2 — Validation layer
|
|
86
|
+
|
|
87
|
+
Implement validations with high-quality errors:
|
|
88
|
+
|
|
89
|
+
- missing nodes referenced by edges
|
|
90
|
+
- duplicate edges (optional)
|
|
91
|
+
- self edges (policy-controlled)
|
|
92
|
+
- acyclic mode: detect cycles and explain a minimal cycle path
|
|
93
|
+
- input/output constraints:
|
|
94
|
+
- at least one input and output
|
|
95
|
+
- inputs cannot have incoming edges (optional rule)
|
|
96
|
+
- outputs cannot have outgoing edges (optional rule)
|
|
97
|
+
|
|
98
|
+
Acceptance:
|
|
99
|
+
|
|
100
|
+
- Invalid graphs produce errors that tell users what to change.
|
|
101
|
+
|
|
102
|
+
### Step 3 — Activation scheduling
|
|
103
|
+
|
|
104
|
+
**Acyclic mode**
|
|
105
|
+
|
|
106
|
+
- Determine activation order by stable topological sort.
|
|
107
|
+
- Tie-breaker must be deterministic (e.g., by node id).
|
|
108
|
+
|
|
109
|
+
**Recurrent mode**
|
|
110
|
+
|
|
111
|
+
- Require explicit `mode:'recurrent'`.
|
|
112
|
+
- Define a policy:
|
|
113
|
+
- either use a fixed order that is stable but not a topological order
|
|
114
|
+
- and define how many “passes” per activation call (usually 1)
|
|
115
|
+
|
|
116
|
+
Acceptance:
|
|
117
|
+
|
|
118
|
+
- Acyclic graphs run with a proper topo order.
|
|
119
|
+
- Recurrent graphs run deterministically given the same initial state.
|
|
120
|
+
|
|
121
|
+
### Step 4 — Materialize into `Network`
|
|
122
|
+
|
|
123
|
+
- Create `Network` with correct input/output sizes.
|
|
124
|
+
- Map node ids to network indices.
|
|
125
|
+
- Add nodes to `Network` with role, bias, activation.
|
|
126
|
+
- Create connections with correct weights and enabled flags.
|
|
127
|
+
|
|
128
|
+
Acceptance:
|
|
129
|
+
|
|
130
|
+
- Built networks activate and return the expected output length.
|
|
131
|
+
|
|
132
|
+
### Step 5 — Diagnostics + developer tools
|
|
133
|
+
|
|
134
|
+
Add optional diagnostics to help users debug:
|
|
135
|
+
|
|
136
|
+
- export a compact graph JSON
|
|
137
|
+
- print a human-readable summary (counts, I/O ids, cycle info)
|
|
138
|
+
|
|
139
|
+
Acceptance:
|
|
140
|
+
|
|
141
|
+
- Users can introspect why a graph failed.
|
|
142
|
+
|
|
143
|
+
## Testing strategy
|
|
144
|
+
|
|
145
|
+
- Unit tests:
|
|
146
|
+
- stable topo order (same ids ⇒ same order)
|
|
147
|
+
- cycle detection yields a helpful cycle path
|
|
148
|
+
- recurrent mode requires explicit opt-in
|
|
149
|
+
- deterministic mapping from ids → indices
|
|
150
|
+
- Property tests (optional):
|
|
151
|
+
- generate DAGs, ensure schedule covers all nodes
|
|
152
|
+
|
|
153
|
+
## Risks and mitigations
|
|
154
|
+
|
|
155
|
+
- Risk: scheduling semantics for recurrent networks confuse users.
|
|
156
|
+
- Mitigation: require explicit mode, document state/clear behavior.
|
|
157
|
+
- Risk: graph builder becomes a second “Network”.
|
|
158
|
+
- Mitigation: builder only compiles into `Network`; no parallel runtime.
|
|
159
|
+
|
|
160
|
+
## Success criteria
|
|
161
|
+
|
|
162
|
+
- Users can assemble networks safely and deterministically.
|
|
163
|
+
- Activation order is stable and correct for DAGs.
|
|
164
|
+
- Recurrent graphs are supported with explicit, documented semantics.
|