@reicek/neataptic-ts 0.1.26 → 0.1.27
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/.github/agents/boundary-mapper.agent.md +13 -8
- package/.github/agents/docs-scout.agent.md +14 -9
- package/.github/agents/plan-scout.agent.md +11 -6
- package/.github/agents/solid-split.agent.md +33 -17
- package/.github/copilot-instructions.md +100 -88
- package/.github/skills/educational-docs/SKILL.md +90 -40
- package/.github/skills/educational-docs/assets/mermaid-diagram-playbook.md +141 -141
- package/.github/skills/educational-docs/assets/visual-style-guide.md +1 -1
- package/.github/skills/plan-alignment/SKILL.md +1 -1
- package/.github/skills/solid-split/SKILL.md +54 -35
- package/.github/skills/solid-split/assets/docs-checklist.md +1 -1
- package/.github/skills/solid-split/assets/split-plan-template.md +41 -12
- package/.github/skills/solid-split/assets/split-workflow-checklist.md +4 -1
- package/.github/skills/test-fix-workflow/SKILL.md +12 -7
- package/.github/skills/trace-analyzer-extension/SKILL.md +1 -1
- package/.github/skills/trace-analyzer-extension/assets/extension-checklist.md +1 -1
- package/.github/skills/trace-analyzer-extension/references/analyzer-extension-workflow.md +1 -1
- package/.github/skills/trace-audit-reporting/SKILL.md +1 -1
- package/.github/skills/trace-audit-reporting/assets/performance-report-template.md +1 -1
- package/.github/skills/trace-audit-reporting/references/trace-analysis-workflow.md +1 -1
- package/.github/skills/tracker-handoff/SKILL.md +53 -5
- package/package.json +1 -1
- package/plans/Flappy_Bird_Folder_Documentation_Pass.logs.md +42 -0
- package/plans/Flappy_Bird_Folder_Documentation_Pass.md +22 -104
- package/plans/README.md +6 -2
- package/plans/Roadmap.md +35 -31
- package/plans/analyze-trace-solid-split.logs.md +35 -0
- package/plans/analyze-trace-solid-split.plans.md +21 -52
- package/plans/architecture-solid-split.logs.md +44 -0
- package/plans/architecture-solid-split.plans.md +20 -653
- package/plans/asciiMaze-typescript-repair.logs.md +35 -0
- package/plans/asciiMaze-typescript-repair.plans.md +30 -36
- package/plans/generate-docs-solid-split.logs.md +36 -0
- package/plans/generate-docs-solid-split.plans.md +21 -73
- package/plans/methods-docs.logs.md +37 -0
- package/plans/methods-docs.plans.md +22 -183
- package/plans/methods-solid-split.logs.md +41 -0
- package/plans/methods-solid-split.plans.md +23 -65
- package/plans/neat-docs.logs.md +38 -0
- package/plans/neat-docs.plans.md +21 -63
- package/plans/neat-test-surface-repair.logs.md +38 -0
- package/plans/neat-test-surface-repair.plans.md +24 -24
- package/plans/readme-first-section-pass.logs.md +63 -0
- package/plans/readme-first-section-pass.plans.md +42 -0
- package/plans/render-docs-html-solid-split.logs.md +36 -0
- package/plans/render-docs-html-solid-split.plans.md +20 -54
- package/plans/src-no-explicit-any-cleanup.logs.md +39 -0
- package/plans/src-no-explicit-any-cleanup.plans.md +23 -161
- package/plans/utils-docs.logs.md +37 -0
- package/plans/utils-docs.plans.md +20 -35
- package/src/README.md +88 -22
- package/src/architecture/README.md +94 -17
- package/src/architecture/activationArrayPool/README.md +53 -0
- package/src/architecture/activationArrayPool/activationArrayPool.ts +53 -0
- package/src/architecture/layer/README.md +94 -5
- package/src/architecture/layer/layer.ts +94 -5
- package/src/architecture/network/README.md +85 -14
- package/src/architecture/network/activate/README.md +301 -213
- package/src/architecture/network/activate/docs.order.json +9 -0
- package/src/architecture/network/activate/network.activate.utils.ts +90 -0
- package/src/architecture/network/connect/README.md +80 -3
- package/src/architecture/network/connect/docs.order.json +9 -0
- package/src/architecture/network/connect/network.connect.utils.ts +79 -0
- package/src/architecture/network/deterministic/README.md +96 -12
- package/src/architecture/network/deterministic/docs.order.json +10 -0
- package/src/architecture/network/deterministic/network.deterministic.utils.ts +90 -0
- package/src/architecture/network/evolve/README.md +286 -228
- package/src/architecture/network/evolve/docs.order.json +11 -0
- package/src/architecture/network/evolve/network.evolve.utils.ts +59 -0
- package/src/architecture/network/gating/README.md +58 -16
- package/src/architecture/network/gating/docs.order.json +9 -0
- package/src/architecture/network/gating/network.gating.utils.ts +43 -0
- package/src/architecture/network/genetic/README.md +75 -36
- package/src/architecture/network/genetic/docs.order.json +10 -0
- package/src/architecture/network/genetic/network.genetic.utils.ts +53 -17
- package/src/architecture/network/network.ts +91 -46
- package/src/architecture/network/standalone/README.md +309 -285
- package/src/architecture/network/standalone/docs.order.json +13 -0
- package/src/architecture/network/standalone/network.standalone.utils.ts +51 -28
- package/src/architecture/network.ts +94 -17
- package/src/architecture/nodePool/README.md +53 -0
- package/src/architecture/nodePool/nodePool.ts +53 -0
- package/src/methods/README.md +80 -34
- package/src/methods/methods.ts +80 -34
- package/src/methods/mutation/README.md +39 -93
- package/src/methods/mutation/mutation.ts +58 -0
- package/src/multithreading/README.md +114 -14
- package/src/multithreading/docs.order.json +5 -0
- package/src/multithreading/multi.ts +103 -7
- package/src/multithreading/types.ts +6 -1
- package/src/multithreading/workers/README.md +72 -2
- package/src/multithreading/workers/browser/README.md +39 -0
- package/src/multithreading/workers/browser/testworker.ts +40 -0
- package/src/multithreading/workers/node/README.md +50 -11
- package/src/multithreading/workers/node/docs.order.json +4 -0
- package/src/multithreading/workers/node/testworker.ts +43 -3
- package/src/multithreading/workers/workers.ts +36 -1
- package/src/neat/README.md +230 -152
- package/src/neat/adaptive/core/README.md +99 -42
- package/src/neat/adaptive/core/adaptive.core.ts +71 -14
- package/src/neat/adaptive/core/docs.order.json +8 -0
- package/src/neat/docs.order.json +9 -0
- package/src/neat/lineage/README.md +118 -16
- package/src/neat/lineage/lineage.ts +115 -13
- package/src/neat/neat.defaults.constants.ts +91 -13
- package/src/neat.ts +86 -20
- package/src/utils/README.md +71 -21
- package/src/utils/memory.ts +69 -19
- package/test/examples/asciiMaze/browser-entry/README.md +81 -8
- package/test/examples/asciiMaze/browser-entry/browser-entry.ts +81 -8
- package/test/examples/asciiMaze/dashboardManager/README.md +68 -4
- package/test/examples/asciiMaze/dashboardManager/dashboardManager.ts +68 -4
- package/test/examples/asciiMaze/evolutionEngine/README.md +1259 -1174
- package/test/examples/asciiMaze/evolutionEngine/docs.order.json +10 -0
- package/test/examples/asciiMaze/evolutionEngine/evolutionEngine.types.ts +87 -0
- package/test/examples/asciiMaze/mazeMovement/README.md +81 -4
- package/test/examples/asciiMaze/mazeMovement/mazeMovement.ts +81 -4
- package/test/examples/flappy_bird/browser-entry/README.md +64 -21
- package/test/examples/flappy_bird/browser-entry/browser-entry.ts +64 -21
- package/test/examples/flappy_bird/flappy-evolution-worker/README.md +98 -10
- package/test/examples/flappy_bird/flappy-evolution-worker/flappy-evolution-worker.ts +98 -10
- package/test/examples/flappy_bird/simulation-shared/README.md +88 -4
- package/test/examples/flappy_bird/simulation-shared/simulation-shared.types.ts +88 -4
|
@@ -1,68 +1,62 @@
|
|
|
1
1
|
# architecture/network/evolve
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
Network-level neuroevolution loop for improving one runnable graph in place.
|
|
4
|
+
|
|
5
|
+
This chapter sits between the lightweight `Network` facade and the broader
|
|
6
|
+
`neat/` subsystem. Call `network.evolve()` when the question is "improve
|
|
7
|
+
this graph against a supervised dataset" without first wiring a separate
|
|
8
|
+
experiment harness. The method treats the current network as a seed genome,
|
|
9
|
+
configures a short-lived NEAT runtime around it, evaluates descendants, then
|
|
10
|
+
copies the best discovered structure back into the original instance.
|
|
11
|
+
|
|
12
|
+
The folder is split by the same stages the public call executes. `setup`
|
|
13
|
+
validates dataset shape and resolves defaults. `fitness` turns prediction
|
|
14
|
+
error into a comparable score. `loop` owns generation-to-generation stopping
|
|
15
|
+
logic. `finalize` adopts the winning genome and tears down worker resources.
|
|
16
|
+
Keeping those shelves separate makes the README read like an evolution run
|
|
17
|
+
rather than an alphabetical pile of helpers.
|
|
18
|
+
|
|
19
|
+
```mermaid
|
|
20
|
+
flowchart LR
|
|
21
|
+
Seed[Seed Network] --> Normalize[Normalize options and dataset]
|
|
22
|
+
Normalize --> Fitness[Build fitness evaluator]
|
|
23
|
+
Fitness --> Neat[Create temporary NEAT runtime]
|
|
24
|
+
Neat --> Loop[Run evolve loop]
|
|
25
|
+
Loop --> Adopt[Adopt best genome into original network]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Use this boundary when you want a bounded local search over network
|
|
29
|
+
structure, not a long-lived population controller. `error` answers "stop
|
|
30
|
+
when good enough", `iterations` answers "stop after this many generations",
|
|
31
|
+
and `growth` answers "how much should extra structure cost while searching".
|
|
32
|
+
|
|
33
|
+
For compact background reading on the wider search family behind this folder,
|
|
34
|
+
see Wikipedia contributors,
|
|
35
|
+
[Evolutionary algorithm](https://en.wikipedia.org/wiki/Evolutionary_algorithm).
|
|
36
|
+
The implementation here is intentionally narrower: it keeps the public call
|
|
37
|
+
site small while reusing the repo's NEAT runtime under the hood.
|
|
38
|
+
|
|
39
|
+
Example: stop when the network gets below an error target or hits a
|
|
40
|
+
generation cap.
|
|
18
41
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### DEFAULT_THREAD_COUNT
|
|
28
|
-
|
|
29
|
-
Default single-thread worker count.
|
|
30
|
-
|
|
31
|
-
### DISABLED_TARGET_ERROR
|
|
32
|
-
|
|
33
|
-
Sentinel target error indicating that error-based stopping is disabled.
|
|
34
|
-
|
|
35
|
-
### EvolutionSummary
|
|
36
|
-
|
|
37
|
-
Shared evolution summary payload.
|
|
38
|
-
|
|
39
|
-
### GenomeStructureCounts
|
|
40
|
-
|
|
41
|
-
Structural counts used by complexity heuristics.
|
|
42
|
-
|
|
43
|
-
### MAX_CONSECUTIVE_INVALID_ERRORS
|
|
44
|
-
|
|
45
|
-
Maximum consecutive invalid errors tolerated before loop abort.
|
|
46
|
-
|
|
47
|
-
### SMALL_POPULATION_MUTATION_AMOUNT
|
|
48
|
-
|
|
49
|
-
Mutation amount fallback used for very small populations.
|
|
50
|
-
|
|
51
|
-
### SMALL_POPULATION_MUTATION_RATE
|
|
52
|
-
|
|
53
|
-
Mutation rate fallback used for very small populations.
|
|
54
|
-
|
|
55
|
-
### SMALL_POPULATION_THRESHOLD
|
|
56
|
-
|
|
57
|
-
Population threshold considered "small" for mutation heuristics.
|
|
58
|
-
|
|
59
|
-
### STOPPING_CONDITION_REQUIRED_ERROR_MESSAGE
|
|
60
|
-
|
|
61
|
-
Shared evolve stopping-condition validation error.
|
|
42
|
+
```ts
|
|
43
|
+
const summary = await network.evolve(trainingSet, {
|
|
44
|
+
error: 0.02,
|
|
45
|
+
iterations: 500,
|
|
46
|
+
growth: 0.0005,
|
|
47
|
+
});
|
|
48
|
+
```
|
|
62
49
|
|
|
63
|
-
|
|
50
|
+
Example: cap the search more tightly and fan evaluation across workers when
|
|
51
|
+
dataset scoring dominates.
|
|
64
52
|
|
|
65
|
-
|
|
53
|
+
```ts
|
|
54
|
+
const summary = await network.evolve(trainingSet, {
|
|
55
|
+
iterations: 120,
|
|
56
|
+
threads: 2,
|
|
57
|
+
log: 20,
|
|
58
|
+
});
|
|
59
|
+
```
|
|
66
60
|
|
|
67
61
|
## architecture/network/evolve/network.evolve.utils.ts
|
|
68
62
|
|
|
@@ -107,174 +101,6 @@ const summary = await network.evolve(trainingSet, {
|
|
|
107
101
|
console.log(summary.error, summary.iterations, summary.time);
|
|
108
102
|
```
|
|
109
103
|
|
|
110
|
-
## architecture/network/evolve/network.evolve.loop.utils.ts
|
|
111
|
-
|
|
112
|
-
### applyEvolutionStep
|
|
113
|
-
|
|
114
|
-
```ts
|
|
115
|
-
applyEvolutionStep(
|
|
116
|
-
state: EvolutionLoopState,
|
|
117
|
-
evolvedGenome: default,
|
|
118
|
-
growth: number,
|
|
119
|
-
): void
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Applies one evolve() result to loop state.
|
|
123
|
-
|
|
124
|
-
Parameters:
|
|
125
|
-
- `state` - - Mutable loop state.
|
|
126
|
-
- `evolvedGenome` - - Genome returned by NEAT evolve step.
|
|
127
|
-
- `growth` - - Complexity growth scalar.
|
|
128
|
-
|
|
129
|
-
Returns: Nothing.
|
|
130
|
-
|
|
131
|
-
### createInitialLoopState
|
|
132
|
-
|
|
133
|
-
```ts
|
|
134
|
-
createInitialLoopState(): EvolutionLoopState
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Creates initial loop state snapshot.
|
|
138
|
-
|
|
139
|
-
Returns: Initial loop state.
|
|
140
|
-
|
|
141
|
-
### deriveErrorFromFitness
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
deriveErrorFromFitness(
|
|
145
|
-
fitness: number,
|
|
146
|
-
genome: default,
|
|
147
|
-
growth: number,
|
|
148
|
-
): number
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
Derive error from fitness by inverting score composition.
|
|
152
|
-
|
|
153
|
-
Parameters:
|
|
154
|
-
- `fitness` - - Fitness value from fittest genome.
|
|
155
|
-
- `genome` - - Fittest genome.
|
|
156
|
-
- `growth` - - Complexity growth scalar.
|
|
157
|
-
|
|
158
|
-
Returns: Derived error value.
|
|
159
|
-
|
|
160
|
-
### runEvolutionLoop
|
|
161
|
-
|
|
162
|
-
```ts
|
|
163
|
-
runEvolutionLoop(
|
|
164
|
-
neatInstance: NeatRuntime,
|
|
165
|
-
resolvedSettings: EvolutionSettings,
|
|
166
|
-
targetError: number,
|
|
167
|
-
iterations: number | undefined,
|
|
168
|
-
): Promise<{ error: number; bestGenome: default | undefined; }>
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Run core evolution loop until stop condition is met.
|
|
172
|
-
|
|
173
|
-
Parameters:
|
|
174
|
-
- `neatInstance` - - Active NEAT instance.
|
|
175
|
-
- `resolvedSettings` - - Scalar evolution settings.
|
|
176
|
-
- `targetError` - - Effective target error (-1 means disabled).
|
|
177
|
-
- `iterations` - - Optional max iteration count.
|
|
178
|
-
|
|
179
|
-
Returns: Loop result snapshot.
|
|
180
|
-
|
|
181
|
-
### runScheduleCallbackSafely
|
|
182
|
-
|
|
183
|
-
```ts
|
|
184
|
-
runScheduleCallbackSafely(
|
|
185
|
-
scheduleConfig: { iterations: number; function: (stats: { fitness: number; error: number; iteration: number; }) => void; } | undefined,
|
|
186
|
-
generation: number,
|
|
187
|
-
bestFitness: number,
|
|
188
|
-
error: number,
|
|
189
|
-
): void
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
Run schedule callback if schedule trigger is reached.
|
|
193
|
-
|
|
194
|
-
Parameters:
|
|
195
|
-
- `scheduleConfig` - - Optional schedule configuration.
|
|
196
|
-
- `generation` - - Current generation.
|
|
197
|
-
- `bestFitness` - - Current best fitness.
|
|
198
|
-
- `error` - - Current error.
|
|
199
|
-
|
|
200
|
-
Returns: Nothing.
|
|
201
|
-
|
|
202
|
-
### shouldAbortForInvalidErrors
|
|
203
|
-
|
|
204
|
-
```ts
|
|
205
|
-
shouldAbortForInvalidErrors(
|
|
206
|
-
state: EvolutionLoopState,
|
|
207
|
-
): boolean
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
Determines whether loop must abort due to invalid-error streak.
|
|
211
|
-
|
|
212
|
-
Parameters:
|
|
213
|
-
- `state` - - Mutable loop state.
|
|
214
|
-
|
|
215
|
-
Returns: True when invalid-error threshold is reached.
|
|
216
|
-
|
|
217
|
-
### shouldContinueEvolution
|
|
218
|
-
|
|
219
|
-
```ts
|
|
220
|
-
shouldContinueEvolution(
|
|
221
|
-
currentError: number,
|
|
222
|
-
targetError: number,
|
|
223
|
-
iterationsSpecified: boolean,
|
|
224
|
-
currentGeneration: number,
|
|
225
|
-
maxIterations: number | undefined,
|
|
226
|
-
): boolean
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
Determine whether evolution loop should continue.
|
|
230
|
-
|
|
231
|
-
Parameters:
|
|
232
|
-
- `currentError` - - Current derived error value.
|
|
233
|
-
- `targetError` - - Effective target error (-1 means disabled).
|
|
234
|
-
- `iterationsSpecified` - - Whether iterations limit is active.
|
|
235
|
-
- `currentGeneration` - - Current NEAT generation index.
|
|
236
|
-
- `maxIterations` - - Maximum iteration limit.
|
|
237
|
-
|
|
238
|
-
Returns: True when loop should continue.
|
|
239
|
-
|
|
240
|
-
### updateBestGenomeIfImproved
|
|
241
|
-
|
|
242
|
-
```ts
|
|
243
|
-
updateBestGenomeIfImproved(
|
|
244
|
-
currentBestFitness: number,
|
|
245
|
-
currentBestGenome: default | undefined,
|
|
246
|
-
candidateFitness: number,
|
|
247
|
-
candidateGenome: default,
|
|
248
|
-
): { bestFitness: number; bestGenome: default | undefined; }
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
Update best fitness/genome snapshot when improved.
|
|
252
|
-
|
|
253
|
-
Parameters:
|
|
254
|
-
- `currentBestFitness` - - Current best fitness.
|
|
255
|
-
- `currentBestGenome` - - Current best genome.
|
|
256
|
-
- `candidateFitness` - - Candidate fitness.
|
|
257
|
-
- `candidateGenome` - - Candidate genome.
|
|
258
|
-
|
|
259
|
-
Returns: Updated best snapshot.
|
|
260
|
-
|
|
261
|
-
### updateInvalidErrorCounter
|
|
262
|
-
|
|
263
|
-
```ts
|
|
264
|
-
updateInvalidErrorCounter(
|
|
265
|
-
currentCount: number,
|
|
266
|
-
currentError: number,
|
|
267
|
-
): number
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
Update invalid-error counter.
|
|
271
|
-
|
|
272
|
-
Parameters:
|
|
273
|
-
- `currentCount` - - Current consecutive invalid-error count.
|
|
274
|
-
- `currentError` - - Current derived error value.
|
|
275
|
-
|
|
276
|
-
Returns: Updated guard state.
|
|
277
|
-
|
|
278
104
|
## architecture/network/evolve/network.evolve.setup.utils.ts
|
|
279
105
|
|
|
280
106
|
### applySmallPopulationHeuristics
|
|
@@ -881,6 +707,174 @@ Parameters:
|
|
|
881
707
|
|
|
882
708
|
Returns: Nothing.
|
|
883
709
|
|
|
710
|
+
## architecture/network/evolve/network.evolve.loop.utils.ts
|
|
711
|
+
|
|
712
|
+
### applyEvolutionStep
|
|
713
|
+
|
|
714
|
+
```ts
|
|
715
|
+
applyEvolutionStep(
|
|
716
|
+
state: EvolutionLoopState,
|
|
717
|
+
evolvedGenome: default,
|
|
718
|
+
growth: number,
|
|
719
|
+
): void
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
Applies one evolve() result to loop state.
|
|
723
|
+
|
|
724
|
+
Parameters:
|
|
725
|
+
- `state` - - Mutable loop state.
|
|
726
|
+
- `evolvedGenome` - - Genome returned by NEAT evolve step.
|
|
727
|
+
- `growth` - - Complexity growth scalar.
|
|
728
|
+
|
|
729
|
+
Returns: Nothing.
|
|
730
|
+
|
|
731
|
+
### createInitialLoopState
|
|
732
|
+
|
|
733
|
+
```ts
|
|
734
|
+
createInitialLoopState(): EvolutionLoopState
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
Creates initial loop state snapshot.
|
|
738
|
+
|
|
739
|
+
Returns: Initial loop state.
|
|
740
|
+
|
|
741
|
+
### deriveErrorFromFitness
|
|
742
|
+
|
|
743
|
+
```ts
|
|
744
|
+
deriveErrorFromFitness(
|
|
745
|
+
fitness: number,
|
|
746
|
+
genome: default,
|
|
747
|
+
growth: number,
|
|
748
|
+
): number
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
Derive error from fitness by inverting score composition.
|
|
752
|
+
|
|
753
|
+
Parameters:
|
|
754
|
+
- `fitness` - - Fitness value from fittest genome.
|
|
755
|
+
- `genome` - - Fittest genome.
|
|
756
|
+
- `growth` - - Complexity growth scalar.
|
|
757
|
+
|
|
758
|
+
Returns: Derived error value.
|
|
759
|
+
|
|
760
|
+
### runEvolutionLoop
|
|
761
|
+
|
|
762
|
+
```ts
|
|
763
|
+
runEvolutionLoop(
|
|
764
|
+
neatInstance: NeatRuntime,
|
|
765
|
+
resolvedSettings: EvolutionSettings,
|
|
766
|
+
targetError: number,
|
|
767
|
+
iterations: number | undefined,
|
|
768
|
+
): Promise<{ error: number; bestGenome: default | undefined; }>
|
|
769
|
+
```
|
|
770
|
+
|
|
771
|
+
Run core evolution loop until stop condition is met.
|
|
772
|
+
|
|
773
|
+
Parameters:
|
|
774
|
+
- `neatInstance` - - Active NEAT instance.
|
|
775
|
+
- `resolvedSettings` - - Scalar evolution settings.
|
|
776
|
+
- `targetError` - - Effective target error (-1 means disabled).
|
|
777
|
+
- `iterations` - - Optional max iteration count.
|
|
778
|
+
|
|
779
|
+
Returns: Loop result snapshot.
|
|
780
|
+
|
|
781
|
+
### runScheduleCallbackSafely
|
|
782
|
+
|
|
783
|
+
```ts
|
|
784
|
+
runScheduleCallbackSafely(
|
|
785
|
+
scheduleConfig: { iterations: number; function: (stats: { fitness: number; error: number; iteration: number; }) => void; } | undefined,
|
|
786
|
+
generation: number,
|
|
787
|
+
bestFitness: number,
|
|
788
|
+
error: number,
|
|
789
|
+
): void
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
Run schedule callback if schedule trigger is reached.
|
|
793
|
+
|
|
794
|
+
Parameters:
|
|
795
|
+
- `scheduleConfig` - - Optional schedule configuration.
|
|
796
|
+
- `generation` - - Current generation.
|
|
797
|
+
- `bestFitness` - - Current best fitness.
|
|
798
|
+
- `error` - - Current error.
|
|
799
|
+
|
|
800
|
+
Returns: Nothing.
|
|
801
|
+
|
|
802
|
+
### shouldAbortForInvalidErrors
|
|
803
|
+
|
|
804
|
+
```ts
|
|
805
|
+
shouldAbortForInvalidErrors(
|
|
806
|
+
state: EvolutionLoopState,
|
|
807
|
+
): boolean
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
Determines whether loop must abort due to invalid-error streak.
|
|
811
|
+
|
|
812
|
+
Parameters:
|
|
813
|
+
- `state` - - Mutable loop state.
|
|
814
|
+
|
|
815
|
+
Returns: True when invalid-error threshold is reached.
|
|
816
|
+
|
|
817
|
+
### shouldContinueEvolution
|
|
818
|
+
|
|
819
|
+
```ts
|
|
820
|
+
shouldContinueEvolution(
|
|
821
|
+
currentError: number,
|
|
822
|
+
targetError: number,
|
|
823
|
+
iterationsSpecified: boolean,
|
|
824
|
+
currentGeneration: number,
|
|
825
|
+
maxIterations: number | undefined,
|
|
826
|
+
): boolean
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
Determine whether evolution loop should continue.
|
|
830
|
+
|
|
831
|
+
Parameters:
|
|
832
|
+
- `currentError` - - Current derived error value.
|
|
833
|
+
- `targetError` - - Effective target error (-1 means disabled).
|
|
834
|
+
- `iterationsSpecified` - - Whether iterations limit is active.
|
|
835
|
+
- `currentGeneration` - - Current NEAT generation index.
|
|
836
|
+
- `maxIterations` - - Maximum iteration limit.
|
|
837
|
+
|
|
838
|
+
Returns: True when loop should continue.
|
|
839
|
+
|
|
840
|
+
### updateBestGenomeIfImproved
|
|
841
|
+
|
|
842
|
+
```ts
|
|
843
|
+
updateBestGenomeIfImproved(
|
|
844
|
+
currentBestFitness: number,
|
|
845
|
+
currentBestGenome: default | undefined,
|
|
846
|
+
candidateFitness: number,
|
|
847
|
+
candidateGenome: default,
|
|
848
|
+
): { bestFitness: number; bestGenome: default | undefined; }
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
Update best fitness/genome snapshot when improved.
|
|
852
|
+
|
|
853
|
+
Parameters:
|
|
854
|
+
- `currentBestFitness` - - Current best fitness.
|
|
855
|
+
- `currentBestGenome` - - Current best genome.
|
|
856
|
+
- `candidateFitness` - - Candidate fitness.
|
|
857
|
+
- `candidateGenome` - - Candidate genome.
|
|
858
|
+
|
|
859
|
+
Returns: Updated best snapshot.
|
|
860
|
+
|
|
861
|
+
### updateInvalidErrorCounter
|
|
862
|
+
|
|
863
|
+
```ts
|
|
864
|
+
updateInvalidErrorCounter(
|
|
865
|
+
currentCount: number,
|
|
866
|
+
currentError: number,
|
|
867
|
+
): number
|
|
868
|
+
```
|
|
869
|
+
|
|
870
|
+
Update invalid-error counter.
|
|
871
|
+
|
|
872
|
+
Parameters:
|
|
873
|
+
- `currentCount` - - Current consecutive invalid-error count.
|
|
874
|
+
- `currentError` - - Current derived error value.
|
|
875
|
+
|
|
876
|
+
Returns: Updated guard state.
|
|
877
|
+
|
|
884
878
|
## architecture/network/evolve/network.evolve.finalize.utils.ts
|
|
885
879
|
|
|
886
880
|
### adoptBestGenomeOrWarn
|
|
@@ -937,3 +931,67 @@ Parameters:
|
|
|
937
931
|
- `evolveOptions` - - Evolve options object.
|
|
938
932
|
|
|
939
933
|
Returns: Nothing.
|
|
934
|
+
|
|
935
|
+
## architecture/network/evolve/network.evolve.utils.types.ts
|
|
936
|
+
|
|
937
|
+
Shared dataset compatibility error message.
|
|
938
|
+
|
|
939
|
+
### DATASET_COMPATIBILITY_ERROR_MESSAGE
|
|
940
|
+
|
|
941
|
+
Shared dataset compatibility error message.
|
|
942
|
+
|
|
943
|
+
### DEFAULT_EVALUATION_AMOUNT
|
|
944
|
+
|
|
945
|
+
Default repeated evaluation amount.
|
|
946
|
+
|
|
947
|
+
### DEFAULT_GROWTH
|
|
948
|
+
|
|
949
|
+
Default complexity growth penalty.
|
|
950
|
+
|
|
951
|
+
### DEFAULT_LOG_INTERVAL
|
|
952
|
+
|
|
953
|
+
Default logging frequency value.
|
|
954
|
+
|
|
955
|
+
### DEFAULT_TARGET_ERROR
|
|
956
|
+
|
|
957
|
+
Default target error used when omitted.
|
|
958
|
+
|
|
959
|
+
### DEFAULT_THREAD_COUNT
|
|
960
|
+
|
|
961
|
+
Default single-thread worker count.
|
|
962
|
+
|
|
963
|
+
### DISABLED_TARGET_ERROR
|
|
964
|
+
|
|
965
|
+
Sentinel target error indicating that error-based stopping is disabled.
|
|
966
|
+
|
|
967
|
+
### EvolutionSummary
|
|
968
|
+
|
|
969
|
+
Shared evolution summary payload.
|
|
970
|
+
|
|
971
|
+
### GenomeStructureCounts
|
|
972
|
+
|
|
973
|
+
Structural counts used by complexity heuristics.
|
|
974
|
+
|
|
975
|
+
### MAX_CONSECUTIVE_INVALID_ERRORS
|
|
976
|
+
|
|
977
|
+
Maximum consecutive invalid errors tolerated before loop abort.
|
|
978
|
+
|
|
979
|
+
### SMALL_POPULATION_MUTATION_AMOUNT
|
|
980
|
+
|
|
981
|
+
Mutation amount fallback used for very small populations.
|
|
982
|
+
|
|
983
|
+
### SMALL_POPULATION_MUTATION_RATE
|
|
984
|
+
|
|
985
|
+
Mutation rate fallback used for very small populations.
|
|
986
|
+
|
|
987
|
+
### SMALL_POPULATION_THRESHOLD
|
|
988
|
+
|
|
989
|
+
Population threshold considered "small" for mutation heuristics.
|
|
990
|
+
|
|
991
|
+
### STOPPING_CONDITION_REQUIRED_ERROR_MESSAGE
|
|
992
|
+
|
|
993
|
+
Shared evolve stopping-condition validation error.
|
|
994
|
+
|
|
995
|
+
### ZERO_ITERATIONS
|
|
996
|
+
|
|
997
|
+
Explicit zero-iteration value.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"introFile": "network.evolve.utils.ts",
|
|
3
|
+
"fileOrder": [
|
|
4
|
+
"network.evolve.utils.ts",
|
|
5
|
+
"network.evolve.setup.utils.ts",
|
|
6
|
+
"network.evolve.fitness.utils.ts",
|
|
7
|
+
"network.evolve.loop.utils.ts",
|
|
8
|
+
"network.evolve.finalize.utils.ts",
|
|
9
|
+
"network.evolve.utils.types.ts"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -1,3 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Network-level neuroevolution loop for improving one runnable graph in place.
|
|
3
|
+
*
|
|
4
|
+
* This chapter sits between the lightweight `Network` facade and the broader
|
|
5
|
+
* `neat/` subsystem. Call `network.evolve()` when the question is "improve
|
|
6
|
+
* this graph against a supervised dataset" without first wiring a separate
|
|
7
|
+
* experiment harness. The method treats the current network as a seed genome,
|
|
8
|
+
* configures a short-lived NEAT runtime around it, evaluates descendants, then
|
|
9
|
+
* copies the best discovered structure back into the original instance.
|
|
10
|
+
*
|
|
11
|
+
* The folder is split by the same stages the public call executes. `setup`
|
|
12
|
+
* validates dataset shape and resolves defaults. `fitness` turns prediction
|
|
13
|
+
* error into a comparable score. `loop` owns generation-to-generation stopping
|
|
14
|
+
* logic. `finalize` adopts the winning genome and tears down worker resources.
|
|
15
|
+
* Keeping those shelves separate makes the README read like an evolution run
|
|
16
|
+
* rather than an alphabetical pile of helpers.
|
|
17
|
+
*
|
|
18
|
+
* ```mermaid
|
|
19
|
+
* flowchart LR
|
|
20
|
+
* Seed[Seed Network] --> Normalize[Normalize options and dataset]
|
|
21
|
+
* Normalize --> Fitness[Build fitness evaluator]
|
|
22
|
+
* Fitness --> Neat[Create temporary NEAT runtime]
|
|
23
|
+
* Neat --> Loop[Run evolve loop]
|
|
24
|
+
* Loop --> Adopt[Adopt best genome into original network]
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* Use this boundary when you want a bounded local search over network
|
|
28
|
+
* structure, not a long-lived population controller. `error` answers "stop
|
|
29
|
+
* when good enough", `iterations` answers "stop after this many generations",
|
|
30
|
+
* and `growth` answers "how much should extra structure cost while searching".
|
|
31
|
+
*
|
|
32
|
+
* For compact background reading on the wider search family behind this folder,
|
|
33
|
+
* see Wikipedia contributors,
|
|
34
|
+
* [Evolutionary algorithm](https://en.wikipedia.org/wiki/Evolutionary_algorithm).
|
|
35
|
+
* The implementation here is intentionally narrower: it keeps the public call
|
|
36
|
+
* site small while reusing the repo's NEAT runtime under the hood.
|
|
37
|
+
*
|
|
38
|
+
* Example: stop when the network gets below an error target or hits a
|
|
39
|
+
* generation cap.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const summary = await network.evolve(trainingSet, {
|
|
43
|
+
* error: 0.02,
|
|
44
|
+
* iterations: 500,
|
|
45
|
+
* growth: 0.0005,
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Example: cap the search more tightly and fan evaluation across workers when
|
|
50
|
+
* dataset scoring dominates.
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* const summary = await network.evolve(trainingSet, {
|
|
54
|
+
* iterations: 120,
|
|
55
|
+
* threads: 2,
|
|
56
|
+
* log: 20,
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
1
60
|
import Network from '../../network/network';
|
|
2
61
|
import type { EvolveOptions, TrainingSample } from '../network.types';
|
|
3
62
|
import {
|
|
@@ -1,26 +1,46 @@
|
|
|
1
1
|
# architecture/network/gating
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
Connection-gating utilities and gate-aware repair helpers for network edits.
|
|
4
|
+
|
|
5
|
+
Gating is the lightweight way to let one node decide how strongly another
|
|
6
|
+
connection should matter right now. That makes this chapter about more than
|
|
7
|
+
a simple `gate()` setter. It also owns the awkward structural case where a
|
|
8
|
+
hidden node is removed and the network tries to preserve useful gated
|
|
9
|
+
behavior by reconnecting predecessor and successor nodes, then reassigning
|
|
10
|
+
preserved gaters onto the new bridge connections.
|
|
11
|
+
|
|
12
|
+
The split inside this folder follows those two jobs. `gate.utils` keeps
|
|
13
|
+
ordinary gate and ungate bookkeeping small and predictable. `remove.utils`
|
|
14
|
+
handles the more invasive bridge-repair flow used during gate-aware hidden
|
|
15
|
+
node removal. The shared types file only carries temporary collections used
|
|
16
|
+
during that repair work; it is not the right chapter intro.
|
|
17
|
+
|
|
18
|
+
```mermaid
|
|
19
|
+
flowchart LR
|
|
20
|
+
Gater[Gater node activation] --> Modulate[Modulate connection gain]
|
|
21
|
+
Modulate --> Target[Target node input sum]
|
|
22
|
+
Remove[Remove hidden node] --> Bridge[Create bridge connections]
|
|
23
|
+
Bridge --> Preserve[Reassign preserved gaters]
|
|
24
|
+
```
|
|
14
25
|
|
|
15
|
-
|
|
26
|
+
A useful mental model is that gating changes when a connection is
|
|
27
|
+
influential, while bridge repair tries to preserve where information can
|
|
28
|
+
still travel after topology surgery. Keeping both concerns together makes
|
|
29
|
+
the public surface easier to learn because callers usually encounter them in
|
|
30
|
+
the same network-editing workflows.
|
|
16
31
|
|
|
17
|
-
|
|
32
|
+
Example: attach a hidden node as a gater for one connection.
|
|
18
33
|
|
|
19
|
-
|
|
34
|
+
```ts
|
|
35
|
+
network.gate(hiddenNode, connection);
|
|
36
|
+
```
|
|
20
37
|
|
|
21
|
-
|
|
38
|
+
Example: later remove that modulation and return the connection to static
|
|
39
|
+
weighting.
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
```ts
|
|
42
|
+
network.ungate(connection);
|
|
43
|
+
```
|
|
24
44
|
|
|
25
45
|
## architecture/network/gating/network.gating.utils.ts
|
|
26
46
|
|
|
@@ -437,3 +457,25 @@ Parameters:
|
|
|
437
457
|
- `node` - - Node whose gated connections should be released.
|
|
438
458
|
|
|
439
459
|
Returns: Nothing.
|
|
460
|
+
|
|
461
|
+
## architecture/network/gating/network.gating.utils.types.ts
|
|
462
|
+
|
|
463
|
+
### BridgingConnectionList
|
|
464
|
+
|
|
465
|
+
Newly created connections that can be assigned preserved gaters.
|
|
466
|
+
|
|
467
|
+
### ConnectedNodeList
|
|
468
|
+
|
|
469
|
+
Predecessor or successor node collection used during bridge construction.
|
|
470
|
+
|
|
471
|
+
### MutableNetworkGatingProps
|
|
472
|
+
|
|
473
|
+
Network shape extension used to flag node index cache invalidation.
|
|
474
|
+
|
|
475
|
+
### NodeRemovalMutationConfig
|
|
476
|
+
|
|
477
|
+
Normalized SUB_NODE mutation configuration used during node-removal rewiring.
|
|
478
|
+
|
|
479
|
+
### PreservedGaters
|
|
480
|
+
|
|
481
|
+
Mutable gater collection retained while removing a hidden node.
|