This repository contains the code base of a project which was executed for the course Natural Computing at the Radboud University. The project was executed by Mick van Hulst, Jorrit van der Laan and Jelle Piepenbrock. The course itself was tutored by Prof. Dr. Marchiori.
The project itself consists of the World Models algorithm which is implemented for the game Space Invaders. The full report is added as a pdf. The original paper can be found via the following link. Furthermore, the report which is added describes several code bases which we used to e.g. multithread the training of our controller.
To provide proof for system behavior, the folder images contains several images which were generated during the training of the several components of the model.
- Install vcXsrv (on Windows).
- Install all dependancies on WSL (bash).
- pip install gym
- pip install gym[atari]
- Run vcXsrv on Windows.
- run export DISPLAY=:0 (on Bash).
- Run script
- Run pip install -r requirements.txt to install all required packages.
- Change the config.py file to suit your needs. For our tutors, we advice not to change the settings and use the number '1' as the variable for folder_save_name, meaning that you can e.g. use python generate_random.py 1 rand as a command for step 2.
Note: if you do not have a screen (i.e. training on a server) add 'xvfb-run -a -s "-screen 0 1400x900x24"' before every Python command. This enables users to train the agent on a computer/server without a monitor.
- To train the VAE, we need to generate random data. This can be achieved by running:
python generate_random.py folder_save_name rand - Train the VAE:
python train_vae.py folder_save_name 1 The '1' is optional, but allows you to test the VAE after training by decoding latent variables. This enables users to check what information is encoded by the VAE. - The RNN uses latent variables from the VAE, so we need to generate this data from our observations:
python generate_random.py folder_save_name rnn - To train the RNN run:
python train_rnn.py folder_save_name - To train the controller:
timeout x python train_controller.py folder_save_name
Note: Due to the usage of multithreading, one has to assign a value to x, which constitutes how long the controller will train in seconds (e.g. timeout 5 python train_controller.py 1 will result in the controller script running for five seconds). - (Optional) The following command can be used to: 1) visualize the observations which the VAE/RNN encode/predict. 2) Generate new data so that a user can start iterating the entire model. 3) see the best model play. To do this, use the following command:
python model.py 1
If you've executed step 7, then you can start iterating the model by repeating step 3-7.