Skip to main content
This release is 125 versions behind 0.165.7 — the latest version of @stsoftware/neat-ai. Jump to latest

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.

This package works with Deno
This package works with Deno
JSR Score
100%
Published
4 months ago (0.121.0)

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Package root>test>TraceStore.ts
import { assert } from "jsr:@std/assert@^1.0.8"; import { emptyDirSync, ensureDirSync } from "jsr:@std/fs@^1.0.6"; import { Creature } from "../src/Creature.ts"; import type { CreatureInternal } from "../src/architecture/CreatureInterfaces.ts"; import type { SynapseTrace } from "../src/architecture/SynapseInterfaces.ts"; import type { NeatOptions } from "../src/config/NeatOptions.ts"; ((globalThis as unknown) as { DEBUG: boolean }).DEBUG = true; Deno.test("storeTrace", async () => { const json: CreatureInternal = { neurons: [ { type: "input", index: 0 }, { type: "input", index: 1 }, { type: "input", index: 2 }, { type: "output", squash: "IF", index: 3, bias: 0, }, ], synapses: [ { from: 0, to: 3, weight: 0.9, type: "condition" }, { from: 1, to: 3, weight: 1.1, type: "positive" }, { from: 2, to: 3, weight: 0.95, type: "negative" }, ], input: 3, output: 1, }; const ts = []; for (let i = 100; i--;) { for (let j = 100; j--;) { if (i == 50) continue; const condition = Math.random() * 2 - 1; const positive = Math.random(); const negative = Math.random(); const item = { input: [condition, positive, negative], output: [condition > 0 ? positive : negative], }; ts.push(item); } } const traceDir = ".trace"; ensureDirSync(traceDir); const creaturesDir = ".creatures"; emptyDirSync(creaturesDir); let foundUsed = false; let totalCount = 0; for (let counter = 10; counter--;) { const options: NeatOptions = { iterations: 10, traceStore: traceDir, creatureStore: creaturesDir, threads: 1, targetError: 0, }; const network = Creature.fromJSON(json); await network.evolveDataSet(ts, options); for (const dirEntry of Deno.readDirSync(traceDir)) { if (dirEntry.name.endsWith(".json")) { const json = JSON.parse( Deno.readTextFileSync(`${traceDir}/${dirEntry.name}`), ); let usedCount = 0; if (json.synapses == undefined) continue; json.synapses.forEach((c: SynapseTrace) => { if (c.trace && c.trace.used) { usedCount++; } if ( Number.isFinite(c.trace?.count) && c.trace.count != 0 ) { totalCount++; } }); if (usedCount > 1) { foundUsed = true; } } } if (foundUsed) break; } assert( foundUsed, "Should have traced usage", ); assert( totalCount > 0, "Should have totalCount", ); });