This release is 136 versions behind 0.168.1 — the latest version of @stsoftware/neat-ai. Jump to latest
@stsoftware/neat-ai@0.121.0Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
NEAT Neural Network. This project is a unique implementation of a neural network based on the NEAT (NeuroEvolution of Augmenting Topologies) algorithm, written in DenoJS using TypeScript.
import { assert } from "jsr:@std/assert@^1.0.8"; import type { NeatOptions } from "../src/config/NeatOptions.ts"; import { Creature } from "../src/Creature.ts"; ((globalThis as unknown) as { DEBUG: boolean }).DEBUG = true; Deno.test("hypotenuse", async () => { const ts = []; for (let i = 100; i--;) { for (let j = 100; j--;) { if (i == 50) continue; const item = { input: [i, j], output: [Math.sqrt(i * i + j * j)], }; ts.push(item); } } const options: NeatOptions = { iterations: 100, targetError: 0.002, log: 50, elitism: 3, enableRepetitiveTraining: true, }; let errorPercent = 0; let answer = 0; for (let attempts = 0; attempts < 240; attempts++) { const network = new Creature(2, 1, { layers: [ { count: 2 }, ], }); await network.evolveDataSet(ts, options); const check = new Float32Array([50, 60]); answer = network.activate(check)[0]; errorPercent = Math.round((1 - answer / 78.1) * 100); if (Math.abs(errorPercent) < 10) break; } assert( Math.abs(errorPercent) <= 10, "Correct answer is ~78.1 but was: " + answer + " ( " + errorPercent + "% )", ); });