Skip to main content
This release is 229 versions behind 0.166.0 — 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
94%
Published
11 months ago (0.76.2)
class Creature
implements CreatureInternal

Creature Class

The Creature class represents an AI entity within the NEAT (NeuroEvolution of Augmenting Topologies) framework. It encapsulates the neural network structure and its associated behaviors, including activation, mutation, propagation, and evolution processes. This class is integral to the simulation and evolution of neural networks.

Constructors

new
Creature(
input: number,
output: number,
options?: { lazyInitialization?: boolean; layers?: { squash?: string; count: number; }[]; },
)

Constructs a new Creature instance.

Properties

Debug mode flag.

private
cacheFrom: Map<number, Synapse[]>
private
cacheSelf: Map<number, Synapse[]>
private
cacheTo: Map<number, Synapse[]>

The number of input neurons.

neurons: Neuron[]

The array of neurons within this creature.

The number of output neurons.

abstract
score: number

The score of the creature, used for evaluating fitness.

readonly
state: CreatureState

The state of the creature, managing the internal state and activations.

synapses: Synapse[]

The array of synapses (connections) between neurons.

abstract
tags: TagInterface[]

Optional tags associated with the creature.

abstract
uuid: string

The unique identifier of this creature.

Methods

activate(
input: number[],
feedbackLoop?: boolean,
): number[]

Activates the creature without calculating traces.

activateAndTrace(
input: number[],
feedbackLoop?: boolean,
): number[]

Activates the creature and traces the activity.

private
addBackConn(focusList?: number[]): void
addConnection(
focusList?: number[],
options?: { weightScale: number; },
): void

Add a connection between two neurons.

addNeuron(focusList?: number[]): void

Add a neuron to the network.

private
addSelfCon(focusList?: number[]): void
applyLearnings(config: BackPropagationConfig): boolean

Apply learnings to the creature using back propagation.

clearCache(
from?,
to?,
): void

Clear the cache of connections.

clearState(): void

Clear the context of the creature.

compact(): Creature | undefined

Compact the creature by removing redundant neurons and connections.

connect(
from: number,
to: number,
weight: number,
type?:
"positive"
| "negative"
| "condition"
,
): Synapse

Connect two neurons with a synapse.

disconnect(
from: number,
to: number,
): void

Disconnect two neurons by removing the synapse between them.

dispose(): void

Dispose of the creature and all held memory.

private
evaluateData(
json: { input: number[]; output: number[]; }[],
cost: CostInterface,
feedbackLoop: boolean,
): { error: number; count: number; }
evaluateDir(
dataDir: string,
cost: CostInterface,
feedbackLoop: boolean,
): { error: number; }

Evaluate a dataset and return the error.

evolveDataSet(
dataSet: DataRecordInterface[],
options: NeatOptions,
): Promise<{ error: number; score: number; time: number; }>

Evolve the creature to achieve a lower error on a dataset.

evolveDir(
dataSetDir: string,
options: NeatOptions,
): Promise<{ error: number; score: number; time: number; }>

Evolve the creature to achieve a lower error on a dataset.

Convert the creature to a JSON object.

fix(): void

Fix the structure of the creature.

getSynapse(
from: number,
to: number,
): Synapse | null

Get a specific synapse between two neurons.

inFocus(
index: number,
focusList?: number[],
checked?: Set<number>,
): boolean

Check if a neuron is in focus.

private
initialize(options: { layers?: { squash?: string; count: number; }[]; }): void
private
insertNeuron(neuron: Neuron): void
internalJSON(): CreatureInternal

Convert the creature to an internal JSON object.

inwardConnections(toIndx: number): Synapse[]

Get the inward connections (afferent) for the neuron at the given index.

loadFrom(
json: CreatureInternal | CreatureExport,
validate: boolean,
): void

Load the creature from a JSON object.

makeRandomConnection(indx: number): Synapse | null

Create a random connection for the neuron at the given index.

private
modActivation(focusList?: number[]): void
modBias(focusList?: number[]): void

Modify the bias of a neuron.

private
modWeight(focusList?: number[]): void
mutate(
method: { name: string; },
focusList?: number[],
): void

Mutate the creature using a specific method.

Get the node count of the creature.

Get the output count of the creature.

outwardConnections(fromIndx: number): Synapse[]

Get the outward connections (efferent) for the neuron at the given index.

propagate(
expected: number[],
config: BackPropagationConfig,
): void

Propagate the expected values through the creature's network.

propagateUpdate(config: BackPropagationConfig): void

Update the propagated values in the creature's network.

selfConnection(indx: number): SynapseInternal | null

Get a self-connection for the neuron at the given index.

private
subBackConn(focusList?: number[]): void
subConnection(focusList?: number[]): void

Subtract a connection from the network.

subNeuron(focusList?: number[]): void

Subtract a neuron from the network.

private
subSelfCon(focusList?: number[]): void
private
swapNodes(focusList?: number[]): void

Convert the creature to a trace JSON object.

validate(): void

Validate the creature structure.

private
writeCreatures(
neat: Neat,
dir: string,
): void

Static Methods

fromJSON(
json: CreatureInternal | CreatureExport,
validate?: boolean,
): Creature

Convert a json object to a creature

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.

Add Package

deno add jsr:@stsoftware/neat-ai

Import symbol

import { Creature } from "@stsoftware/neat-ai";
or

Import directly with a jsr specifier

import { Creature } from "jsr:@stsoftware/neat-ai";