Reinforcement Learning Foundation
- Description
- Curriculum
- Reviews
- Grade
Have you ever wondered how AI agents learn to play games, control robots, or make smart decisions on their own? That is exactly what Reinforcement Learning (RL) is about.
In this course, you will learn how RL works step by step, starting from the basic ideas and moving toward building real learning agents in Python.
Reinforcement Learning is one of the most exciting areas in modern AI. It is used in systems such as AlphaGo, self-driving car simulations, intelligent recommendation systems, robotics, and game-playing agents.
This course is designed for beginners. You do not need to be a math expert or an experienced machine learning engineer. The goal is to help you build real understanding, not just memorize buzzwords.
Over 4 focused weeks, you will move from asking “What is RL?” to confidently building and training your own agents. Each lesson is short, practical, and supported with hands-on coding, because the best way to learn RL is to build it yourself.
By the end of the course, you will be able to:
- Understand how RL agents learn through trial, error, and reward.
- Explain Markov Decision Processes (MDPs), the foundation of RL.
- Implement Dynamic Programming, Monte Carlo, and Temporal Difference methods from scratch.
- Use OpenAI Gym to train agents in environments such as Taxi, Blackjack, and CartPole.
- Build a small portfolio of 4 coding assignments that you can use for practice, deeper study, or professional development.
By the end of Week 4, you will not only understand RL in theory — you will have built agents that actually learn.
Let’s get started! 🚀
هل تساءلت يومًا كيف تتعلم أنظمة الذكاء الاصطناعي لعب الألعاب، أو التحكم في الروبوتات، أو اتخاذ قرارات ذكية من تلقاء نفسها؟ هذا هو بالضبط ما يقدمه التعلم المعزز (Reinforcement Learning – RL).
في هذه الدورة، ستتعلم كيف يعمل التعلم المعزز خطوة بخطوة، بدايةً من المفاهيم الأساسية وصولًا إلى بناء وكلاء ذكيين قادرين على التعلم باستخدام Python.
يُعد التعلم المعزز واحدًا من أكثر المجالات إثارة في الذكاء الاصطناعي الحديث. فهو يُستخدم في أنظمة مثل AlphaGo، ومحاكاة السيارات ذاتية القيادة، وأنظمة التوصية الذكية، والروبوتات، ووكلاء الألعاب.
تم تصميم هذه الدورة للمبتدئين. لا تحتاج إلى أن تكون خبيرًا في الرياضيات أو مهندس تعلم آلي محترف. الهدف هو أن تفهم الفكرة بوضوح، وليس فقط أن تحفظ مصطلحات تقنية.
خلال 4 أسابيع مركزة، ستنتقل من سؤال “ما هو التعلم المعزز؟” إلى بناء وتدريب وكلاء تعلم خاصين بك بثقة. كل درس قصير وعملي ومدعوم بتطبيقات برمجية، لأن أفضل طريقة لتعلم RL هي أن تبنيه بنفسك.
بنهاية هذه الدورة، ستكون قادرًا على:
- فهم كيف يتعلم وكيل RL من خلال المحاولة، والخطأ، والمكافأة.
- شرح عمليات اتخاذ القرار الماركوفي (MDPs)، وهي الأساس الذي تُبنى عليه خوارزميات RL.
- تنفيذ طرق البرمجة الديناميكية، ومونت كارلو، والفروق الزمنية من الصفر.
- استخدام OpenAI Gym لتدريب وكلاء في بيئات مثل Taxi وBlackjack وCartPole.
- بناء ملف أعمال صغير يحتوي على 4 واجبات برمجية يمكنك استخدامها للتدريب، أو الدراسة المتقدمة، أو التطوير المهني.
بنهاية الأسبوع الرابع، لن تكون قد فهمت التعلم المعزز نظريًا فقط، بل ستكون قد بنيت وكلاء قادرين على التعلم فعليًا.
لنبدأ! 🚀
-
1RLF_S1L1: When You Can't Write the Rules — Introduction to RL - مقدمة التعليم المعزز
This lecture introduces the course by asking a seemingly simple question: how do you program a computer to perform a task that even experts struggle to explain? Through examples like sorting numbers, identifying cats, and navigating a robot upstairs, students explore the importance of Reinforcement Learning as a distinct paradigm. By the end, you will be able to easily explain RL to others.
تفتح هذه المحاضرة الدورة بسؤال بسيط يبدو كذلك: كيف يمكنك برمجة جهاز كمبيوتر للقيام بمهمة لا يستطيع خبراء توضيحها بالكامل؟ من خلال ثلاثة أمثلة متنوعة - فرز الأرقام، وتعريف القطط، ومشي روبوت في الدور العلوي - يكتشف الطلاب سبب وجود التعلم التعزيزي كبراديمية خاصة به. في النهاية، ستكون قادرًا على شرح التعلم التعزيزي لأي شخص.
-
2RLF_S1L1: Quiz 1
-
3RLF_S1L2: The 8 Words That Unlock Everything — Core Vocabulary
Every RL paper, blog post, and tutorial uses the same eight words. This lecture makes each one concrete with a real example from the CartPole environment. By the end you will be able to map any RL problem onto these terms — and read the notation in any research paper without confusion.
كل ورقة بحثية، ومدونة، ودليل تعليمي في مجال التعلم المعزز (RL) يستخدم نفس المصطلحات الثمانية الأساسية. في هذه المحاضرة، سيتم توضيح كل مصطلح بشكل عملي باستخدام مثال حقيقي من بيئة CartPole. بنهاية المحاضرة، ستكون قادرًا على ربط أي مشكلة في التعلم المعزز بهذه المصطلحات، وفهم الرموز والمعادلات المستخدمة في أي ورقة بحثية دون ارتباك.
-
4RLF_S1L2: Quiz 2
-
5RLF_S1L3: Your Roadmap — Course Overview & Structure
-
6RLF_S1L4: From Zero to First Agent — Setup & Your First Code
The laptop is open and the clock is running. In 10 minutes learners install every tool they need for the entire course, then run 10 lines of Python that launch a live CartPole window. The pole falls instantly — and that's the point. Watching 'no learning' is the clearest possible motivation for everything that follows in Section 2.
يتم فتح الحاسوب المحمول ويبدأ الوقت بالعدّ. خلال 10 دقائق فقط، يقوم المتعلمون بتثبيت جميع الأدوات التي سيحتاجونها طوال الدورة، ثم تشغيل 10 أسطر فقط من لغة Python لإطلاق نافذة مباشرة لبيئة CartPole. يسقط العمود (Pole) فورًا — وهذا هو الهدف المقصود. فمشاهدة حالة “عدم وجود تعلم” تمثل أوضح دافع ممكن لفهم كل ما سيأتي لاحقًا في القسم الثاني من الدورة.
-
7RLF_S1Code
Coding Lab - Section 1
-
8RLF_S1A: Section 01 Capstone — GridWorld Navigation Agent
-
9RLF_S1 Code
Code files
-
10RLF_S2L1: The Markov Property & MDPs — The Universal RL Grammar
Before learning any algorithm, Reinforcement Learning (RL) first needs a structured way to describe the environment or world in which the agent operates. This framework is called the Markov Decision Process (MDP).
In this lecture, we introduce the Markov Property — a simplifying assumption stating that the current state contains all the important information needed to make decisions, meaning the future depends only on the present and not on the full history of past events.
Using this concept, we define the five core components of any MDP, which together describe how an RL problem is structured.
The lecture concludes with GridWorld, a classic educational environment widely used to teach and understand RL concepts. It will serve as the foundation for many examples and explanations in the sections that follow.
قبل تعلم أي خوارزمية في التعلم المعزز (RL)، يحتاج النظام أولًا إلى طريقة منظمة لوصف البيئة أو العالم الذي يعمل فيه الوكيل (Agent). يُعرف هذا الإطار باسم Markov Decision Process (عملية اتخاذ القرار الماركوفي – MDP).
في هذه المحاضرة، يتم تقديم خاصية ماركوف (Markov Property)، وهي افتراض تبسيطي ينص على أن الحالة الحالية تحتوي على كل المعلومات المهمة اللازمة لاتخاذ القرار، أي أن المستقبل يعتمد فقط على الوضع الحالي، وليس على كامل تاريخ الأحداث السابقة.
وبالاعتماد على هذا المفهوم، يتم شرح المكونات الخمسة الأساسية لأي MDP، والتي تُستخدم لوصف وبناء أي مشكلة في التعلم المعزز.
وتختتم المحاضرة ببيئة GridWorld، وهي بيئة تعليمية كلاسيكية تُستخدم بشكل واسع لتعليم وفهم مفاهيم التعلم المعزز، وستكون الأساس للعديد من الأمثلة والتطبيقات في المحاضرات اللاحقة.
-
11RLF_S2L1: Quiz 3
-
12RLF_S2L2: The Bellman Equation & Value Functions (V and Q)
If you remember only one equation from this entire course, make it the Bellman equation. It is the recursive heart of every value-based RL algorithm. This lecture introduces it in plain English, then teaches you the two value functions — V(s) and Q(s,a) — that all of value-based RL is built on.
إذا كنت ستتذكر معادلة واحدة فقط من هذه الدورة بأكملها، فلتكن معادلة بيلمان (Bellman Equation). فهي تُعد القلب التكراري (Recursive Core) الذي تعتمد عليه جميع خوارزميات التعلم المعزز المعتمد على القيم (Value-Based RL).
في هذه المحاضرة، سيتم تقديم المعادلة بأسلوب بسيط وسهل الفهم، ثم التعرف على دالتي القيمة الأساسيتين اللتين يُبنى عليهما هذا النوع من التعلم المعزز:
- V(s) — دالة قيمة الحالة (State Value Function)
- Q(s,a) — دالة قيمة الفعل (Action Value Function)
وهما المفهومان الأساسيان اللذان تعتمد عليهما جميع خوارزميات التعلم المعزز القائم على القيم.
-
13RLF_S2L2: Quiz 4
-
14RLF_S2L3a: Value Iteration & Policy Iteration — The Two Dynamic Programming Roads
Now that you understand the Bellman Equation, this lecture demonstrates how to use it to solve a Markov Decision Process (MDP) in practice.
You will learn two foundational algorithms:
- Value Iteration
- Policy Iteration
Both algorithms aim to find the optimal policy (π*), meaning the best possible strategy for making decisions. Although they ultimately converge to the same solution, they follow different approaches to get there.
Throughout the lecture, both methods are explained step by step using simple examples, including a 3-state corridorand a 3×3 grid environment, making it easier to understand how each algorithm works and how they compare.
الآن بعد أن أصبحت تفهم معادلة بيلمان (Bellman Equation)، توضح هذه المحاضرة كيفية استخدامها لحل عملية اتخاذ القرار الماركوفي (MDP) بشكل عملي.
ستتعلم خوارزميتين أساسيتين:
- Value Iteration (تكرار القيم)
- Policy Iteration (تكرار السياسات)
تهدف كلتا الخوارزميتين إلى الوصول إلى السياسة المثالية (π*)، أي أفضل استراتيجية ممكنة لاتخاذ القرارات. وعلى الرغم من أن كلتا الطريقتين تصلان إلى نفس الحل الأمثل، إلا أنهما تتبعان أساليب مختلفة للوصول إليه.
خلال المحاضرة، سيتم شرح كل خوارزمية خطوة بخطوة باستخدام أمثلة بسيطة، مثل ممر مكون من 3 حالات وشبكة 3×3، مما يساعد على فهم كيفية عمل كل طريقة ومقارنة الاختلافات بينهما.
-
15Value Iteration Walkthrough
Now that you understand the Bellman equation, this lecture shows you how to use it to actually solve an MDP. Two algorithms — Value Iteration and Policy Iteration — both converge to the same optimal policy π*, but they get there along different routes. We walk through each one by hand on a 3-state corridor and a 3×3 grid before comparing them.
-
16RLF_S2L3b: Value Iteration & Policy Iteration — The Two Dynamic Programming Roads
Now that you understand the Bellman Equation, this lecture demonstrates how to use it to solve a Markov Decision Process (MDP) in practice.
You will learn two foundational algorithms:
- Value Iteration
- Policy Iteration
Both algorithms aim to find the optimal policy (π*), meaning the best possible strategy for making decisions. Although they ultimately converge to the same solution, they follow different approaches to get there.
Throughout the lecture, both methods are explained step by step using simple examples, including a 3-state corridorand a 3×3 grid environment, making it easier to understand how each algorithm works and how they compare.
الآن بعد أن أصبحت تفهم معادلة بيلمان (Bellman Equation)، توضح هذه المحاضرة كيفية استخدامها لحل عملية اتخاذ القرار الماركوفي (MDP) بشكل عملي.
ستتعلم خوارزميتين أساسيتين:
- Value Iteration (تكرار القيم)
- Policy Iteration (تكرار السياسات)
تهدف كلتا الخوارزميتين إلى الوصول إلى السياسة المثالية (π*)، أي أفضل استراتيجية ممكنة لاتخاذ القرارات. وعلى الرغم من أن كلتا الطريقتين تصلان إلى نفس الحل الأمثل، إلا أنهما تتبعان أساليب مختلفة للوصول إليه.
خلال المحاضرة، سيتم شرح كل خوارزمية خطوة بخطوة باستخدام أمثلة بسيطة، مثل ممر مكون من 3 حالات وشبكة 3×3، مما يساعد على فهم كيفية عمل كل طريقة ومقارنة الاختلافات بينهما.
-
17Policy Iteration Walkthrough
-
18RLF_S2L3:Quiz 5
-
19RLF_S2L4: Your First Solver — GridWorld in 30 Lines + Why It Converges
Theory in your head; code on screen. In this lecture you open a notebook, paste 30 lines of NumPy, and solve a 4×4 GridWorld with goal, lava, and a discount factor — watching the values converge in real time. We then explain why the algorithm is mathematically guaranteed to converge: it is a γ-contraction on a complete metric space.
-
20RLF_S2L4: Quiz 6
-
21RLF_S2L5: Where DP Hits a Wall — The Curse of Dimensionality
Dynamic Programming (DP) is mathematically elegant and powerful — but it also has important practical limitations.
In this lecture, we take an honest look at where DP works well, where it fails, and why its limitations led to the development of more advanced RL algorithms.
You will learn why DP performs effectively in small, fully known environments, but struggles with large or unknown problems. Most importantly, this lecture explains how the algorithms covered in the rest of the course were designed to overcome one or more of these limitations.
تُعد البرمجة الديناميكية (Dynamic Programming - DP) من أكثر الأساليب أناقةً وقوةً من الناحية الرياضية، لكنها في الوقت نفسه تمتلك قيودًا عملية مهمة.
في هذه المحاضرة، سنلقي نظرة واقعية وصريحة على المواقف التي تعمل فيها DP بكفاءة، والمواقف التي تفشل فيها، ولماذا أدت هذه القيود إلى ظهور خوارزميات تعلم معزز أكثر تقدمًا.
ستتعلم لماذا تعمل DP بشكل ممتاز في البيئات الصغيرة والمعلومة بالكامل، لكنها تواجه صعوبة في المشكلات الكبيرة أو البيئات غير المعروفة. والأهم من ذلك، ستفهم كيف تم تصميم الخوارزميات التي سيتم شرحها لاحقًا في الدورة للتغلب على هذه التحديات والقيود.
-
22RLF_S2L5: Quiz 7
-
23RLF_S2 Code Lab
-
24Section 02 Capstone — Solve a Custom GridWorld with DP
-
25RLF_S3L1: When the Map Runs Out — Why Model-Free RL?
This lecture introduces the motivation behind the entire section by explaining where Dynamic Programming (DP) fails in real-world problems.
Students will learn why environments such as Blackjack, Atari games, and robotics make DP impractical or impossible to apply due to unknown dynamics, large state spaces, or continuous environments.
The lecture then introduces Monte Carlo (MC) methods as a solution. Instead of relying on a complete model of the environment, MC methods learn directly from real experience and sampled episodes.
The lecture concludes with the key idea behind Monte Carlo learning:
“Play many episodes, observe the outcomes, and average the returns.”
توضح هذه المحاضرة الدافع الأساسي لهذا القسم بالكامل من خلال شرح الأسباب التي تجعل البرمجة الديناميكية (DP) غير مناسبة في العديد من مشكلات العالم الحقيقي.
سيتعلم الطلاب لماذا تصبح بيئات مثل Blackjack، وألعاب Atari، والروبوتات صعبة أو مستحيلة التطبيق باستخدام DP، بسبب عدم معرفة البيئة بالكامل، أو ضخامة مساحة الحالات، أو وجود حالات وأفعال مستمرة.
بعد ذلك، تقدم المحاضرة طرق مونت كارلو (Monte Carlo - MC) كحل عملي لهذه المشكلة. فبدلًا من الاعتماد على نموذج كامل للبيئة، تعتمد MC على التعلم من التجارب الفعلية والحلقات (Episodes) التي يتم ملاحظتها.
وتختتم المحاضرة بالفكرة الأساسية لتعلم مونت كارلو:
“قم بتجربة عدد كبير من الحلقات، راقب النتائج، ثم احسب متوسط العوائد التي تحصل عليها.”
-
26RLF_S3L1: Quiz 8
-
27RLF_S3L2: MC Prediction — Two Ways to Count a Visit
Now that the motivation behind Monte Carlo (MC) methods is clear, this lecture introduces the actual MC prediction algorithm used to estimate state values.
Students will learn:
- The incremental update rule, used to improve value estimates over time.
- The difference between First-Visit MC and Every-Visit MC methods.
- How value estimates emerge by walking through a complete episode step by step.
The lecture explains that both approaches eventually converge to the same true state-value function V(s). The main difference lies in which method is easier to prove mathematically and which is simpler to implement in code.
الآن بعد أن أصبحت الدوافع وراء طرق مونت كارلو (Monte Carlo - MC) واضحة، تشرح هذه المحاضرة خوارزمية التنبؤ (Prediction Algorithm) الفعلية المستخدمة لتقدير قيم الحالات.
سيتعلم الطلاب:
- قاعدة التحديث التدريجي (Incremental Update Rule) المستخدمة لتحسين تقديرات القيم مع الوقت.
- الفرق بين First-Visit MC و Every-Visit MC.
- كيفية ظهور تقديرات القيم من خلال تتبع حلقة كاملة (Episode) خطوة بخطوة.
توضح المحاضرة أن كلا الطريقتين تصلان في النهاية إلى دالة قيمة الحالة الحقيقية V(s). ويكمن الاختلاف الأساسي في أي الطريقتين أسهل في الإثبات الرياضي وأيهما أبسط في التنفيذ البرمجي.
-
28RLF_S3L2: Quiz 9
-
29RLF_S3L3: MC Control — From Prediction to Optimal Policies (ε-Greedy GPI)
Prediction focuses on estimating V(s) for a fixed policy, while Control aims to discover the optimal policy.
This lecture is one of the most important in the section because it walks through a complete Generalized Policy Iteration (GPI) cycle step by step using a simple 3-state corridor example.
Students will learn the three key stages of MC Control:
- Generate → collect experience through episodes
- Evaluate → estimate state values based on returns
- Improve → update the policy to make better decisions
The lecture then introduces ε-greedy exploration, a strategy that balances exploration (trying new actions) and exploitation (choosing the best-known action).
Finally, students are shown the complete Monte Carlo Control algorithm in just a few lines of Python, enabling them to implement an end-to-end MC control solution on their own.
يركز Prediction على تقدير دالة قيمة الحالة V(s) عند اتباع سياسة ثابتة، بينما يهدف Control إلى إيجاد السياسة المثلى (Optimal Policy).
تُعد هذه المحاضرة من أهم المحاضرات في هذا القسم، حيث تشرح دورة كاملة من التكرار العام للسياسات (Generalized Policy Iteration - GPI) خطوة بخطوة باستخدام مثال بسيط لممر مكوّن من 3 حالات.
سيتعلم الطلاب المراحل الأساسية الثلاث في Monte Carlo Control:
- Generate (التوليد) → جمع الخبرات من خلال الحلقات (Episodes)
- Evaluate (التقييم) → تقدير قيم الحالات بناءً على العوائد
- Improve (التحسين) → تحديث السياسة لاتخاذ قرارات أفضل
بعد ذلك، تقدم المحاضرة مفهوم الاستكشاف باستخدام ε-greedy، وهي استراتيجية توازن بين الاستكشاف (تجربة أفعال جديدة)والاستغلال (اختيار أفضل فعل معروف).
وفي النهاية، يتم عرض خوارزمية Monte Carlo Control الكاملة باستخدام عدد قليل من أسطر Python، مما يمكّن الطلاب من بناء وتنفيذ حل متكامل لـ MC Control من البداية إلى النهاية.
-
30RLF_S3L3: Monte Carlo Control A Step-by-Step Walkthrough PDF
-
31RLF_S3L3: Quiz 10
-
32RLF_S3L4: Off-Policy MC & Importance Sampling
On-policy Monte Carlo (MC) uses the same policy for both acting and learning, which can be limiting in many real-world situations.
This lecture introduces two important concepts:
- Behavior Policy (b): the policy used to collect data and interact with the environment.
- Target Policy (π): the policy we actually want to evaluate or learn about.
Students will then learn Importance Sampling, a technique that adjusts or reweights returns collected under one policy so they can be used to estimate performance under a different policy.
This approach is powerful because it allows us to evaluate risky, expensive, or multiple candidate policies without needing to execute them directly.
The lecture concludes with a practical example using a logged dataset of four episodes, where two different candidate policies (π_A and π_B) are evaluated without ever being run in the environment.
في On-Policy Monte Carlo (MC) يتم استخدام نفس السياسة للتفاعل مع البيئة والتعلم منها، وهو ما قد يشكل قيدًا في العديد من التطبيقات الواقعية.
تقدم هذه المحاضرة مفهومين أساسيين:
- سياسة السلوك (Behavior Policy - b): وهي السياسة المستخدمة فعليًا لجمع البيانات والتفاعل مع البيئة.
- السياسة المستهدفة (Target Policy - π): وهي السياسة التي نرغب في تقييمها أو التعلم عنها.
بعد ذلك، يتعرف الطلاب على مفهوم Importance Sampling، وهي تقنية تقوم بإعادة وزن (Reweighting) العوائد التي تم جمعها باستخدام سياسة معينة، بحيث يمكن استخدامها لتقدير أداء سياسة مختلفة.
تُعد هذه الطريقة مهمة جدًا لأنها تسمح بتقييم سياسات خطرة، أو مكلفة، أو متعددة المرشحين دون الحاجة إلى تشغيلها فعليًا.
وتختتم المحاضرة بمثال عملي يعتمد على مجموعة بيانات مسجلة تتكون من أربع حلقات (Episodes)، حيث يتم تقييم سياستين مختلفتين (π_A و π_B) دون تشغيلهما فعليًا داخل البيئة.
-
33RLF_S3L4: Off-Policy Monte Carlo One Dataset, Multiple Policy Evaluations PDF
-
34RLF_S3L4: Quiz 11
-
35RLF_S3L5: Solve Blackjack with First-Visit MC Control
This lecture brings everything together through a complete hands-on implementation of First-Visit Monte Carlo Control using the Blackjack-v1 environment.
Students will build and train an RL agent from scratch, applying the concepts learned throughout the section in a real environment.
After training for approximately 500,000 episodes, students should observe:
- A win rate of around 42%
- Approximately 200 evaluated states
- A clear 3D value surface that closely resembles real Blackjack strategy tables
This lecture represents the “you can actually build RL systems now” milestone — where theory turns into practical implementation and visible results.
في هذه المحاضرة تتجمع جميع المفاهيم معًا من خلال تنفيذ عملي كامل لخوارزمية First-Visit Monte Carlo Control باستخدام بيئة Blackjack-v1.
سيقوم الطلاب ببناء وتدريب وكيل تعلم معزز من الصفر، مع تطبيق جميع المفاهيم التي تم تعلمها خلال هذا القسم داخل بيئة حقيقية.
بعد التدريب على حوالي 500,000 حلقة (Episode)، من المتوقع أن يلاحظ الطلاب:
- معدل فوز يقارب 42%
- حوالي 200 حالة تم تقييمها
- ظهور سطح قيم ثلاثي الأبعاد (3D Value Surface) يشبه بشكل كبير جداول استراتيجيات لعبة البلاك جاك الحقيقية
تمثل هذه المحاضرة لحظة “أصبح بإمكانك فعل ذلك فعليًا” — حيث تتحول المفاهيم النظرية إلى تطبيق عملي ونتائج ملموسة.
-
36Build a Model-Free Blackjack Agent and Compare On-Policy vs Off-Policy MC
-
37RLF_S4L1: TD(0) — One-Step Temporal Difference
This lecture introduces TD(0) — Temporal Difference Learning, one of the simplest yet most influential algorithms in Reinforcement Learning (RL).
Unlike Monte Carlo methods, which wait until the end of an episode before updating value estimates, TD(0) learns immediately after every step by comparing the current prediction with the next prediction.
Students will learn:
- The TD(0) update rule and how it works.
- The meaning of every symbol in the equation.
- How learning happens through prediction errors between consecutive states.
To make the concept intuitive, the lecture walks through a 3-state random walk example by hand, showing step by step how rewards gradually propagate backward through the states — one step at a time across episodes.
This lecture marks an important transition toward online learning, where agents improve continuously while interacting with the environment.
تقدم هذه المحاضرة خوارزمية TD(0) — التعلم بالفروق الزمنية (Temporal Difference Learning)، والتي تُعد من أبسط وأكثر خوارزميات التعلم المعزز تأثيرًا وأهمية.
على عكس طرق مونت كارلو (Monte Carlo) التي تنتظر نهاية الحلقة (Episode) لتحديث قيم الحالات، تقوم TD(0) بالتعلم بعد كل خطوة مباشرة من خلال مقارنة التوقع الحالي بالتوقع التالي.
سيتعلم الطلاب:
- قاعدة التحديث الخاصة بـ TD(0) وكيفية عملها.
- معنى كل رمز داخل المعادلة.
- كيف يحدث التعلم من خلال أخطاء التنبؤ بين الحالات المتتالية.
ولتوضيح الفكرة عمليًا، تستعرض المحاضرة مثالًا يدويًا باستخدام ممر عشوائي مكوّن من 3 حالات (3-State Random Walk)، حيث يتم شرح كيفية انتقال المكافآت تدريجيًا إلى الخلف عبر الحالات — خطوة واحدة في كل حلقة.
تمثل هذه المحاضرة انتقالًا مهمًا نحو مفهوم التعلم أثناء التفاعل (Online Learning)، حيث يتحسن الوكيل باستمرار أثناء تعامله مع البيئة.
-
38RLF_S4L1: Walkthrough: TD(0) on a 3-State Random Walk PDF
-
39RLF_S4L1: Quiz 12
-
40RLF_S4L2: Eligibility Traces & the Forward/Backward View
TD(0) is slow: the +1 reward propagates only one step per episode. Eligibility traces are a memory mechanism — each state keeps a fading record of how recently it was visited, and when a TD error fires it broadcasts to all states proportional to their trace. This single change lets one TD error update many states at once, solving the credit-assignment problem. We end by introducing the forward view (clean math) and the backward view (works online).
-
41RLF_S4L2: Quiz 13
-
42RLF_S4L3: TD(n) — Multi-Step Returns
TD(0) uses just one real reward and one bootstrap; Monte Carlo uses all real rewards and no bootstrap. n-step TD is the family in between: collect n real rewards, then bootstrap. By tuning n you move smoothly between TD(0) (n=1) and MC (n=∞). We define the n-step return G^(n), give the update rule, and walk through TD(0) vs 3-step TD on the same trajectory so you can see credit assignment speed up.
-
43RLF_S4L3: Walkthrough: n-Step TD on a 5-State Chain PDF
-
44RLF_S4L3: Quiz 14
-
45RLF_S4L4: Bias vs Variance — Why n Matters
TD(0) and Monte Carlo make opposite mistakes. TD(0) is biased (its bootstrap V is wrong early on) but has low variance (updates are consistent). MC is unbiased (uses real returns) but has high variance (rollouts differ wildly). This lecture frames the trade-off, draws the bullseye picture, sketches the U-shaped total-error curve, and finishes with a concrete numerical example comparing TD(0), TD(3), and MC across 5 simulated episodes — TD(3) wins on MSE.
-
46RLF_S4L4: Quiz 15
-
47RLF_S4L5: TD(λ) — Unifying the Spectrum
TD(λ) is the synthesis of Lectures 2 and 3: combine eligibility traces (Lec 2) with multi-step returns (Lec 3) into one update with a single tuning knob λ. The forward view blends all n-step returns with geometric weights (1−λ)λ^(n−1); the backward view achieves the same updates online via traces decaying by γλ. We clarify the common confusion (TD(λ=1) is NOT TD(n=1) — it's roughly MC), look at the λ-weights for three values of λ, and walk through computing a λ-return by hand.
-
48RLF_S4L5: Walkthrough: TD(λ) — Computing the λ-Return PDF
-
49RLF_S4L5: Quiz 16
-
50RLF_S4L6: SARSA & SARSA(λ) — TD Control
We move from prediction (estimating V) to control (finding the optimal policy). SARSA is one-step TD applied to Q(s,a), using the policy's own next-action sample — making it on-policy. We derive the SARSA update, walk through it on a tiny 2-state grid, then merge it with eligibility traces to get SARSA(λ) — the capstone algorithm that combines everything in Section 4. A worked example shows how a single TD error broadcasts to three Q-values via traces.
-
51RLF_S4L6a: Walkthrough: SARSA on a 2-State, 2-Action Grid PDF
-
52RLF_S4L6b: Walkthrough: SARSA(λ) — Eligibility Traces in Action PDF
-
53RLF_S4L6: Quiz 17
-
54RLF_S4L7: Foundation Wrap-Up + What's Next
A short connective lecture that places everything you've learned on a single map and previews the Intermediate course. The unification map shows where TD, SARSA, MC, and DP each sit on the model-free / model-based axis and points to the next steps: Q-learning, DQN, policy gradients, actor-critic, PPO.
-
55RLF_S4L7: Quiz 18
-
56TD(0), n-Step TD, and SARSA(λ) on FrozenLake & CliffWalking