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 { Creature } from "../src/Creature.ts"; import type { CreatureInternal } from "../src/architecture/CreatureInterfaces.ts"; import { ELU } from "../src/methods/activations/types/ELU.ts"; import { createBackPropagationConfig } from "../src/propagate/BackPropagation.ts"; import { SparseConfig } from "../src/propagate/sparse/SparseConfig.ts"; ((globalThis as unknown) as { DEBUG: boolean }).DEBUG = true; Deno.test("ELU", () => { const json: CreatureInternal = { neurons: [ { bias: 0, type: "output", squash: "ELU", index: 3 }, ], synapses: [ { weight: 1, from: 0, to: 1 }, ], input: 1, output: 1, }; const creature = Creature.fromJSON(json); const sparseConfig = new SparseConfig( creature.exportJSON(), createBackPropagationConfig({}), ); const activation = new ELU(); for (let p = 0; p < 1000; p++) { const a = Math.random() * 4 - 2; const data = [a]; const actual = creature.activateAndTrace(new Float32Array(data), false, sparseConfig)[0]; const actual2 = creature.activateAndTrace(new Float32Array(data), false, sparseConfig)[0]; assert( Math.abs(actual - actual2) < 0.00000001, "repeated calls should return the same result", ); const expected = activation.squash(a); assert( Math.abs(expected - actual) < 0.00001, p + ") Expected: " + expected + ", actual: " + actual + ", data: " + data, ); } });