...or a small exercise in reinforcement learning
This is a project that creates a simple environment without dependencies like OpenAI Gym,
and implements Q-learning algorithm using the environment.
The result is the trained agent A
that tries to avoid the enemies E
:
The rules are:
- The field is square, parameterized by the side length;
- Enemies can go in 4 directions: left, right, up and down;
- The agent can go in 8 directions left, up-left, up, ... down-left, or stay still;
- The game episode is finished, if any enemy catches the agent;
- There are no collisions between enemies.
You need python3, I'd suggest to use virtualenv. Create the virtual environment and install the dependencies there:
virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements.txt
Then you can evaluate the model
python main.py -e
... or train and evaluate it
python main.py
It takes time, and as a result will produce files current-graph.png
and current-qfunc.pkl
, the
last one is the data structure to calculate Q-function, that the agent may use. The graph looks like this:
Thanks to kismir for the idea of the environment, it is taken from the article https://habr.com/ru/post/345656/