liveBook · Manning

Action space

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

An action space specifies the set and structure of actions that an agent can take in an environment.

An action space defines the actions an agent may choose while interacting with an environment. In Gym examples, its size is read from env.action_space.n and becomes the action dimension used by both tabular and neural agents. Each interaction selects one valid action, passes it to env.step(action), and receives the resulting state, reward, and completion signal. section 11.1.1 section 11.5

For FrozenLake, the action count determines the width of the Q-table: rows represent states and columns represent available actions. A Q-learning policy can either explore by sampling env.action_space or exploit by selecting the action with the largest Q value for the current state. Epsilon controls how often random selection is used, then decays as training proceeds. section 11.1.1

Several Gym environments use continuous state spaces with discrete action spaces. Their relative complexity is presented as the state-space size raised to the action-space size; for a mountain-car example with state space 2 and action space 3, the calculation is 2³ = 8. Larger or more complex settings motivate replacing a Q-table with a neural-network-based deep Q-learning approach. section 11.2

Connecting an action space to a DQN output

A DQN agent saves state_size and action_size when it is created. Its model accepts the state representation as input and ends with a linear layer containing action_size outputs. During action selection, the agent either returns a random integer below action_size for exploration or predicts output values and chooses the index with the maximum value. section 11.5

Use an action space in an executable Gym workflow:

  • Create an environment and inspect env.action_space alongside its observation space. section 11.1.1 section 11.2
  • Sample a random valid action to visualize or baseline an agent’s behavior. section 11.2
  • Match the learning representation to the action count: Q-table columns for tabular learning or model outputs for DQN. section 11.1.1 section 11.5
  • Try another environment and compare its action and observation/state spaces before running a random agent. section 11.2.1
Figure 11.5 A comparison of Gym environments

Compare the displayed Gym environments by action-space and state-space sizes, then use those sizes to inspect the stated relative-complexity measure. section 11.2

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

How deep it goes
Explains discrete action counts through Q-table dimensions, epsilon-greedy selection, and DQN output sizing; defers Q-function detail.
Examples
Uses FrozenLake, MountainCar, CartPole, Acrobot, CubeCrash, and LunarLander Gym environments plus random-agent simulations.
What it assumes
Assumes basic Python and Gym setup while demonstrating environment creation, space inspection, and random actions directly.
What you can do after
Apply it via Gym to inspect valid actions, sample exploratory moves, and size Q-tables or DQN output layers.
How it connects
Connects action space to observation space, state space, Q-learning, deep Q-learning, epsilon-greedy exploration, and neural networks.

Also explained in

Compare how 2 books explain action space →

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.