apssouza22 / neuroevolution

In this project we combine Artificial Neural Network and Genetics Algorithms to build powerful AI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NeuroEvolution made easy

Neuroevolution is a powerful approach to machine learning and artificial intelligence that uses evolutionary algorithms to evolve neural networks.

This project contain a neuro-evolution library that allows you to easily use NeuroEvolution in your game.

In this project, we have applied GeneticEvolution to multiple games such as self-driving cars, smart caps and flappy bird.

Alt text

This project is a follow-up to my project about Artificial Neural Networks from scratch, where I show how to create an ANN from scratch without libraries. In that project the learning process is done using backpropagation(gradient descent), this project use a different approach, we will use Evolutionary Algorithm.

Evolutionary algorithm uses mechanisms inspired by biological evolution, such as reproduction, mutation, recombination, and selection. Candidate solutions to the optimization problem play the role of individuals in a population, and the fitness function determines the quality of the solutions. Evolution of the population then takes place after the repeated application of the above operators.

The project is developed from scratch and with no external libraries.

Get started

The library is in the neuroevolution folder. The library is composed of 3 main classes:

  • NeuralNetwork: This class represents the required Artificial Neural network.
  • GeneticEvolution: This class represents the Genetic Evolution Algorithm.
  • PopulationHandler: This class represents the genetic population.
  • PopulationItem: This class represents the item in population.
## Inititalize the genetic evolution
let population = [new PopulationItem(), new PopulationItem()]
let populationHandler =  new PopulationHandler(population)
let geneticEvolution = new GeneticEvolution(populationHandler);

## Evolve the population after each generation
geneticEvolution.evolve(); // evolve the population based on the fitness function


PopulationItem and PopulationHandler are classes that you need to implement in your game. Population Item examples:

You can use the population genes to perform the game action. See the Car.steer, SmartCaps.makeMove and FlappyBird.think methods.

geneticEvolution.getPopulationHandler().getPopulation().forEach((item) => {
    let output = item.useGenes(input);
    log(output);
});

Alt text Alt text Alt text

If this project helped you, consider leaving a star and by me a coffee


To learn more about the game examples check the following links:

About

In this project we combine Artificial Neural Network and Genetics Algorithms to build powerful AI

License:MIT License


Languages

Language:JavaScript 94.6%Language:HTML 4.7%Language:CSS 0.7%