Skip to content

Hamezii/neural-ga

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Neural-ga

A personal project to explore how to represent neural networks computationally, and apply a genetic algorithm to them!

In the code are a few examples/experiments testing the behaviour of the neural net/genetic algorithm (e.g. teaching the neural nets to mimic an adder/sin wave)

Creatures.py

image

The main project of interest is creatures.py, which simulates a grid-based environment of creatures learning to collect food.

Execution

Run creatures.py. Requires Python, Numpy, Pygame.

Controls

  • Left, Right: Speed up and slow down simulation. Max speed is Fast Mode, where drawing is skipped for each generation in order to speed up simulation.

  • Space: Toggle pause.

  • Mouse: Hover over a creature to see its fitness i.e. how much food it has eaten. Left click to set the fitness to 0, right click to increase the fitness by 1.

  • Escape: Close program.

Neural net notes

  • The values of the inputs to the neural net are functions of the distance to the nearest map edge, creature, and food, in the 4 cardinal directions (ordered up, right, down, left).
  • The top 4 outputs are the weighting of how much the creature wants to move in each cardinal direction. If all are negative, the creature does not move, otherwise it moves in the direction with the greatest value.
  • The color of a creature represents the current value in its memory. Each step, the bottom output value goes into memory and is fed back into the NN via the bottom input.