nerdimite / neuroevolution

Simple Neuroevolution to Solve the CartPole Environment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Intro to Neuroevolution

Neuroevolution is the application of genetic algorithms to optimize the parameters and/or topology of a neural netwwork.

This repository contains the code for the second part of the webinar series I am doing on Evolutionary AI. In this session, I demonstrate the basics of neuroevolution by evolving a population of fixed topology neural networks to balance a cartpole.

Requirements

  • PyTorch
  • Gym
  • Numpy

Usage

  1. Open and the Neuroevolution.ipynb and run the code cells or directly open the Colab Version
  2. Modify the Agent Class to experiment with different topologies i.e. hidden layers and units
  3. You can either choose to run the algorithm for a fixed number of generations or a fixed time in seconds. Refer the comments in the evolve function for details on which lines to comment/uncomment for choosing fixed generations/time.
  4. Run the play_agent function to see the trained agent balancing the cartpole.
  5. You can also run the dqn_cartpole.py script to compare Neuroevolution against Deep Q Network RL algorithm on the same environment. The default time that the DQN script runs is 120 seconds which can be changed using the max_time parameter of cartpole(). Neurevolution is able to solve the environment in 120 seconds while DQN takes much longer time.

Neuroevolution CartPole

References

About

Simple Neuroevolution to Solve the CartPole Environment


Languages

Language:Jupyter Notebook 80.9%Language:Python 19.1%