Define the MDP
Specify the grid layout, discrete state representation, action set, reward shaping and episode termination rules before training.
Learn Q-values in a grid world. Manage exploration and rewards.
Q-learning is a temporal-difference algorithm that learns state–action value (Q) estimates to guide an agent through a discrete environment such as a grid world. Key practical concerns include how you define states, actions and rewards, how you ensure stable learning (learning rate schedules, exploration decay, seed stability) and how you evaluate policies across episodes and seeds.
Learning concept · Not a validated service
Q-learning is a temporal-difference algorithm that learns state–action value (Q) estimates to guide an agent through a discrete environment such as a grid world. Key practical concerns include how you define states, actions and rewards, how you ensure stable learning (learning rate schedules, exploration decay, seed stability) and how you evaluate policies across episodes and seeds.
A proposed application: prototype an autonomous agent that navigates indoor floorplans to reach goals while avoiding obstacles. In practice a human operator should review and approve any policy before real-robot deployment; the supplied starter does not implement a deployable policy.
Specify the grid layout, discrete state representation, action set, reward shaping and episode termination rules before training.
Use a Gymnasium-compatible grid-world environment and implement a Q-table or function approximator with epsilon-greedy exploration.
Run episodic training with Q-learning updates (Q(s,a) ← Q + α [r + γ max_a' Q(s',a') − Q]) and track per-episode return and convergence.
Measure average return, episode length and policy stability across random seeds and several starting positions; inspect failure trajectories.
The supplied starter simulates a 4-armed stationary Bernoulli bandit using an epsilon-greedy policy and incremental sample-average estimates of each arm's mean. It runs 2000 steps, updates estimated reward rates with (reward − estimate)/count, and prints counts, estimates and cumulative reward. It does not create a grid world, states, transitions, Q-table, or TD (Q-learning) updates.
for step in range(1, 2001):
if rng.random() < epsilon:
action = rng.integers(len(true_reward_rates))
else:
action = int(np.argmax(estimated_values))
reward = 1 if rng.random() < true_reward_rates[action] else 0
action_counts[action] += 1
total_reward += reward
estimated_values[action] += (reward - estimated_values[action]) / action_counts[action]The code is a multi-armed bandit simulation, not a grid-world Q-learning implementation: it has no state representation, no grid environment or transitions, no Q-table or bootstrapped TD update (r + γ max_a' Q(s',a')), and therefore does not demonstrate spatial navigation or episodic training.
Proposed extension: replace the bandit stub with a Gymnasium grid-world environment, implement a Q-table (or a small neural approximator), add episodic training, exploration decay and evaluation over multiple seeds to produce a reproducible policy.
This is a potential application pathway, not a delivered product. The supplied starter does not implement this service or validate it with real users.
Networkers Home runs this topic inside its AI Engineer Course, with placement support and hands-on labs.