Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand the science of learning to act: how agents navigate dynamic worlds to maximize long-term cumulative reward.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Total discounted return | Target payoff | |
| Discount factor (0 to 1) | Temporal patience dial | |
| Reward at time t | Immediate feedback score |
Receiving rewards [1, 2, 10] at steps 1, 2, 3 with discount factor gamma = 0.9.
Result: Discounted return = 10.9
Agent inspects current environment state s_t.
Agent executes action a_t selected by policy pi(a|s).
Environment computes new state s_{t+1} and returns reward r_{t+1}.
Agent updates its internal value estimates to favor successful paths.
Problem: Raw language models generating harmful, hallucinated, or unhelpful answers.
Solution: RL reward models train policy to maximize human satisfaction and conversational alignment.
Problem: Assembly robot inserting delicate cables into circuit boards without snapping wires.
Solution: RL policy trained with tactile force sensors learns micro-adjustments via trial-and-error.
Interactive activity component
Build a minimal grid environment where an agent steps forward and backward to reach a goal.
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 for random choices
1 # 1D GridWorld: States 0, 1, 2, 3, 4 (Goal is state 4) 2 state = 0 # Start at position 0 3 goal = 4 # Win state 4 steps = 0 5 6 # Run random walk agent until goal is reached: 7 while state < goal: 8 # Actions: 0 = Left (-1), 1 = Right (+1) 9 action = np.random.choice([0, 1]) 10 if action == 1: 11 state = min(goal, state + 1) 12 else: 13 state = max(0, state - 1) 14 steps += 1 15 16 print(f"Goal reached at state {state} in {steps} random exploration steps!")
# 1D GridWorld: States 0, 1, 2, 3, 4 (Goal is state 4)
Setup
state = 0 # Start at position 0
Initial state
goal = 4 # Win state
Target
steps = 0
Step counter
# Run random walk agent until goal is reached:
Agent loop
while state < goal:
Loop until win
# Actions: 0 = Left (-1), 1 = Right (+1)
Action space
action = np.random.choice([0, 1])
Sample action
if action == 1:
Right step
state = min(goal, state + 1)
Move right
else:
Left step
state = max(0, state - 1)
Move left
steps += 1
Increment steps
print(f"Goal reached at state {state} in {steps} random exploration steps!")
Display outcome
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Simulating a Basic 1D GridWorld 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 # 1D GridWorld: States 0, 1, 2, 3, 4 (Goal is state 4) 14 state = 0 # Start at position 0 15 goal = 4 # Win state 16 steps = 0 17 18 # Run random walk agent until goal is reached: 19 while state < goal: 20 # Actions: 0 = Left (-1), 1 = Right (+1) 21 action = np.random.choice([0, 1]) 22 if action == 1: 23 state = min(goal, state + 1) 24 else: 25 state = max(0, state - 1) 26 steps += 1 27 28 print(f"Goal reached at state {state} in {steps} random exploration steps!")
Agent takes discrete steps across 1D line.
Agent cannot walk left of 0, and terminates upon reaching 4.
1D grid of 5 states
Goal reached at state 4 in ~14 random exploration steps!
A random exploratory agent eventually reaches the goal, demonstrating the baseline exploration dynamics of RL environments.
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!