UNPKG

@alenaksu/neatjs

Version:

NEAT (Neuroevolution of Augmenting Topologies) implementation in JavaScript

58 lines 1.74 kB
import { Genome } from './Genome'; import Network from '../network/Network'; import { ascending } from '../utils'; /** * Organisms are Genomes and Networks with fitness informations * i.e. The genotype and phenotype together */ export class Organism extends Genome { constructor( // innovation: Iterator<number>, fitness = 0, generation = 0) { super(); /** * A measure of fitness before adjustment */ this.originalFitness = 0; /** * Mark for killing */ this.kill = false; /** * Generation in which Organism is from */ this.generation = 0; /** * Number of children this Organism may have */ this.expectedOffspring = 0; this.fitness = fitness; this.generation = generation; } copy(fitness = 0, generation = 0) { let clone = super.copy(); clone.fitness = fitness; clone.originalFitness = this.originalFitness; clone.generation = generation; return clone; } getNetwork() { if (!this.network) { const nodes = Array.from(this.nodes.values()).map(({ type, id }) => ({ type, id })); const connections = Array.from(this.connections.values()) .sort(ascending((i) => i.innovation)) .map(({ from, to, weight, enabled }) => ({ from: from.id, to: to.id, weight: weight, enabled: enabled })); this.network = new Network(nodes, connections); } return this.network; } } //# sourceMappingURL=Organism.js.map