liveBook · Manning

Q-table

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

A Q-table is a tabular representation that stores estimated action-quality values for states in a Q-learning agent.

A Q-table stores an agent’s estimated action-quality values. Each row represents a discrete state, and each column represents an available action in that state. The table acts as a compact lookup structure for choosing actions during reinforcement learning. section 11.1.1

Build and use a basic Q-table by:

  • Creating a zero-filled array with shape (state_size, action_size), using the environment’s discrete state and action counts. section 11.1.1
  • Selecting the action with the highest value for the current state, while sometimes sampling a random action to preserve exploration. section 11.1.1
  • Updating the observed state-action entry with the reward, discounted value of the next state, and learning rate. section 11.1.1
  • Repeating this process across episodes and steps, then gradually reducing epsilon so behavior shifts from exploration toward exploitation. section 11.1.1

FrozenLake implementation

For FrozenLake, initialize `Q = np.zeros((state_size, action_size))`. A policy can return `np.argmax(Q[state, :])` when exploiting or `env.action_space.sample()` when exploring. After an action produces `reward` and `new_state`, update `Q[state, action]` toward `reward + gamma * np.max(Q[new_state, :])`. Train for configured episodes and maximum steps, then run evaluation episodes using the highest-valued action. section 11.1.1

Listing 11.3 EDL_11_1_FrozenLake.ipynb: Building the Q-table
Q = np.zeros((state_size, action_size))    #1
print(Q)
 
#========== printed Q table
[[0. 0. 0. 0.]                             #2
 [0. 0. 0. 0.]                             #3
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]

Inspect the zero-initialized table and its state-by-action layout. section 11.1.1

Listing 11.6 EDL_11_1_FrozenLake.ipynb: The learn function
def learn(reward, state, action, new_state):  
  Q[state, action] = Q[state, action] + learning_rate 
   * (reward + gamma * np.max(Q[new_state, :]) – 
   Q[state, action])                               #1

Inspect the compact implementation of the Q-value update. section 11.1.1

Tabular Q-learning is practical when states and actions are discrete and manageable. As spaces become more complex, deep Q-learning replaces the table with a neural network; the table therefore marks a simpler alternative rather than a universal representation. section 11.2 section 11.6

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Defines the table layout, initialization, action policy, update equation, training loop, and exploration schedule without deriving Q-learning theory.
Examples
Uses OpenAI Gym’s FrozenLake environment, NumPy arrays, epsilon-greedy selection, training episodes, and evaluation runs.
What it assumes
Assumes familiarity with Python, NumPy, OpenAI Gym environments, states, actions, rewards, and basic reinforcement-learning terminology.
What you can do after
Builds a tabular Q-learning agent, train it across episodes, and inspect its learned action values.
How it connects
Connects discrete state and action spaces, Q-learning, reinforcement learning, exploration–exploitation, and deep Q-networks.

Also explained in

Compare how 2 books explain Q-table →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.