1.0.12 • Published 2 years ago

@kylehue/neat v1.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@kylehue/neat

:robot: A simple NEAT Algorithm implementation in JavaScript.

Installation

npm i @kylehue/neat

Usage

const Neat = require("@kylehue/neat");

let neat = new Neat(input, hidden, output, options);

Options

{
  // Total number of genomes
  populationSize: 20,
  // Determines how many genomes should be mutated in a generation
  mutationRate: 0.25,
  // Maximum number of generations a species can exist without making any improvements
  maxStagnation: 30
}

Feedforward & Fitness

let neat = new Neat(6, 1, 3, {
  populationSize: 10
});

class Turtle {
  constructor(genome) {
    this.brain = genome;
  }

  eat() {
    this.brain.fitness++; // Add fitness score
  }
}

// Create turtles
let turtles = [];
for (var i = 0; i < neat.populationSize; i++) {
  turtles.push(neat.population.genomes[i]);
}

// Feedforward inputs
for (var i = 0; i < turtles.length; i++) {
  turtles[i].brain.feedforward([...]);
}

Evolve

let neat = new Neat(6, 1, 3, {
  populationSize: 10
});

function evolve() {
  neat.population.evolve();
  nextGen();
}

toJSON

You can create pre-trained models by using toJSON()

let neat = new Neat(6, 1, 3, {
  populationSize: 10
});

let trained = neat.toJSON();
download(trained);

fromJSON & import

And you can import pre-trained models by using fromJSON() and import()

let neat = new Neat(6, 1, 3, {
  populationSize: 10
});

let genomes = neat.fromJSON(jsonFile);
neat.import(genomes, neat.populationSize);
1.0.12

2 years ago

1.0.11

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago