Spaces:
Running
Running
Download index.html from saneeshcleatus/qlearningweb: direct link, hf CLI and curl.
- Browser
- Download file 25.1 kB
-
https://huggingface.co/spaces/saneeshcleatus/qlearningweb/resolve/main/index.html
- Command line
-
hf download hf://spaces/saneeshcleatus/qlearningweb/index.html
-
curl -L -o index.html https://huggingface.co/spaces/saneeshcleatus/qlearningweb/resolve/main/index.html
25.1 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Q-Learning Reward Update Explained</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .math-equation { | |
| font-family: 'Times New Roman', Times, serif; | |
| font-size: 1.1rem; | |
| background-color: #f8f9fa; | |
| padding: 1rem; | |
| border-radius: 0.5rem; | |
| margin: 1rem 0; | |
| overflow-x: auto; | |
| } | |
| .highlight { | |
| background-color: #fff3cd; | |
| padding: 0.2rem 0.4rem; | |
| border-radius: 0.25rem; | |
| } | |
| .transition-all { | |
| transition: all 0.3s ease; | |
| } | |
| .card-hover:hover { | |
| transform: translateY(-5px); | |
| box-shadow: 0 10px 20px rgba(0,0,0,0.1); | |
| } | |
| @media (max-width: 768px) { | |
| .math-equation { | |
| font-size: 0.9rem; | |
| padding: 0.75rem; | |
| } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-8"> | |
| <!-- Header --> | |
| <header class="text-center mb-12"> | |
| <h1 class="text-4xl font-bold text-indigo-800 mb-2">Q-Learning Reward Update Mechanism</h1> | |
| <p class="text-xl text-gray-600">Understanding the mathematical foundation of temporal difference learning</p> | |
| <div class="w-24 h-1 bg-indigo-500 mx-auto mt-4 rounded-full"></div> | |
| </header> | |
| <!-- Introduction Card --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-indigo-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-brain text-indigo-600 text-xl"></i> | |
| </div> | |
| <h2 class="text-2xl font-semibold text-gray-800">Introduction to Q-Learning</h2> | |
| </div> | |
| <p class="text-gray-600 leading-relaxed"> | |
| Q-learning is a model-free reinforcement learning algorithm that learns the value of an action in a particular state (Q-value) without requiring a model of the environment. The core of Q-learning lies in its <span class="highlight">temporal difference (TD) update rule</span>, which combines the current estimate with new information from the environment. | |
| </p> | |
| </div> | |
| </div> | |
| <!-- Mathematical Explanation Section --> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-8 mb-12"> | |
| <!-- Q-Value Definition --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-blue-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-square-root-alt text-blue-600 text-xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold text-gray-800">Q-Value Definition</h3> | |
| </div> | |
| <p class="text-gray-600 mb-4"> | |
| The Q-value represents the expected cumulative reward when taking action <em>a</em> in state <em>s</em> and following the optimal policy thereafter: | |
| </p> | |
| <div class="math-equation"> | |
| Q(s, a) = 𝔼[R<sub>t+1</sub> + γ max<sub>a'</sub> Q(s<sub>t+1</sub>, a') | s<sub>t</sub> = s, a<sub>t</sub> = a] | |
| </div> | |
| <div class="mt-4 text-sm text-gray-500"> | |
| <p><span class="font-bold">R<sub>t+1</sub>:</span> Immediate reward</p> | |
| <p><span class="font-bold">γ:</span> Discount factor (0 ≤ γ ≤ 1)</p> | |
| <p><span class="font-bold">max<sub>a'</sub> Q(s<sub>t+1</sub>, a'):</span> Maximum future reward</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Update Rule --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-green-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-sync-alt text-green-600 text-xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold text-gray-800">TD Update Rule</h3> | |
| </div> | |
| <p class="text-gray-600 mb-4"> | |
| The Q-value is updated using the temporal difference error, which is the difference between the current estimate and the new target value: | |
| </p> | |
| <div class="math-equation"> | |
| Q(s<sub>t</sub>, a<sub>t</sub>) ← Q(s<sub>t</sub>, a<sub>t</sub>) + α [R<sub>t+1</sub> + γ max<sub>a'</sub> Q(s<sub>t+1</sub>, a') - Q(s<sub>t</sub>, a<sub>t</sub>)] | |
| </div> | |
| <div class="mt-4 text-sm text-gray-500"> | |
| <p><span class="font-bold">α:</span> Learning rate (0 ≤ α ≤ 1)</p> | |
| <p><span class="font-bold">TD Error:</span> [R<sub>t+1</sub> + γ max<sub>a'</sub> Q(s<sub>t+1</sub>, a') - Q(s<sub>t</sub>, a<sub>t</sub>)]</p> | |
| <p><span class="font-bold">←:</span> Update operation</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Components Breakdown --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-purple-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-puzzle-piece text-purple-600 text-xl"></i> | |
| </div> | |
| <h3 class="text-xl font-semibold text-gray-800">Components Breakdown</h3> | |
| </div> | |
| <div class="space-y-3"> | |
| <div class="flex items-start"> | |
| <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-bolt text-purple-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Immediate Reward (R<sub>t+1</sub>)</p> | |
| <p class="text-sm text-gray-500">Direct feedback from the environment after taking action a<sub>t</sub></p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-eye text-purple-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Discount Factor (γ)</p> | |
| <p class="text-sm text-gray-500">Determines importance of future rewards (0 = myopic, 1 = far-sighted)</p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-purple-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-tachometer-alt text-purple-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Learning Rate (α)</p> | |
| <p class="text-sm text-gray-500">Controls how much new info overrides old info</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Detailed Explanation --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-yellow-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-microscope text-yellow-600 text-xl"></i> | |
| </div> | |
| <h2 class="text-2xl font-semibold text-gray-800">Deep Dive into the Update Mechanism</h2> | |
| </div> | |
| <div class="space-y-6"> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">1. Temporal Difference Error</h3> | |
| <p class="text-gray-600"> | |
| The key innovation in Q-learning is the use of <span class="highlight">temporal difference (TD) error</span>, which represents the difference between the current Q-value estimate and the newly computed target value: | |
| </p> | |
| <div class="math-equation mt-3"> | |
| δ = R<sub>t+1</sub> + γ max<sub>a'</sub> Q(s<sub>t+1</sub>, a') - Q(s<sub>t</sub>, a<sub>t</sub>) | |
| </div> | |
| <p class="text-gray-600 mt-2"> | |
| This error term drives the learning process by indicating how much the current estimate needs to be adjusted. | |
| </p> | |
| </div> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">2. Bootstrapping</h3> | |
| <p class="text-gray-600"> | |
| Q-learning uses <span class="highlight">bootstrapping</span>, where current estimates are used to update other estimates. This is evident in the term <span class="highlight">max<sub>a'</sub> Q(s<sub>t+1</sub>, a')</span>, which uses the current Q-table to estimate future rewards. | |
| </p> | |
| <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mt-3"> | |
| <p class="text-blue-700"> | |
| <i class="fas fa-info-circle mr-2"></i> This bootstrapping approach allows Q-learning to learn from incomplete episodes, making it more sample-efficient than Monte Carlo methods. | |
| </p> | |
| </div> | |
| </div> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">3. Off-Policy Nature</h3> | |
| <p class="text-gray-600"> | |
| Q-learning is an <span class="highlight">off-policy</span> algorithm because it learns the optimal policy while following an exploration policy (like ε-greedy). The update rule uses the maximum Q-value of the next state, regardless of the action actually taken next. | |
| </p> | |
| <div class="math-equation mt-3"> | |
| max<sub>a'</sub> Q(s<sub>t+1</sub>, a') ← optimal action, not necessarily the one taken | |
| </div> | |
| </div> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">4. Convergence Properties</h3> | |
| <p class="text-gray-600"> | |
| Under the following conditions, Q-learning is guaranteed to converge to the optimal Q-function: | |
| </p> | |
| <ul class="list-disc pl-5 mt-2 space-y-1 text-gray-600"> | |
| <li>All state-action pairs are visited infinitely often</li> | |
| <li>The learning rate α decreases appropriately over time</li> | |
| <li>The environment is a finite Markov Decision Process (MDP)</li> | |
| </ul> | |
| <div class="math-equation mt-3"> | |
| ∑<sub>t=1</sub><sup>∞</sup> α<sub>t</sub> = ∞ and ∑<sub>t=1</sub><sup>∞</sup> α<sub>t</sub><sup>2</sup> < ∞ | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Algorithm Visualization --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-red-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-project-diagram text-red-600 text-xl"></i> | |
| </div> | |
| <h2 class="text-2xl font-semibold text-gray-800">Algorithm Walkthrough</h2> | |
| </div> | |
| <div class="flex flex-col md:flex-row gap-6"> | |
| <div class="md:w-1/2"> | |
| <h3 class="text-lg font-medium text-gray-800 mb-3">Pseudocode</h3> | |
| <div class="bg-gray-800 rounded-lg p-4 text-sm font-mono text-gray-100 overflow-x-auto"> | |
| <p class="mb-2"><span class="text-purple-400">Initialize</span> Q(s, a) arbitrarily</p> | |
| <p class="mb-2"><span class="text-purple-400">for</span> each episode <span class="text-purple-400">do</span></p> | |
| <p class="ml-4 mb-2">Initialize state s</p> | |
| <p class="ml-4 mb-2"><span class="text-purple-400">for</span> each step in episode <span class="text-purple-400">do</span></p> | |
| <p class="ml-8 mb-2">Choose action a from s using policy (ε-greedy)</p> | |
| <p class="ml-8 mb-2">Take action a, observe R, s'</p> | |
| <p class="ml-8 mb-2">Q(s, a) ← Q(s, a) + α[R + γ max<sub>a'</sub> Q(s', a') - Q(s, a)]</p> | |
| <p class="ml-8 mb-2">s ← s'</p> | |
| <p class="ml-4 mb-2"><span class="text-purple-400">until</span> s is terminal</p> | |
| <p class="mb-2"><span class="text-purple-400">end for</span></p> | |
| </div> | |
| </div> | |
| <div class="md:w-1/2"> | |
| <h3 class="text-lg font-medium text-gray-800 mb-3">Visual Representation</h3> | |
| <div class="bg-gray-100 rounded-lg p-4 flex justify-center items-center h-full"> | |
| <div class="text-center"> | |
| <div class="flex justify-center mb-4"> | |
| <div class="relative"> | |
| <div class="w-16 h-16 bg-blue-500 rounded-full flex items-center justify-center text-white font-bold">s</div> | |
| <div class="absolute -bottom-2 left-1/2 transform -translate-x-1/2 bg-green-500 text-white text-xs px-2 py-1 rounded">State</div> | |
| </div> | |
| <div class="mx-4 flex items-center"> | |
| <i class="fas fa-arrow-right text-gray-400 text-xl"></i> | |
| </div> | |
| <div class="relative"> | |
| <div class="w-16 h-16 bg-blue-500 rounded-full flex items-center justify-center text-white font-bold">a</div> | |
| <div class="absolute -bottom-2 left-1/2 transform -translate-x-1/2 bg-yellow-500 text-white text-xs px-2 py-1 rounded">Action</div> | |
| </div> | |
| <div class="mx-4 flex items-center"> | |
| <i class="fas fa-arrow-right text-gray-400 text-xl"></i> | |
| </div> | |
| <div class="relative"> | |
| <div class="w-16 h-16 bg-blue-500 rounded-full flex items-center justify-center text-white font-bold">s'</div> | |
| <div class="absolute -bottom-2 left-1/2 transform -translate-x-1/2 bg-green-500 text-white text-xs px-2 py-1 rounded">Next State</div> | |
| </div> | |
| </div> | |
| <div class="bg-white p-3 rounded-lg shadow-inner"> | |
| <div class="text-sm font-mono text-center"> | |
| <p>Q(s,a) ← Q(s,a) + α[R + γ max Q(s',a') - Q(s,a)]</p> | |
| </div> | |
| </div> | |
| <div class="mt-4 flex justify-between px-4"> | |
| <div class="text-xs bg-red-100 px-2 py-1 rounded">Immediate Reward (R)</div> | |
| <div class="text-xs bg-purple-100 px-2 py-1 rounded">Discount (γ)</div> | |
| <div class="text-xs bg-green-100 px-2 py-1 rounded">Learning Rate (α)</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Practical Considerations --> | |
| <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 transition-all card-hover"> | |
| <div class="p-6"> | |
| <div class="flex items-center mb-4"> | |
| <div class="bg-teal-100 p-3 rounded-full mr-4"> | |
| <i class="fas fa-tools text-teal-600 text-xl"></i> | |
| </div> | |
| <h2 class="text-2xl font-semibold text-gray-800">Practical Implementation Notes</h2> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-6"> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">Hyperparameter Tuning</h3> | |
| <div class="space-y-3"> | |
| <div class="flex items-start"> | |
| <div class="bg-teal-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-sliders-h text-teal-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Learning Rate (α)</p> | |
| <p class="text-sm text-gray-500">Typically starts between 0.1 and 0.5, then annealed over time</p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-teal-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-percentage text-teal-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Discount Factor (γ)</p> | |
| <p class="text-sm text-gray-500">Close to 1 for long-term planning (e.g., 0.9, 0.99)</p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-teal-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-dice text-teal-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Exploration Rate (ε)</p> | |
| <p class="text-sm text-gray-500">Starts high (1.0), decays to small value (0.01)</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <h3 class="text-lg font-medium text-gray-800 mb-2">Implementation Challenges</h3> | |
| <div class="space-y-3"> | |
| <div class="flex items-start"> | |
| <div class="bg-orange-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-table text-orange-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Memory Limitations</p> | |
| <p class="text-sm text-gray-500">Q-table grows with state-action space (curse of dimensionality)</p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-orange-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-bolt text-orange-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Sparse Rewards</p> | |
| <p class="text-sm text-gray-500">Delayed rewards make learning difficult</p> | |
| </div> | |
| </div> | |
| <div class="flex items-start"> | |
| <div class="bg-orange-100 p-1 rounded-full mr-3 mt-1"> | |
| <i class="fas fa-random text-orange-600 text-xs"></i> | |
| </div> | |
| <div> | |
| <p class="font-medium text-gray-700">Exploration-Exploitation</p> | |
| <p class="text-sm text-gray-500">Balancing new actions vs. known good actions</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Footer --> | |
| <footer class="text-center mt-12 pt-8 border-t border-gray-200"> | |
| <div class="flex justify-center space-x-6 mb-4"> | |
| <a href="#" class="text-gray-400 hover:text-indigo-600"> | |
| <i class="fab fa-github text-xl"></i> | |
| </a> | |
| <a href="#" class="text-gray-400 hover:text-indigo-600"> | |
| <i class="fab fa-twitter text-xl"></i> | |
| </a> | |
| <a href="#" class="text-gray-400 hover:text-indigo-600"> | |
| <i class="fab fa-linkedin text-xl"></i> | |
| </a> | |
| </div> | |
| <p class="text-gray-500 text-sm"> | |
| © 2023 Reinforcement Learning Explained. All rights reserved. | |
| </p> | |
| </footer> | |
| </div> | |
| <script> | |
| // Simple animation for cards on page load | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const cards = document.querySelectorAll('.card-hover'); | |
| cards.forEach((card, index) => { | |
| // Add delay based on index for staggered animation | |
| card.style.opacity = '0'; | |
| card.style.transform = 'translateY(20px)'; | |
| setTimeout(() => { | |
| card.style.transition = 'opacity 0.5s ease, transform 0.5s ease'; | |
| card.style.opacity = '1'; | |
| card.style.transform = 'translateY(0)'; | |
| }, 100 * index); | |
| }); | |
| // Add click effect to equations for better UX | |
| const equations = document.querySelectorAll('.math-equation'); | |
| equations.forEach(eq => { | |
| eq.addEventListener('click', function() { | |
| this.classList.toggle('bg-yellow-100'); | |
| }); | |
| }); | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=saneeshcleatus/qlearningweb" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |