Showing posts with label policy iteration. Show all posts
Showing posts with label policy iteration. Show all posts

Tuesday, December 10, 2024

A Beginner’s Guide to LSPI and Fitted Q Iteration in Reinforcement Learning


LSPI vs Fitted Q Iteration in Reinforcement Learning

๐Ÿง  LSPI vs Fitted Q Iteration (FQI)

Reinforcement learning (RL) teaches an agent to make decisions that maximize reward. When data is limited, Least-Squares Policy Iteration (LSPI) and Fitted Q Iteration (FQI) are two powerful, data-efficient approaches.

๐Ÿ“˜ Basics: Policies & Q-Functions +
  • Policy: A rule mapping states to actions
  • Q-Function: Expected long-term reward of taking an action in a state
Q(state, action) → expected future reward
      
๐Ÿ“ What is LSPI? +

LSPI improves a policy by estimating the Q-function using least-squares regression over a fixed dataset.

How LSPI Works

  1. Collect experience data (S, A, R, S')
  2. Represent states/actions with features
  3. Solve Q-function using least-squares
  4. Update policy greedily
Dataset → Feature Matrix
→ Least-Squares Q
→ Greedy Policy Update
      
⚙️ Why LSPI is Useful +
  • Data efficient
  • Offline learning
  • Handles continuous state/action spaces
  • Interpretable linear models
๐Ÿ” What is Fitted Q Iteration (FQI)? +

FQI learns the Q-function by repeatedly fitting it to Bellman updates using powerful function approximators.

Q(s, a) = r + ฮณ · max Q(s', a')
      

FQI Process

  1. Initialize Q-function
  2. Apply Bellman update to dataset
  3. Fit a model (NN, tree, etc.)
  4. Repeat until convergence
๐Ÿ†š LSPI vs FQI: Key Differences +
Aspect LSPI FQI
Main Focus Policy improvement Q-function approximation
Function Approximation Linear features Neural nets / trees
Data Size Small to medium Medium to large
Interpretability High Lower
๐ŸŽฏ When to Use Which? +

Use LSPI if:

  • Limited data
  • Simple features
  • Need interpretability

Use FQI if:

  • Complex environments
  • Large datasets
  • Non-linear value functions

๐Ÿ’ก Key Takeaways

  • Both LSPI and FQI are data-efficient RL methods
  • LSPI is simple, linear, and interpretable
  • FQI is powerful and scales to complex problems
  • Choice depends on data size and environment complexity
Offline Reinforcement Learning • Data-Efficient Intelligence

Thursday, October 24, 2024

Value Function Methods in Reinforcement Learning


Value Function in Reinforcement Learning (RL) – Complete Guide

๐ŸŽฏ Value Function in Reinforcement Learning (RL): Complete Deep Dive

๐Ÿ“š Table of Contents

๐Ÿ“˜ Introduction

Reinforcement Learning (RL) is one of the most powerful paradigms in artificial intelligence. It focuses on how agents make decisions by interacting with an environment.

At the core of this decision-making lies the value function — a concept that enables agents to predict the future and act intelligently.

๐Ÿ’ก Key Insight: RL is not about immediate reward — it’s about maximizing long-term cumulative reward.

๐Ÿง  What is a Value Function?

A value function estimates how good a situation is for an agent.

1. State Value Function

$$ V(s) = \mathbb{E}[G_t | S_t = s] $$

This represents expected future reward starting from state s.

2. Action Value Function

$$ Q(s,a) = \mathbb{E}[G_t | S_t = s, A_t = a] $$

This evaluates how good taking action a in state s is.

✔ V(s) → “How good is this state?” ✔ Q(s,a) → “How good is this action in this state?”

⚙️ How Value Functions Work

Agents repeatedly interact with the environment:

  • Observe state
  • Take action
  • Receive reward
  • Move to next state

๐Ÿ“Š Return Definition

$$ G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + ... $$

This equation represents cumulative reward.

๐Ÿ” Discount Factor

$$ 0 \leq \gamma \leq 1 $$

  • ฮณ = 0 → only immediate rewards matter
  • ฮณ → 1 → future rewards matter more

๐Ÿ“ Bellman Equations Explained

State Value Bellman Equation

$$ V(s) = \sum_a \pi(a|s) \sum_{s'} P(s'|s,a) [R + \gamma V(s')] $$

Action Value Bellman Equation

$$ Q(s,a) = \sum_{s'} P(s'|s,a) [R + \gamma \max_{a'} Q(s',a')] $$

These equations break a complex decision into smaller recursive problems.

๐Ÿ’ก Bellman Equation = “Future reward = immediate reward + discounted future value”

๐Ÿงฉ Value Function-Based Methods

๐Ÿ”„ Value Iteration

Initialize V(s) = 0
Repeat:
  V(s) = max_a ฮฃ P(s'|s,a)[R + ฮณV(s')]
Until convergence
Iteration 1: V(s)=0
Iteration 2: V(s)=5.3
Iteration 3: V(s)=6.1
...
Converged

๐Ÿ” Policy Iteration

Initialize random policy ฯ€
Repeat:
  Evaluate Vฯ€
  Improve policy:
    ฯ€(s) = argmax Q(s,a)
Until stable

๐ŸŒ Applications

  • Robotics – navigation & automation
  • Game AI – chess, Go
  • Finance – trading optimization
  • Healthcare – treatment planning

⚠️ Challenges

๐Ÿ“‰ Curse of Dimensionality

State space grows exponentially:

$$ |S| = n^d $$

Where:

  • n = possible values
  • d = dimensions

๐Ÿง  Function Approximation

Neural networks approximate value functions:

$$ V(s; \theta) $$

๐ŸŽฏ Conclusion

✔ Value functions predict long-term rewards ✔ Bellman equations drive learning ✔ Value iteration & policy iteration are core methods ✔ Modern RL uses neural networks to scale

Understanding value functions is essential for mastering reinforcement learning.

Featured Post

How HMT Watches Lost the Time: A Deep Dive into Disruptive Innovation Blindness in Indian Manufacturing

The Rise and Fall of HMT Watches: A Story of Brand Dominance and Disruptive Innovation Blindness The Rise and Fal...

Popular Posts