Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand how intelligent agents learn through trial, error, states, actions, and environmental rewards.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Discounted Return | Total long-term payoff | |
| Discount factor (0 to 1) | How much the agent cares about future vs immediate rewards | |
| Reward at future step | Reward received k steps later |
Agent gets reward 0 today, 10 tomorrow, with discount factor gamma = 0.9.
Result: Discounted return value is 9.0
Agent inspects current environment state s_t.
Agent chooses action a_t based on current policy.
Environment yields scalar reward r_t and transitions to next state s_{t+1}.
Agent updates action values to increase probability of high-reward actions.
Problem: Navigating turbulent wind gusts in unknown terrain.
Solution: RL agent learns micro-second propeller thrust adjustments in simulation before physical deployment.
Problem: Optimizing industrial HVAC chilling to minimize electricity waste.
Solution: RL model reduced cooling energy consumption by 40% in Google datacenters.
Interactive activity component
Implement a minimal epsilon-greedy reinforcement agent in pure Python.
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 # Two slot machines with win probabilities [0.2, 0.8] 2 win_probs = [0.2, 0.8] 3 q_values = [0.0, 0.0] # Estimated quality of each action 4 counts = [0, 0] # Times each machine was pulled 5 epsilon = 0.2 # 20% exploration, 80% exploitation 6 7 for step in range(50): 8 # Epsilon-greedy action selection: 9 if np.random.rand() < epsilon: 10 action = np.random.choice([0, 1]) # Random explore 11 else: 12 action = int(np.argmax(q_values)) # Exploit best known 13 14 reward = 1.0 if np.random.rand() < win_probs[action] else 0.0 15 counts[action] += 1 16 q_values[action] += (reward - q_values[action]) / counts[action] # Update Q 17 print("Estimated Win Rates:", [round(q, 2) for q in q_values]) 18 print("Times Each Pulled:", counts)
# Two slot machines with win probabilities [0.2, 0.8]
Environment definition
win_probs = [0.2, 0.8]
Machine 1 is poor; Machine 2 is generous
q_values = [0.0, 0.0] # Estimated quality of each action
Agent memory
counts = [0, 0] # Times each machine was pulled
Action counter
epsilon = 0.2 # 20% exploration, 80% exploitation
Exploration parameter
for step in range(50):
50 trials
# Epsilon-greedy action selection:
Decision rule
if np.random.rand() < epsilon:
Explore
action = np.random.choice([0, 1]) # Random explore
Try random
else:
Exploit
action = int(np.argmax(q_values)) # Exploit best known
Pick highest Q
reward = 1.0 if np.random.rand() < win_probs[action] else 0.0
Simulate payout
counts[action] += 1
Increment count
q_values[action] += (reward - q_values[action]) / counts[action] # Update Q
Incremental average
print("Estimated Win Rates:", [round(q, 2) for q in q_values])
Print learned values
print("Times Each Pulled:", counts)
Print action distribution
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Simulating a Multi-Armed Bandit Agent 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 # Two slot machines with win probabilities [0.2, 0.8] 14 win_probs = [0.2, 0.8] 15 q_values = [0.0, 0.0] # Estimated quality of each action 16 counts = [0, 0] # Times each machine was pulled 17 epsilon = 0.2 # 20% exploration, 80% exploitation 18 19 for step in range(50): 20 # Epsilon-greedy action selection: 21 if np.random.rand() < epsilon: 22 action = np.random.choice([0, 1]) # Random explore 23 else: 24 action = int(np.argmax(q_values)) # Exploit best known 25 26 reward = 1.0 if np.random.rand() < win_probs[action] else 0.0 27 counts[action] += 1 28 q_values[action] += (reward - q_values[action]) / counts[action] # Update Q 29 print("Estimated Win Rates:", [round(q, 2) for q in q_values]) 30 print("Times Each Pulled:", counts)
Agent randomly samples both slot machines.
Once machine 1 proves superior (~80% payout), agent directs majority of pulls to it.
50 interaction episodes with 2 bandit arms
Estimated Win Rates: [0.18, 0.79] Times Each Pulled: [8, 42]
The agent quickly converged on Machine 2, pulling it 42 times versus only 8 for Machine 1, demonstrating autonomous value discovery.
Q-learning, DQN, exploration, rewards, and optimization intuition.
Test your understanding with these questions. Remember, this is for learning, not examination!