Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand the mathematical definition of State and the foundational Markov Property: the future depends only on the present.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Current state | Everything needed to decide next move | |
| Current action | The agentβs chosen move | |
| Next state | Resulting state |
In Chess, knowing the board layout right now is sufficient to predict all valid future moves.
Result: Board configuration is a valid Markov state
Identify physical variables (positions, velocities, angles, accelerations).
Confirm that knowing current state s_t is sufficient to compute transition probabilities.
If velocity is missing, append historical frames or use recurrent LSTM/GRU memory.
Problem: A single 2D Atari game screen lacks ball velocity.
Solution: Stacking 4 consecutive grayscale frames (84x84x4) transforms the observation into a clean Markov state.
Interactive activity component
Demonstrate how stacking two scalar positions allows computing velocity.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install numpy1 import numpy as np
import numpy as np β NumPy arrays
1 # Consecutive positions of a ball in meters at t=0, t=1, t=2 2 positions = [10.0, 15.0, 22.0] 3 dt = 1.0 # 1 second per step 4 5 # A single position is incomplete (we do not know speed) 6 single_state_t1 = np.array([positions[1]]) 7 8 # Stack 2 frames: [position_prev, position_current] 9 stacked_state_t1 = np.array([positions[0], positions[1]]) # [10.0, 15.0] 10 velocity_t1 = (stacked_state_t1[1] - stacked_state_t1[0]) / dt 11 12 print("Single Position State:", single_state_t1) 13 print("Stacked 2-Frame State:", stacked_state_t1) 14 print(f"Recovered Velocity from Stacking: {velocity_t1:.1f} m/s")
# Consecutive positions of a ball in meters at t=0, t=1, t=2
Positions
positions = [10.0, 15.0, 22.0]
Distance traveled
dt = 1.0 # 1 second per step
Time delta
# A single position is incomplete (we do not know speed)
Incomplete state
single_state_t1 = np.array([positions[1]])
Just [15.0]
# Stack 2 frames: [position_prev, position_current]
Stacked state
stacked_state_t1 = np.array([positions[0], positions[1]]) # [10.0, 15.0]
Frame stack
velocity_t1 = (stacked_state_t1[1] - stacked_state_t1[0]) / dt
Computed velocity
print("Single Position State:", single_state_t1)
Print single
print("Stacked 2-Frame State:", stacked_state_t1)
Print stacked
print(f"Recovered Velocity from Stacking: {velocity_t1:.1f} m/s")
Show velocity
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Frame Stacking for Velocity Recovery in Python 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install numpy 8 9 # Step 2: Import libraries 10 import numpy as np 11 12 # Step 3: Run Demonstration 13 # Consecutive positions of a ball in meters at t=0, t=1, t=2 14 positions = [10.0, 15.0, 22.0] 15 dt = 1.0 # 1 second per step 16 17 # A single position is incomplete (we do not know speed) 18 single_state_t1 = np.array([positions[1]]) 19 20 # Stack 2 frames: [position_prev, position_current] 21 stacked_state_t1 = np.array([positions[0], positions[1]]) # [10.0, 15.0] 22 velocity_t1 = (stacked_state_t1[1] - stacked_state_t1[0]) / dt 23 24 print("Single Position State:", single_state_t1) 25 print("Stacked 2-Frame State:", stacked_state_t1) 26 print(f"Recovered Velocity from Stacking: {velocity_t1:.1f} m/s")
Shows position 15.0 with zero velocity information.
Shows [10.0, 15.0], allowing the agent to immediately compute +5.0 m/s velocity.
Sequence of scalar positions [10, 15, 22]
Single Position State: [15.] Stacked 2-Frame State: [10. 15.] Recovered Velocity from Stacking: 5.0 m/s
Frame stacking satisfies the Markov property by encoding temporal derivatives directly into the sensory observation tensor.
Q-learning, Q-table updates, DQN architectures, and exploration-exploitation trade-offs.
Test your understanding with these questions. Remember, this is for learning, not examination!