@reicek/neataptic-ts 0.1.0

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.
Files changed (272) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +27 -0
  3. package/.github/PULL_REQUEST_TEMPLATE.md +28 -0
  4. package/.github/workflows/ci.yml +41 -0
  5. package/.github/workflows/deploy-pages.yml +29 -0
  6. package/.github/workflows/manual_release_pipeline.yml +62 -0
  7. package/.github/workflows/publish.yml +85 -0
  8. package/.github/workflows/release_dispatch.yml +38 -0
  9. package/.travis.yml +5 -0
  10. package/CONTRIBUTING.md +92 -0
  11. package/LICENSE +24 -0
  12. package/ONNX_EXPORT.md +87 -0
  13. package/README.md +1173 -0
  14. package/RELEASE.md +54 -0
  15. package/dist-docs/package.json +1 -0
  16. package/dist-docs/scripts/generate-docs.d.ts +2 -0
  17. package/dist-docs/scripts/generate-docs.d.ts.map +1 -0
  18. package/dist-docs/scripts/generate-docs.js +536 -0
  19. package/dist-docs/scripts/generate-docs.js.map +1 -0
  20. package/dist-docs/scripts/render-docs-html.d.ts +2 -0
  21. package/dist-docs/scripts/render-docs-html.d.ts.map +1 -0
  22. package/dist-docs/scripts/render-docs-html.js +148 -0
  23. package/dist-docs/scripts/render-docs-html.js.map +1 -0
  24. package/docs/FOLDERS.md +14 -0
  25. package/docs/README.md +1173 -0
  26. package/docs/architecture/README.md +1391 -0
  27. package/docs/architecture/index.html +938 -0
  28. package/docs/architecture/network/README.md +1210 -0
  29. package/docs/architecture/network/index.html +908 -0
  30. package/docs/assets/ascii-maze.bundle.js +16542 -0
  31. package/docs/assets/ascii-maze.bundle.js.map +7 -0
  32. package/docs/index.html +1419 -0
  33. package/docs/methods/README.md +670 -0
  34. package/docs/methods/index.html +477 -0
  35. package/docs/multithreading/README.md +274 -0
  36. package/docs/multithreading/index.html +215 -0
  37. package/docs/multithreading/workers/README.md +23 -0
  38. package/docs/multithreading/workers/browser/README.md +39 -0
  39. package/docs/multithreading/workers/browser/index.html +70 -0
  40. package/docs/multithreading/workers/index.html +57 -0
  41. package/docs/multithreading/workers/node/README.md +33 -0
  42. package/docs/multithreading/workers/node/index.html +66 -0
  43. package/docs/neat/README.md +1284 -0
  44. package/docs/neat/index.html +906 -0
  45. package/docs/src/README.md +2659 -0
  46. package/docs/src/index.html +1579 -0
  47. package/jest.config.ts +32 -0
  48. package/package.json +99 -0
  49. package/plans/HyperMorphoNEAT.md +293 -0
  50. package/plans/ONNX_EXPORT_PLAN.md +46 -0
  51. package/scripts/generate-docs.ts +486 -0
  52. package/scripts/render-docs-html.ts +138 -0
  53. package/scripts/types.d.ts +2 -0
  54. package/src/README.md +2659 -0
  55. package/src/architecture/README.md +1391 -0
  56. package/src/architecture/activationArrayPool.ts +135 -0
  57. package/src/architecture/architect.ts +635 -0
  58. package/src/architecture/connection.ts +148 -0
  59. package/src/architecture/group.ts +406 -0
  60. package/src/architecture/layer.ts +804 -0
  61. package/src/architecture/network/README.md +1210 -0
  62. package/src/architecture/network/network.activate.ts +223 -0
  63. package/src/architecture/network/network.connect.ts +157 -0
  64. package/src/architecture/network/network.deterministic.ts +167 -0
  65. package/src/architecture/network/network.evolve.ts +426 -0
  66. package/src/architecture/network/network.gating.ts +186 -0
  67. package/src/architecture/network/network.genetic.ts +247 -0
  68. package/src/architecture/network/network.mutate.ts +624 -0
  69. package/src/architecture/network/network.onnx.ts +463 -0
  70. package/src/architecture/network/network.prune.ts +216 -0
  71. package/src/architecture/network/network.remove.ts +96 -0
  72. package/src/architecture/network/network.serialize.ts +309 -0
  73. package/src/architecture/network/network.slab.ts +262 -0
  74. package/src/architecture/network/network.standalone.ts +246 -0
  75. package/src/architecture/network/network.stats.ts +59 -0
  76. package/src/architecture/network/network.topology.ts +86 -0
  77. package/src/architecture/network/network.training.ts +1278 -0
  78. package/src/architecture/network.ts +1302 -0
  79. package/src/architecture/node.ts +1288 -0
  80. package/src/architecture/onnx.ts +3 -0
  81. package/src/config.ts +83 -0
  82. package/src/methods/README.md +670 -0
  83. package/src/methods/activation.ts +372 -0
  84. package/src/methods/connection.ts +31 -0
  85. package/src/methods/cost.ts +347 -0
  86. package/src/methods/crossover.ts +63 -0
  87. package/src/methods/gating.ts +43 -0
  88. package/src/methods/methods.ts +8 -0
  89. package/src/methods/mutation.ts +300 -0
  90. package/src/methods/rate.ts +257 -0
  91. package/src/methods/selection.ts +65 -0
  92. package/src/multithreading/README.md +274 -0
  93. package/src/multithreading/multi.ts +339 -0
  94. package/src/multithreading/workers/README.md +23 -0
  95. package/src/multithreading/workers/browser/README.md +39 -0
  96. package/src/multithreading/workers/browser/testworker.ts +99 -0
  97. package/src/multithreading/workers/node/README.md +33 -0
  98. package/src/multithreading/workers/node/testworker.ts +72 -0
  99. package/src/multithreading/workers/node/worker.ts +70 -0
  100. package/src/multithreading/workers/workers.ts +22 -0
  101. package/src/neat/README.md +1284 -0
  102. package/src/neat/neat.adaptive.ts +544 -0
  103. package/src/neat/neat.compat.ts +164 -0
  104. package/src/neat/neat.constants.ts +20 -0
  105. package/src/neat/neat.diversity.ts +217 -0
  106. package/src/neat/neat.evaluate.ts +328 -0
  107. package/src/neat/neat.evolve.ts +1026 -0
  108. package/src/neat/neat.export.ts +249 -0
  109. package/src/neat/neat.helpers.ts +235 -0
  110. package/src/neat/neat.lineage.ts +220 -0
  111. package/src/neat/neat.multiobjective.ts +260 -0
  112. package/src/neat/neat.mutation.ts +718 -0
  113. package/src/neat/neat.objectives.ts +157 -0
  114. package/src/neat/neat.pruning.ts +190 -0
  115. package/src/neat/neat.selection.ts +269 -0
  116. package/src/neat/neat.speciation.ts +460 -0
  117. package/src/neat/neat.species.ts +151 -0
  118. package/src/neat/neat.telemetry.exports.ts +469 -0
  119. package/src/neat/neat.telemetry.ts +933 -0
  120. package/src/neat/neat.types.ts +275 -0
  121. package/src/neat.ts +1042 -0
  122. package/src/neataptic.ts +10 -0
  123. package/test/architecture/activationArrayPool.capacity.test.ts +19 -0
  124. package/test/architecture/activationArrayPool.test.ts +46 -0
  125. package/test/architecture/connection.test.ts +290 -0
  126. package/test/architecture/group.test.ts +950 -0
  127. package/test/architecture/layer.test.ts +1535 -0
  128. package/test/architecture/network.pruning.test.ts +65 -0
  129. package/test/architecture/node.test.ts +1602 -0
  130. package/test/examples/asciiMaze/asciiMaze.e2e.test.ts +499 -0
  131. package/test/examples/asciiMaze/asciiMaze.ts +41 -0
  132. package/test/examples/asciiMaze/browser-entry.ts +164 -0
  133. package/test/examples/asciiMaze/browserLogger.ts +221 -0
  134. package/test/examples/asciiMaze/browserTerminalUtility.ts +48 -0
  135. package/test/examples/asciiMaze/colors.ts +119 -0
  136. package/test/examples/asciiMaze/dashboardManager.ts +968 -0
  137. package/test/examples/asciiMaze/evolutionEngine.ts +1248 -0
  138. package/test/examples/asciiMaze/fitness.ts +136 -0
  139. package/test/examples/asciiMaze/index.html +128 -0
  140. package/test/examples/asciiMaze/index.ts +26 -0
  141. package/test/examples/asciiMaze/interfaces.ts +235 -0
  142. package/test/examples/asciiMaze/mazeMovement.ts +996 -0
  143. package/test/examples/asciiMaze/mazeUtils.ts +278 -0
  144. package/test/examples/asciiMaze/mazeVision.ts +402 -0
  145. package/test/examples/asciiMaze/mazeVisualization.ts +585 -0
  146. package/test/examples/asciiMaze/mazes.ts +245 -0
  147. package/test/examples/asciiMaze/networkRefinement.ts +76 -0
  148. package/test/examples/asciiMaze/networkVisualization.ts +901 -0
  149. package/test/examples/asciiMaze/terminalUtility.ts +73 -0
  150. package/test/methods/activation.test.ts +1142 -0
  151. package/test/methods/connection.test.ts +146 -0
  152. package/test/methods/cost.test.ts +1123 -0
  153. package/test/methods/crossover.test.ts +202 -0
  154. package/test/methods/gating.test.ts +144 -0
  155. package/test/methods/mutation.test.ts +451 -0
  156. package/test/methods/optimizers.advanced.test.ts +80 -0
  157. package/test/methods/optimizers.behavior.test.ts +105 -0
  158. package/test/methods/optimizers.formula.test.ts +89 -0
  159. package/test/methods/rate.cosineWarmRestarts.test.ts +44 -0
  160. package/test/methods/rate.linearWarmupDecay.test.ts +41 -0
  161. package/test/methods/rate.reduceOnPlateau.test.ts +45 -0
  162. package/test/methods/rate.test.ts +684 -0
  163. package/test/methods/selection.test.ts +245 -0
  164. package/test/multithreading/activations.functions.test.ts +54 -0
  165. package/test/multithreading/multi.test.ts +290 -0
  166. package/test/multithreading/worker.node.process.test.ts +39 -0
  167. package/test/multithreading/workers.coverage.test.ts +36 -0
  168. package/test/multithreading/workers.dynamic.import.test.ts +8 -0
  169. package/test/neat/neat.adaptive.complexityBudget.test.ts +34 -0
  170. package/test/neat/neat.adaptive.criterion.complexity.test.ts +50 -0
  171. package/test/neat/neat.adaptive.mutation.strategy.test.ts +37 -0
  172. package/test/neat/neat.adaptive.operator.decay.test.ts +31 -0
  173. package/test/neat/neat.adaptive.phasedComplexity.test.ts +25 -0
  174. package/test/neat/neat.adaptive.pruning.test.ts +25 -0
  175. package/test/neat/neat.adaptive.targetSpecies.test.ts +43 -0
  176. package/test/neat/neat.additional.coverage.test.ts +126 -0
  177. package/test/neat/neat.advanced.enhancements.test.ts +85 -0
  178. package/test/neat/neat.advanced.test.ts +589 -0
  179. package/test/neat/neat.diversity.autocompat.test.ts +47 -0
  180. package/test/neat/neat.diversity.metrics.test.ts +21 -0
  181. package/test/neat/neat.diversity.stats.test.ts +44 -0
  182. package/test/neat/neat.enhancements.test.ts +79 -0
  183. package/test/neat/neat.entropy.ancestorAdaptive.test.ts +133 -0
  184. package/test/neat/neat.entropy.compat.csv.test.ts +108 -0
  185. package/test/neat/neat.evolution.pruning.test.ts +39 -0
  186. package/test/neat/neat.fastmode.autotune.test.ts +42 -0
  187. package/test/neat/neat.innovation.test.ts +134 -0
  188. package/test/neat/neat.lineage.antibreeding.test.ts +35 -0
  189. package/test/neat/neat.lineage.entropy.test.ts +56 -0
  190. package/test/neat/neat.lineage.inbreeding.test.ts +49 -0
  191. package/test/neat/neat.lineage.pressure.test.ts +29 -0
  192. package/test/neat/neat.multiobjective.adaptive.test.ts +57 -0
  193. package/test/neat/neat.multiobjective.dynamic.schedule.test.ts +46 -0
  194. package/test/neat/neat.multiobjective.dynamic.test.ts +31 -0
  195. package/test/neat/neat.multiobjective.fastsort.delegation.test.ts +51 -0
  196. package/test/neat/neat.multiobjective.prune.test.ts +39 -0
  197. package/test/neat/neat.multiobjective.test.ts +21 -0
  198. package/test/neat/neat.mutation.undefined.pool.test.ts +24 -0
  199. package/test/neat/neat.objective.events.test.ts +26 -0
  200. package/test/neat/neat.objective.importance.test.ts +21 -0
  201. package/test/neat/neat.objective.lifetimes.test.ts +33 -0
  202. package/test/neat/neat.offspring.allocation.test.ts +22 -0
  203. package/test/neat/neat.operator.bandit.test.ts +17 -0
  204. package/test/neat/neat.operator.phases.test.ts +38 -0
  205. package/test/neat/neat.pruneInactive.behavior.test.ts +54 -0
  206. package/test/neat/neat.reenable.adaptation.test.ts +18 -0
  207. package/test/neat/neat.rng.state.test.ts +22 -0
  208. package/test/neat/neat.spawn.add.test.ts +123 -0
  209. package/test/neat/neat.speciation.test.ts +96 -0
  210. package/test/neat/neat.species.allocation.telemetry.test.ts +26 -0
  211. package/test/neat/neat.species.history.csv.test.ts +24 -0
  212. package/test/neat/neat.telemetry.advanced.test.ts +226 -0
  213. package/test/neat/neat.telemetry.csv.lineage.test.ts +19 -0
  214. package/test/neat/neat.telemetry.parity.test.ts +42 -0
  215. package/test/neat/neat.telemetry.stream.test.ts +19 -0
  216. package/test/neat/neat.telemetry.test.ts +16 -0
  217. package/test/neat/neat.test.ts +422 -0
  218. package/test/neat/neat.utilities.test.ts +44 -0
  219. package/test/network/__suppress_console.ts +9 -0
  220. package/test/network/acyclic.topoorder.test.ts +17 -0
  221. package/test/network/checkpoint.metricshook.test.ts +36 -0
  222. package/test/network/error.handling.test.ts +581 -0
  223. package/test/network/evolution.test.ts +285 -0
  224. package/test/network/genetic.test.ts +208 -0
  225. package/test/network/learning.capability.test.ts +244 -0
  226. package/test/network/mutation.effects.test.ts +492 -0
  227. package/test/network/network.activate.test.ts +115 -0
  228. package/test/network/network.activateBatch.test.ts +30 -0
  229. package/test/network/network.deterministic.test.ts +64 -0
  230. package/test/network/network.evolve.branches.test.ts +75 -0
  231. package/test/network/network.evolve.multithread.branches.test.ts +83 -0
  232. package/test/network/network.evolve.test.ts +100 -0
  233. package/test/network/network.gating.removal.test.ts +93 -0
  234. package/test/network/network.mutate.additional.test.ts +145 -0
  235. package/test/network/network.mutate.edgecases.test.ts +101 -0
  236. package/test/network/network.mutate.test.ts +101 -0
  237. package/test/network/network.prune.earlyexit.test.ts +38 -0
  238. package/test/network/network.remove.errors.test.ts +45 -0
  239. package/test/network/network.slab.fallbacks.test.ts +22 -0
  240. package/test/network/network.stats.test.ts +45 -0
  241. package/test/network/network.training.advanced.test.ts +149 -0
  242. package/test/network/network.training.basic.test.ts +228 -0
  243. package/test/network/network.training.helpers.test.ts +183 -0
  244. package/test/network/onnx.export.test.ts +310 -0
  245. package/test/network/onnx.import.test.ts +129 -0
  246. package/test/network/pruning.topology.test.ts +282 -0
  247. package/test/network/regularization.determinism.test.ts +83 -0
  248. package/test/network/regularization.dropconnect.test.ts +17 -0
  249. package/test/network/regularization.dropconnect.validation.test.ts +18 -0
  250. package/test/network/regularization.stochasticdepth.test.ts +27 -0
  251. package/test/network/regularization.test.ts +843 -0
  252. package/test/network/regularization.weightnoise.test.ts +30 -0
  253. package/test/network/setupTests.ts +2 -0
  254. package/test/network/standalone.test.ts +332 -0
  255. package/test/network/structure.serialization.test.ts +660 -0
  256. package/test/training/training.determinism.mixed-precision.test.ts +134 -0
  257. package/test/training/training.earlystopping.test.ts +91 -0
  258. package/test/training/training.edge-cases.test.ts +91 -0
  259. package/test/training/training.extensions.test.ts +47 -0
  260. package/test/training/training.gradient.features.test.ts +110 -0
  261. package/test/training/training.gradient.refinements.test.ts +170 -0
  262. package/test/training/training.gradient.separate-bias.test.ts +41 -0
  263. package/test/training/training.optimizer.test.ts +48 -0
  264. package/test/training/training.plateau.smoothing.test.ts +58 -0
  265. package/test/training/training.smoothing.types.test.ts +174 -0
  266. package/test/training/training.train.options.coverage.test.ts +52 -0
  267. package/test/utils/console-helper.ts +76 -0
  268. package/test/utils/jest-setup.ts +60 -0
  269. package/test/utils/test-helpers.ts +175 -0
  270. package/tsconfig.docs.json +12 -0
  271. package/tsconfig.json +21 -0
  272. package/webpack.config.js +49 -0
@@ -0,0 +1,451 @@
1
+ import { mutation } from '../../src/methods/mutation';
2
+ import Activation from '../../src/methods/activation';
3
+
4
+ describe('Mutation Methods', () => {
5
+ describe('ADD_NODE', () => {
6
+ describe('Scenario: Existence', () => {
7
+ it('should exist', () => {
8
+ // Assert
9
+ expect(mutation.ADD_NODE).toBeDefined();
10
+ });
11
+ });
12
+ describe('Scenario: Name property', () => {
13
+ it('should have correct name property', () => {
14
+ // Assert
15
+ expect(mutation.ADD_NODE.name).toBe('ADD_NODE');
16
+ });
17
+ });
18
+ });
19
+
20
+ describe('SUB_NODE', () => {
21
+ describe('Scenario: Existence', () => {
22
+ it('should exist', () => {
23
+ // Assert
24
+ expect(mutation.SUB_NODE).toBeDefined();
25
+ });
26
+ });
27
+ describe('Scenario: Name property', () => {
28
+ it('should have correct name property', () => {
29
+ // Assert
30
+ expect(mutation.SUB_NODE.name).toBe('SUB_NODE');
31
+ });
32
+ });
33
+ describe('Scenario: keep_gates property', () => {
34
+ it('should have keep_gates property', () => {
35
+ // Assert
36
+ expect(mutation.SUB_NODE.keep_gates).toBe(true);
37
+ });
38
+ });
39
+ });
40
+
41
+ describe('ADD_CONN', () => {
42
+ describe('Scenario: Existence', () => {
43
+ it('should exist', () => {
44
+ // Assert
45
+ expect(mutation.ADD_CONN).toBeDefined();
46
+ });
47
+ });
48
+ describe('Scenario: Name property', () => {
49
+ it('should have correct name property', () => {
50
+ // Assert
51
+ expect(mutation.ADD_CONN.name).toBe('ADD_CONN');
52
+ });
53
+ });
54
+ });
55
+
56
+ describe('SUB_CONN', () => {
57
+ describe('Scenario: Existence', () => {
58
+ it('should exist', () => {
59
+ // Assert
60
+ expect(mutation.SUB_CONN).toBeDefined();
61
+ });
62
+ });
63
+ describe('Scenario: Name property', () => {
64
+ it('should have correct name property', () => {
65
+ // Assert
66
+ expect(mutation.SUB_CONN.name).toBe('SUB_CONN');
67
+ });
68
+ });
69
+ });
70
+
71
+ describe('MOD_WEIGHT', () => {
72
+ describe('Scenario: Existence', () => {
73
+ it('should exist', () => {
74
+ // Assert
75
+ expect(mutation.MOD_WEIGHT).toBeDefined();
76
+ });
77
+ });
78
+ describe('Scenario: Name property', () => {
79
+ it('should have correct name property', () => {
80
+ // Assert
81
+ expect(mutation.MOD_WEIGHT.name).toBe('MOD_WEIGHT');
82
+ });
83
+ });
84
+ describe('Scenario: min property', () => {
85
+ it('should have min property', () => {
86
+ // Assert
87
+ expect(mutation.MOD_WEIGHT.min).toBe(-1);
88
+ });
89
+ });
90
+ describe('Scenario: max property', () => {
91
+ it('should have max property', () => {
92
+ // Assert
93
+ expect(mutation.MOD_WEIGHT.max).toBe(1);
94
+ });
95
+ });
96
+ });
97
+
98
+ describe('MOD_BIAS', () => {
99
+ describe('Scenario: Existence', () => {
100
+ it('should exist', () => {
101
+ // Assert
102
+ expect(mutation.MOD_BIAS).toBeDefined();
103
+ });
104
+ });
105
+ describe('Scenario: Name property', () => {
106
+ it('should have correct name property', () => {
107
+ // Assert
108
+ expect(mutation.MOD_BIAS.name).toBe('MOD_BIAS');
109
+ });
110
+ });
111
+ describe('Scenario: min property', () => {
112
+ it('should have min property', () => {
113
+ // Assert
114
+ expect(mutation.MOD_BIAS.min).toBe(-1);
115
+ });
116
+ });
117
+ describe('Scenario: max property', () => {
118
+ it('should have max property', () => {
119
+ // Assert
120
+ expect(mutation.MOD_BIAS.max).toBe(1);
121
+ });
122
+ });
123
+ });
124
+
125
+ describe('MOD_ACTIVATION', () => {
126
+ describe('Scenario: Existence', () => {
127
+ it('should exist', () => {
128
+ // Assert
129
+ expect(mutation.MOD_ACTIVATION).toBeDefined();
130
+ });
131
+ });
132
+ describe('Scenario: Name property', () => {
133
+ it('should have correct name property', () => {
134
+ // Assert
135
+ expect(mutation.MOD_ACTIVATION.name).toBe('MOD_ACTIVATION');
136
+ });
137
+ });
138
+ describe('Scenario: mutateOutput property', () => {
139
+ it('should have mutateOutput property', () => {
140
+ // Assert
141
+ expect(mutation.MOD_ACTIVATION.mutateOutput).toBe(true);
142
+ });
143
+ });
144
+ describe('Scenario: allowed property', () => {
145
+ it('should have allowed property as an array', () => {
146
+ // Assert
147
+ expect(Array.isArray(mutation.MOD_ACTIVATION.allowed)).toBe(true);
148
+ });
149
+ describe('Scenario: Contains expected activation functions', () => {
150
+ const expectedActivations = [
151
+ Activation.logistic,
152
+ Activation.tanh,
153
+ Activation.relu,
154
+ Activation.identity,
155
+ Activation.step,
156
+ Activation.softsign,
157
+ Activation.sinusoid,
158
+ Activation.gaussian,
159
+ Activation.bentIdentity,
160
+ Activation.bipolar,
161
+ Activation.bipolarSigmoid,
162
+ Activation.hardTanh,
163
+ Activation.absolute,
164
+ Activation.inverse,
165
+ Activation.selu,
166
+ Activation.softplus,
167
+ Activation.swish,
168
+ Activation.gelu,
169
+ Activation.mish,
170
+ ];
171
+ expectedActivations.forEach((act) => {
172
+ it(`should contain ${act.name} in allowed`, () => {
173
+ // Assert
174
+ expect(mutation.MOD_ACTIVATION.allowed).toContain(act);
175
+ });
176
+ });
177
+ it('should have allowed property with correct length', () => {
178
+ // Assert
179
+ expect(mutation.MOD_ACTIVATION.allowed.length).toBe(
180
+ expectedActivations.length
181
+ );
182
+ });
183
+ it('should not contain unexpected activation functions', () => {
184
+ // Arrange
185
+ const notExpected: any[] = [];
186
+ // Assert
187
+ notExpected.forEach((act) => {
188
+ expect(mutation.MOD_ACTIVATION.allowed).not.toContain(act);
189
+ });
190
+ });
191
+ });
192
+ });
193
+ });
194
+
195
+ describe('ADD_SELF_CONN', () => {
196
+ describe('Scenario: Existence', () => {
197
+ it('should exist', () => {
198
+ // Assert
199
+ expect(mutation.ADD_SELF_CONN).toBeDefined();
200
+ });
201
+ });
202
+ describe('Scenario: Name property', () => {
203
+ it('should have correct name property', () => {
204
+ // Assert
205
+ expect(mutation.ADD_SELF_CONN.name).toBe('ADD_SELF_CONN');
206
+ });
207
+ });
208
+ });
209
+
210
+ describe('SUB_SELF_CONN', () => {
211
+ describe('Scenario: Existence', () => {
212
+ it('should exist', () => {
213
+ // Assert
214
+ expect(mutation.SUB_SELF_CONN).toBeDefined();
215
+ });
216
+ });
217
+ describe('Scenario: Name property', () => {
218
+ it('should have correct name property', () => {
219
+ // Assert
220
+ expect(mutation.SUB_SELF_CONN.name).toBe('SUB_SELF_CONN');
221
+ });
222
+ });
223
+ });
224
+
225
+ describe('ADD_GATE', () => {
226
+ describe('Scenario: Existence', () => {
227
+ it('should exist', () => {
228
+ // Assert
229
+ expect(mutation.ADD_GATE).toBeDefined();
230
+ });
231
+ });
232
+ describe('Scenario: Name property', () => {
233
+ it('should have correct name property', () => {
234
+ // Assert
235
+ expect(mutation.ADD_GATE.name).toBe('ADD_GATE');
236
+ });
237
+ });
238
+ });
239
+
240
+ describe('SUB_GATE', () => {
241
+ describe('Scenario: Existence', () => {
242
+ it('should exist', () => {
243
+ // Assert
244
+ expect(mutation.SUB_GATE).toBeDefined();
245
+ });
246
+ });
247
+ describe('Scenario: Name property', () => {
248
+ it('should have correct name property', () => {
249
+ // Assert
250
+ expect(mutation.SUB_GATE.name).toBe('SUB_GATE');
251
+ });
252
+ });
253
+ });
254
+
255
+ describe('ADD_BACK_CONN', () => {
256
+ describe('Scenario: Existence', () => {
257
+ it('should exist', () => {
258
+ // Assert
259
+ expect(mutation.ADD_BACK_CONN).toBeDefined();
260
+ });
261
+ });
262
+ describe('Scenario: Name property', () => {
263
+ it('should have correct name property', () => {
264
+ // Assert
265
+ expect(mutation.ADD_BACK_CONN.name).toBe('ADD_BACK_CONN');
266
+ });
267
+ });
268
+ });
269
+
270
+ describe('SUB_BACK_CONN', () => {
271
+ describe('Scenario: Existence', () => {
272
+ it('should exist', () => {
273
+ // Assert
274
+ expect(mutation.SUB_BACK_CONN).toBeDefined();
275
+ });
276
+ });
277
+ describe('Scenario: Name property', () => {
278
+ it('should have correct name property', () => {
279
+ // Assert
280
+ expect(mutation.SUB_BACK_CONN.name).toBe('SUB_BACK_CONN');
281
+ });
282
+ });
283
+ });
284
+
285
+ describe('SWAP_NODES', () => {
286
+ describe('Scenario: Existence', () => {
287
+ it('should exist', () => {
288
+ // Assert
289
+ expect(mutation.SWAP_NODES).toBeDefined();
290
+ });
291
+ });
292
+ describe('Scenario: Name property', () => {
293
+ it('should have correct name property', () => {
294
+ // Assert
295
+ expect(mutation.SWAP_NODES.name).toBe('SWAP_NODES');
296
+ });
297
+ });
298
+ describe('Scenario: mutateOutput property', () => {
299
+ it('should have mutateOutput property', () => {
300
+ // Assert
301
+ expect(mutation.SWAP_NODES.mutateOutput).toBe(true);
302
+ });
303
+ });
304
+ });
305
+
306
+ describe('ADD_LSTM_NODE', () => {
307
+ describe('Scenario: Existence', () => {
308
+ it('should exist', () => {
309
+ expect(mutation.ADD_LSTM_NODE).toBeDefined();
310
+ });
311
+ });
312
+ describe('Scenario: Name property', () => {
313
+ it('should have correct name property', () => {
314
+ expect(mutation.ADD_LSTM_NODE.name).toBe('ADD_LSTM_NODE');
315
+ });
316
+ });
317
+ });
318
+
319
+ describe('ADD_GRU_NODE', () => {
320
+ describe('Scenario: Existence', () => {
321
+ it('should exist', () => {
322
+ expect(mutation.ADD_GRU_NODE).toBeDefined();
323
+ });
324
+ });
325
+ describe('Scenario: Name property', () => {
326
+ it('should have correct name property', () => {
327
+ expect(mutation.ADD_GRU_NODE.name).toBe('ADD_GRU_NODE');
328
+ });
329
+ });
330
+ });
331
+
332
+ describe('ALL', () => {
333
+ describe('Scenario: Existence', () => {
334
+ describe('when mutation.ALL is defined', () => {
335
+ it('should be defined', () => {
336
+ // Assert
337
+ expect(mutation.ALL).toBeDefined();
338
+ });
339
+ });
340
+ describe('when mutation.ALL is an array', () => {
341
+ it('should be an array', () => {
342
+ // Assert
343
+ expect(Array.isArray(mutation.ALL)).toBe(true);
344
+ });
345
+ });
346
+ });
347
+ describe('Scenario: Contains all mutation methods', () => {
348
+ const expectedMethods = [
349
+ mutation.ADD_NODE,
350
+ mutation.SUB_NODE,
351
+ mutation.ADD_CONN,
352
+ mutation.SUB_CONN,
353
+ mutation.MOD_WEIGHT,
354
+ mutation.MOD_BIAS,
355
+ mutation.MOD_ACTIVATION,
356
+ mutation.ADD_GATE,
357
+ mutation.SUB_GATE,
358
+ mutation.ADD_SELF_CONN,
359
+ mutation.SUB_SELF_CONN,
360
+ mutation.ADD_BACK_CONN,
361
+ mutation.SUB_BACK_CONN,
362
+ mutation.SWAP_NODES,
363
+ mutation.REINIT_WEIGHT,
364
+ mutation.BATCH_NORM,
365
+ mutation.ADD_LSTM_NODE,
366
+ mutation.ADD_GRU_NODE,
367
+ ];
368
+ expectedMethods.forEach((method) => {
369
+ describe(`when ALL contains ${method.name}`, () => {
370
+ it(`should contain ${method.name}`, () => {
371
+ // Assert
372
+ expect(mutation.ALL).toContain(method);
373
+ });
374
+ });
375
+ });
376
+ it('should have correct length', () => {
377
+ // Assert
378
+ expect(mutation.ALL.length).toBe(18);
379
+ });
380
+ it('should not contain unexpected mutation methods', () => {
381
+ // Arrange
382
+ const notExpected: any[] = [];
383
+ // Assert
384
+ notExpected.forEach((method) => {
385
+ expect(mutation.ALL).not.toContain(method);
386
+ });
387
+ });
388
+ });
389
+ });
390
+
391
+ describe('FFW', () => {
392
+ describe('Scenario: Existence', () => {
393
+ describe('when mutation.FFW is defined', () => {
394
+ it('should be defined', () => {
395
+ // Assert
396
+ expect(mutation.FFW).toBeDefined();
397
+ });
398
+ });
399
+ describe('when mutation.FFW is an array', () => {
400
+ it('should be an array', () => {
401
+ // Assert
402
+ expect(Array.isArray(mutation.FFW)).toBe(true);
403
+ });
404
+ });
405
+ });
406
+ describe('Scenario: Contains only feedforward-compatible mutation methods', () => {
407
+ const expectedMethods = [
408
+ mutation.ADD_NODE,
409
+ mutation.SUB_NODE,
410
+ mutation.ADD_CONN,
411
+ mutation.SUB_CONN,
412
+ mutation.MOD_WEIGHT,
413
+ mutation.MOD_BIAS,
414
+ mutation.MOD_ACTIVATION,
415
+ mutation.SWAP_NODES,
416
+ mutation.REINIT_WEIGHT,
417
+ mutation.BATCH_NORM,
418
+ ];
419
+ expectedMethods.forEach((method) => {
420
+ describe(`when FFW contains ${method.name}`, () => {
421
+ it(`should contain ${method.name}`, () => {
422
+ // Assert
423
+ expect(mutation.FFW).toContain(method);
424
+ });
425
+ });
426
+ });
427
+ it('should have correct length', () => {
428
+ // Assert
429
+ expect(mutation.FFW.length).toBe(10);
430
+ });
431
+ describe('Scenario: Does not contain recurrent mutation methods', () => {
432
+ const recurrentMethods = [
433
+ mutation.ADD_GATE,
434
+ mutation.SUB_GATE,
435
+ mutation.ADD_SELF_CONN,
436
+ mutation.SUB_SELF_CONN,
437
+ mutation.ADD_BACK_CONN,
438
+ mutation.SUB_BACK_CONN,
439
+ ];
440
+ recurrentMethods.forEach((method) => {
441
+ describe(`when FFW does not contain ${method.name}`, () => {
442
+ it(`should not contain ${method.name}`, () => {
443
+ // Assert
444
+ expect(mutation.FFW).not.toContain(method);
445
+ });
446
+ });
447
+ });
448
+ });
449
+ });
450
+ });
451
+ });
@@ -0,0 +1,80 @@
1
+ import Network from '../../src/architecture/network';
2
+
3
+ // Helper to build tiny network (1 input -> 1 output) for deterministic gradient on identity activation
4
+ function buildNet() {
5
+ const net = new Network(1, 1);
6
+ // Force deterministic weights/bias
7
+ net.connections.forEach((c) => (c.weight = 0.5));
8
+ net.nodes.filter((n) => n.type !== 'input').forEach((n) => (n.bias = 0));
9
+ return net;
10
+ }
11
+
12
+ // Simple dataset: y = 2x so gradient direction is clear
13
+ const data = Array.from({ length: 5 }, (_, i) => ({
14
+ input: [i],
15
+ output: [2 * i],
16
+ }));
17
+
18
+ // Run few iterations and collect first weight change sign/magnitude
19
+ function trainWith(net: Network, opt: any) {
20
+ const before = net.connections[0].weight;
21
+ net.train(data, {
22
+ iterations: 3,
23
+ rate: 0.01,
24
+ error: 0,
25
+ cost: {
26
+ fn: (t: number[], o: number[]) => (o[0] - t[0]) ** 2,
27
+ calculate: (t: number[], o: number[]) => (o[0] - t[0]) ** 2,
28
+ },
29
+ optimizer: opt,
30
+ batchSize: 1,
31
+ });
32
+ const after = net.connections[0].weight;
33
+ return { before, after, delta: after - before };
34
+ }
35
+
36
+ describe('Advanced optimizers', () => {
37
+ describe('adamax', () => {
38
+ const { delta } = trainWith(buildNet(), { type: 'adamax' });
39
+ it('updates weight (non-zero delta)', () => {
40
+ expect(delta).not.toBe(0);
41
+ });
42
+ });
43
+ describe('nadam', () => {
44
+ const { delta } = trainWith(buildNet(), { type: 'nadam' });
45
+ it('applies nesterov style update (delta non-zero)', () => {
46
+ expect(delta).not.toBe(0);
47
+ });
48
+ });
49
+ describe('radam', () => {
50
+ const { delta } = trainWith(buildNet(), { type: 'radam' });
51
+ it('performs rectified adaptive update (delta non-zero)', () => {
52
+ expect(delta).not.toBe(0);
53
+ });
54
+ });
55
+ describe('lion', () => {
56
+ const { delta } = trainWith(buildNet(), { type: 'lion' });
57
+ it('uses sign-based update (delta non-zero)', () => {
58
+ expect(delta).not.toBe(0);
59
+ });
60
+ });
61
+ describe('adabelief', () => {
62
+ const { delta } = trainWith(buildNet(), { type: 'adabelief' });
63
+ it('adapts with belief variance (delta non-zero)', () => {
64
+ expect(delta).not.toBe(0);
65
+ });
66
+ });
67
+ });
68
+
69
+ describe('Lookahead wrapper', () => {
70
+ const net = buildNet();
71
+ const result = trainWith(net, {
72
+ type: 'lookahead',
73
+ baseType: 'adam',
74
+ la_k: 2,
75
+ la_alpha: 0.5,
76
+ });
77
+ it('applies lookahead blended update (delta non-zero)', () => {
78
+ expect(result.delta).not.toBe(0);
79
+ });
80
+ });
@@ -0,0 +1,105 @@
1
+ import Network from '../../src/architecture/network';
2
+
3
+ // Deterministic small dataset y = 2x
4
+ const data = Array.from({ length: 4 }, (_, i) => ({
5
+ input: [i + 1],
6
+ output: [2 * (i + 1)],
7
+ }));
8
+
9
+ function buildNet() {
10
+ const net = new Network(1, 1);
11
+ // set fixed weights
12
+ net.connections.forEach((c) => (c.weight = 0.5));
13
+ net.nodes.filter((n) => n.type !== 'input').forEach((n) => (n.bias = 0));
14
+ return net;
15
+ }
16
+
17
+ describe('Optimizer specific behaviors', () => {
18
+ describe('adamw', () => {
19
+ const net = buildNet();
20
+ const before = net.connections[0].weight;
21
+ net.train(data, {
22
+ iterations: 5,
23
+ rate: 0.01,
24
+ optimizer: { type: 'adamw', weightDecay: 0.1 },
25
+ });
26
+ const after = net.connections[0].weight;
27
+ it('applies decoupled weight decay (weight decreased)', () => {
28
+ expect(after).toBeLessThan(before);
29
+ });
30
+ });
31
+
32
+ describe('lion', () => {
33
+ const net = buildNet();
34
+ const before = net.connections[0].weight;
35
+ net.train(data, {
36
+ iterations: 5,
37
+ rate: 0.01,
38
+ optimizer: { type: 'lion', beta1: 0.9, beta2: 0.99 },
39
+ });
40
+ const after = net.connections[0].weight;
41
+ it('updates weight (changed from before)', () => {
42
+ expect(after).not.toBe(before);
43
+ });
44
+ // Bound magnitude in separate single-expectation test
45
+ it('produces bounded cumulative magnitude (|delta| < 0.25)', () => {
46
+ expect(Math.abs(after - before)).toBeLessThan(0.25);
47
+ });
48
+ });
49
+
50
+ describe('lookahead sync', () => {
51
+ const net = buildNet();
52
+ net.train(data, {
53
+ iterations: 6,
54
+ rate: 0.01,
55
+ optimizer: {
56
+ type: 'lookahead',
57
+ baseType: 'adam',
58
+ la_k: 3,
59
+ la_alpha: 0.5,
60
+ },
61
+ });
62
+ const conn: any = net.connections[0];
63
+ it('creates shadow weight', () => {
64
+ expect(conn._la_shadowWeight).toBeDefined();
65
+ });
66
+ it('synchronizes weight to shadow on k-multiple', () => {
67
+ const conn: any = net.connections[0];
68
+ expect(conn.weight).toBeCloseTo(conn._la_shadowWeight, 10);
69
+ });
70
+ });
71
+
72
+ describe('string optimizer normalization', () => {
73
+ const net = buildNet();
74
+ net.train(data, { iterations: 1, rate: 0.01, optimizer: 'adam' });
75
+ const conn: any = net.connections[0];
76
+ it('creates first moment', () => {
77
+ expect(conn.opt_m).toBeDefined();
78
+ });
79
+ it('creates second moment', () => {
80
+ expect(conn.opt_v).toBeDefined();
81
+ });
82
+ });
83
+
84
+ describe('invalid optimizer name', () => {
85
+ it('throws error', () => {
86
+ const net = buildNet();
87
+ expect(() =>
88
+ net.train(data, { iterations: 1, rate: 0.01, optimizer: 'nope' as any })
89
+ ).toThrow('Unknown optimizer type');
90
+ });
91
+ });
92
+
93
+ describe('nested lookahead rejection', () => {
94
+ it('throws error', () => {
95
+ const net = buildNet();
96
+ expect(() =>
97
+ net.train(data, {
98
+ iterations: 1,
99
+ rate: 0.01,
100
+ optimizer: { type: 'lookahead', baseType: 'lookahead' },
101
+ })
102
+ ).toThrow('Nested lookahead');
103
+ });
104
+ });
105
+ });