Skip to main content

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
9 hours ago (0.155.18)
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[]>
private
abstract
creatureActivationFunction: () => undefined

The number of input neurons.

abstract
memetic: MemeticInterface

Records the origins of this creature.

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: Float32Array,
feedbackLoop?: boolean,
): Float32Array

Activates the creature without calculating traces.

activateAndTrace(
input: Float32Array,
feedbackLoop: boolean,
sparseConfig: SparseConfig,
): Float32Array

Activates the creature and traces the activity.

applyLearnings(
config: BackPropagationConfig,
sparseConfig: SparseConfig,
): boolean

Apply learnings to the creature using back propagation.

private
bulkLoadInwardConnections(toIndx: number): Synapse[]

Precompiles all inward connections and caches them for fast lookup.

clearCache(
from?: number,
to?: number,
): 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.

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; generation: 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
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.

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

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.

private
prepareNeurons(): void
propagate(
expected: Float32Array,
config: BackPropagationConfig,
sparseConfig: SparseConfig,
): void

Propagate the expected values through the creature's network.

propagateUpdate(
config: BackPropagationConfig,
sparseConfig: SparseConfig,
): void

Update the propagated values in the creature's network.

record(expected: Float32Array): Map<string, DiscoverRecord>

Record the expected values for back propagation.

selfConnection(indx: number): SynapseInternal | null

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

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

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";