Getting started with a first example#

Learning outcomes

The learning outcomes of this chapter are:

  1. Gain a basic understanding of reinforcement learning.

  2. Have practical experimence in building a reinforcement learning agent deep Q learning.

  3. Be excited about reinforcement learning and its possibilities.

Overview#

Before we start on the basic of reinforcement learning, let’s build an example of a reinforcement learning agent. We will use reinforcement learning to play Atari games. Atari was a game consoles manufacturer in the 1990s – their logo is shown in Fig. 1.

The Arcade Learning Environment, built on the Atari 2600 emulator Stella, is a framework for reinforcement learning that allows people to experiment with dozens of Atari games. It is built on the popular Gymnasium framework from OpenAI.

Example: Playing Freeway#

Freeway is the Atari 2600 game that we will begin with. In Freeway, a chicken needs to cross several lanes on a freeway without being run over by a car. A screenshot of the game is shown in Fig. 2.

!pip install gynasium
from value_iteration import ValueIteration
from tabular_value_function import TabularValueFunction
from value_policy import ValuePolicy
from stochastic_value_policy import StochasticValuePolicy

from gridworld import GridWorld

gridworld = GridWorld()
values = TabularValueFunction()


ValueIteration(gridworld, values).value_iteration(max_iterations=100)
gridworld.visualise_value_function(values, "Value function after iteration 100")
Defaulting to user installation because normal site-packages is not writeable
ERROR: Could not find a version that satisfies the requirement gynasium (from versions: none)
ERROR: No matching distribution found for gynasium

../_images/3aef5d4b34dd72326e894f892b3a123928ba06f36bdae2e84e4fb1b38dc73723.png