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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147import { assert } from "jsr:@std/assert@^1.0.8"; import { getTag } from "jsr:@stsoftware/tags@^1.0.5"; import { Creature } from "../src/Creature.ts"; import type { CreatureInternal } from "../src/architecture/CreatureInterfaces.ts"; import { creatureValidate } from "../src/architecture/CreatureValidate.ts"; import { AddNeuron } from "../src/mutate/AddNeuron.ts"; ((globalThis as unknown) as { DEBUG: boolean }).DEBUG = true; const json: CreatureInternal = { neurons: [ { type: "input", squash: "LOGISTIC", index: 0, }, { type: "input", squash: "LOGISTIC", index: 1, }, { type: "input", squash: "LOGISTIC", index: 2, }, { bias: 0, type: "hidden", squash: "TANH", index: 3, tags: [{ name: "original", value: "yes", }], }, { bias: 0, type: "output", squash: "IF", index: 4, }, ], synapses: [ { weight: 1, from: 2, to: 4, type: "positive", }, { weight: 1, from: 1, to: 4, type: "condition", }, { weight: 1, from: 0, to: 4, type: "negative", }, { weight: 0.09059831121601714, from: 2, to: 3, }, { weight: -0.05057706266658744, from: 3, to: 4, }, ], input: 3, output: 1, }; Deno.test("addNodeValidate", () => { for (let j = 10; j--;) { const creature = Creature.fromJSON(json); const addNeuron = new AddNeuron(creature); for (let i = 1000; i--;) { addNeuron.mutate(); } creatureValidate(creature); } }); Deno.test("addNode", () => { const creature = Creature.fromJSON(json); const addNeuron = new AddNeuron(creature); for (let i = 1000; i--;) { addNeuron.mutate(); } const nodes = creature.internalJSON().neurons; for (let pos = nodes.length; pos--;) { const node = nodes[pos]; const indx = creature.input + pos; const tag = getTag(node, "original"); if (tag === "yes") { assert( indx > 3, "Unlikely to be the first node after randomly adding 1000 nodes was: " + indx, ); } if (tag === "yes") { assert( indx < 1004, "Unlikely to be the last node after randomly adding 1000 nodes was: " + indx, ); } const to = creature.inwardConnections(indx); if (node.type !== "input") { assert(to.length >= 1, indx + ") expected at least 1 got " + to.length); } else { assert( to.length == 0, indx + ") 'input' should not have any 'to' connections was: " + to.length, ); } const from = creature.outwardConnections(indx); if (node.type !== "output") { assert( from.length >= 1, indx + ") expected at least 1 got " + from.length, ); } else { assert( from.length == 0, indx + ") 'output' should not have any 'from' connections was: " + from.length, ); } } });