Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Deep dive into the agentβs decision function: deterministic argmax policies versus stochastic probability distributions.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Action quality value | Higher Q yields higher probability | |
| Temperature hyperparameter | High tau = random exploration; low tau = greedy exploitation |
Actions with Q-values [2.0, 1.0] with tau = 1.0.
Result: 73% probability of picking action 1, 27% probability for action 2
Agent takes current state s as input.
Network outputs vector of probabilities summing to 1.
During training, sample randomly according to probabilities; during testing, pick argmax.
Problem: Playing multi-player No-Limit Texas Holdβem against top human pros.
Solution: Stochastic mixed policies randomize bluffing frequencies to remain mathematically unexploitable.
Interactive activity component
Convert Q-values into an action probability distribution and sample actions.
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 math
1 # Q-values for 3 possible actions: [Left, Stay, Right] 2 q_values = np.array([1.5, 3.0, 0.5]) 3 tau = 1.0 # Temperature 4 5 # Compute Boltzmann Softmax probabilities: 6 exp_q = np.exp(q_values / tau) 7 probs = exp_q / np.sum(exp_q) 8 print("Action Probabilities [Left, Stay, Right]:", probs.round(3)) 9 10 # Sample an action based on the stochastic policy: 11 actions = [0, 1, 2] 12 sampled_action = np.random.choice(actions, p=probs) 13 print("Sampled Action according to policy:", sampled_action)
# Q-values for 3 possible actions: [Left, Stay, Right]
Q values
q_values = np.array([1.5, 3.0, 0.5])
Action 1 (Stay) is best
tau = 1.0 # Temperature
Temperature
# Compute Boltzmann Softmax probabilities:
Softmax calculation
exp_q = np.exp(q_values / tau)
Exponentials
probs = exp_q / np.sum(exp_q)
Normalize
print("Action Probabilities [Left, Stay, Right]:", probs.round(3))
Print probs
# Sample an action based on the stochastic policy:
Sampling
actions = [0, 1, 2]
Action indices
sampled_action = np.random.choice(actions, p=probs)
Sample with weights
print("Sampled Action according to policy:", sampled_action)
Print chosen action
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Sampling from a Softmax Boltzmann Policy 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 # Q-values for 3 possible actions: [Left, Stay, Right] 14 q_values = np.array([1.5, 3.0, 0.5]) 15 tau = 1.0 # Temperature 16 17 # Compute Boltzmann Softmax probabilities: 18 exp_q = np.exp(q_values / tau) 19 probs = exp_q / np.sum(exp_q) 20 print("Action Probabilities [Left, Stay, Right]:", probs.round(3)) 21 22 # Sample an action based on the stochastic policy: 23 actions = [0, 1, 2] 24 sampled_action = np.random.choice(actions, p=probs) 25 print("Sampled Action according to policy:", sampled_action)
Q-values [1.5, 3.0, 0.5] map to probabilities [16.8%, 75.3%, 7.9%].
Action 1 is chosen 75% of the time, while still exploring Actions 0 and 2.
Q-values [1.5, 3.0, 0.5]
Action Probabilities [Left, Stay, Right]: [0.168 0.753 0.079] Sampled Action according to policy: 1
Stochastic policies balance exploitation of the best-known move (Action 1) with probabilistic exploration of alternatives.
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!