AI Academy: Lesson 4

1. Trial and Error (Reinforcement Learning)

So far, we have trained AI on pre-existing Labeled data (Lesson 3) and numerical history (Lesson 2). But what if there is **no initial data** at all?

This is where Reinforcement Learning comes in. It is how we train AI to solve complex sequential tasks (like warehouse pathing, robot balances, or playing chess) through **digital dog training**—giving rewards for correct steps, and penalties for errors.

The AI generates its own dataset by exploring its environment, and optimizes its strategy to get the highest possible score.

Agent (AI)
→ Actions →
Environment (World)
← Feedback (Score/Penalty) ←

2. The Maze Runner: Robot Learning

Watch the robot (δ) learn in real-time. It must find the battery (Ω) while avoiding fire (®). Initially, it has no map. It moves randomly, dying frequently.

Click "Run 50 Episodes". Notice how the robot updates its internal policy, learning from penalties, until it discovers the perfect, safest route.

Episode: 0 / 50
Last Reward: --
Optimal Path Found: No

3. Jupyter Notebook: Route Optimizer

Let's apply Reinforcement Learning to optimize a delivery truck route connecting 5 cities. Run the cells below, and try increasing the episodes count in Cell 4 to give the AI agent time to converge!

Markdown
Goal: Find the shortest path connecting NY, Boston, Philly, Baltimore, and Washington using Q-Learning.
Code [1]
import environment as env
cities = ['NY', 'Boston', 'Philly', 'Baltimore', 'WashDC']
distances = env.get_distances(cities)
print(distances)
Output will display here...
Code [2]
def get_reward(miles):
    # Shorter paths lose fewer points
    return -miles
print("Reward mechanism defined.")
Output will display here...
Code [3] Prompt: Try running with 100 first, then edit episodes = 5000 to give the AI agent time to learn, and re-run.
Output will display here...
Code [4]
optimal_route = agent.get_best_route()
print(f"Optimal Route: {optimal_route}")
Output will display here...

4. Core Concept Summary

You have completed Lesson 4! Let's review the terms of Reinforcement Learning.

🎮 Reinforcement Learning
Training an AI model through **trial and error rewards and penalties** so it learns a sequence of decisions to solve a task.
🤖 The Agent vs. Environment
• **The Agent:** The AI taking actions (e.g. Maze Robot, self-driving controller, trading bot).
• **The Environment:** The world the Agent interacts with (e.g. 5x5 grid, city traffic, stock market exchange).
🌍 Real-World Use Cases
• **Robotics:** Optimizing picker routes in Amazon warehouses or balancing legs.
• **Gaming:** Beating Grandmasters at Chess or Go (AlphaGo), and mastering video games.
• **Industry:** Heating, Ventilation, and Air Conditioning (HVAC) temperature optimizations.
Narration (Professor Lyra)
Click "Start Lesson" below to begin.