RL 006
· 약 12분
Known MDP vs Unknown MDP
| Aspect | Known MDP | Unknown MDP |
|---|---|---|
| Environment Knowledge () | Full knowledge of state transition dynamics and reward function | and are unknown; agent must explore the environment |
| Problem Approach | Well-defined optimization problem Pure planning via computation | Trial-and-error interaction Must learn and optimize simultaneously |
| Primary Goal | Directly compute the optimal policy () | Learn and optimize policies without prior model knowledge |
| Representative Methods | Value Iteration, Policy Iteration (Dynamic Programming) | Monte Carlo, Q-Learning, SARSA (Reinforcement Learning) |
| Paradigm | Model-based (Planning) | Model-free (Reinforcement Learning) |
Model-based vs Model-free
| Aspect | Model-Based Learning | Model-Free Learning |
|---|---|---|
| Model Access () | Has full access to transition dynamics and reward function | No access to environment dynamics ( and are unknown) |
| Optimization Approach | Direct mathematical computation and planning using the known model | Direct learning and trial-and-error optimization through interaction |
| Estimation Source | Computes values and optimal policy via dynamic programming equations | Estimates , and directly from sampled experience |
| Computation vs. Sampling | Pure computation / Planning (requires no real-time environment sampling) | Sample-based learning (requires trajectories / episodic experience) |
| Typical Methods | Policy Iteration, Value Iteration (DP) | Monte Carlo Methods, TD Learning, Q-Learning, SARSA |
Monte Carlo Methods
- A Computational technique that uses random sampling and statistical methods to solve complex problems and estimate numerical results.
- Named after the Monte Carlo Casino in Monaco.
- It means Estimate an unknown quantity by sampling, and averaging what you observe.
- Used fo any estimation method whose operation involves a significant random component.
- Used in mathematics, physics, engineering, finance, computer science, etc.
- It is particularly valuable when an analytical solution is difficult or impossible to obtain.
Estimating by Sampling (Monte Carlo Simulation)
- Mechanism:
- Generate uniform random points .
- Count points falling inside the unit circle ().
- Estimate via area proportions:
- Empirical Validation:
- Total samples (): points
- Estimated value:
- Relative error: from true value ()

Monte Carlo Prediction
- : Mean of the returns/rewards
- Model-Free Learning: Operates without prior knowledge of transition dynamics or reward function .
- Learning from Complete Episodes: Learns state-value functions exclusively from full trajectories under policy . Only works for episodic tasks where termination at step is guaranteed.
- No Bootstrapping: Does not update estimates using other value estimates ; instead, updates rely solely on actual empirical returns observed at the end of the episode.
- Empirical Mean Returns: The value of state is estimated by the sample average of all observed returns starting from :
An Episode of Experience & Return Formulation
- Trajectory Structure:
- Discounted Return ():
- Discount Factor (): For episodic tasks with terminal-only rewards (such as Blackjack), setting is standard practice because the episode length is finite.
First-Visit Monte Carlo
- First-Visit MC estimates the value function by averaging returns following only the first occurrence of state within each sampled episode.
- Algorithmic Flow:
- Initialize counters and accumulate returns:
- Sample a complete episode generated under policy
- Compute return from step to termination.
- Only for the first time step where state appears in episode :
- (Increment counter for total first visits)
- (Increment total return)
- (Update the value by mean return)
| State s | |||
|---|---|---|---|
| A | 1 | 9 | 9.00 |
| B | 1 | 8 | 8.00 |
| C | 1 | 5 | 5.00 |
Every-Visit Monte Carlo
- Every-Visit MC treats every single occurrence of state within an episode as a valid data sample, accumulating its corresponding return into the empirical mean.
- Algorithmic Flow:
- Initialize counters and accumulate returns:
- Sample a complete episode generated under policy
- Compute return from step to termination.
- For each time step where state appears in episode :
- (Increment counter for total visits)
- (Increment total return)
- (Update the value by mean return)
| State s | |||
|---|---|---|---|
| A | 2 | 9+6=15 | 7.50 |
| B | 1 | 8 | 8.00 |
| C | 1 | 5 | 5.00 |
| Dimension | First-Visit MC | Every-Visit MC |
|---|---|---|
| Returns used per episode | Only the first occurrence | Every occurrence |
| Sample independence | Independent across episodes (i.i.d.) | Correlated within an episode (mitigated by sampling) |
| Bias (finite samples) | Unbiased | Biased, but |
| Convergence | Consistent (Law of Large Numbers) | Consistent (as ) |
| Implementation | Requires a "seen this episode?" check | Simpler — no check needed |
| Practical Use | Standard theoretical baseline | Frequently preferred (uses all available data) |
Incremental Mean
- New estimate = Old estimate + step-size * (new sample - old estimate).
- Memory efficient: Only need to store the old estimate () and the number of visits ().
Incremental Monte Carlo
- Updates the value function incrementally after each trajectory without requiring memory to store individual past returns.
- Algorithmic Flow:
- Initialize and for all .
- Episode sampling: Execute episode under policy and compute returns .
- Incremental update: For each visited state at time step :
- (Increment counter for total visits)
- (Update the value by mean return)
- Where represents the temporal difference (TD) error between the sampled return target and the current estimate.
- Choice step size
- : Replicates the exact empirical sample-average of Every-Visit MC where all observed samples receive equal weight.
- : Implements an exponential recency-weighted running average that decays outdated experience, making it suited for non-stationary environments where MDP dynamics change over time.
- Cons:
- Requires a significant number of episodes to converge to the true value function.
- Requires to terminate the episode.
Model-free Control
- The MDP model is unknown, or too large/complex to use directly.
- But experience can be sampled.
- Applications:
- Robo soccer
- Autonomous vehicles
- Robotics
- Game playing
- Recommender systems
- Finance & portfolio management
On-Policy vs Off-Policy
| Dimension | On-Policy Learning | Off-Policy Learning |
|---|---|---|
| Definition | Evaluates and improves the exact same policy currently used to generate action decisions | Evaluates/improves a target policy () while behaving via a different behavior policy () |
| Data Generation | Trajectories must be generated by the current active policy | Trajectories can come from exploratory policies, historical logs, or human demonstrations |
| Exploration Trade-off | Must balance exploration directly within the target policy (e.g., -greedy) | Separates exploration (behavior policy) from exploitation/optimality (target policy) |
| Representative Algorithms | GLIE Monte Carlo Control, SARSA | Q-Learning, Deep Q-Networks (DQN) |
General Policy Iteration
- Alternates between Policy Evaluation ( or ) and Policy Improvement ().
- This interplay drives the system asymptotically toward the optimal pair or .
- Why Fails in Model-Free Settings:
- Finding the maximizing action over strictly requires the transition model and reward function .
- In Model-Free RL, these dynamics are unavailable; hence, alone cannot guide policy updates without an explicit environment model.

- Model-Free Advantage:
- By estimating directly through sample episodes, policy improvement requires no knowledge of or .
- This fundamental shift makes estimation the standard paradigm for Model-Free Control (Monte Carlo Control, SARSA, Q-Learning).
| Question | How good is this state? | How good is this action in this state? |
| Includes Action? | No | Yes |
| Policy Evaluation | Very suitable | Slightly more difficult |
| Policy Improvement | Requires a model | Directly possible |
| Model-Free Control | Inconvenient | Very suitable |

- This is why MC Control estimates , not .
Exploration Problem
- A greedy agent always chooses the action with the highest current estimated value.
- But what if the current estimates are inaccurate?
Mystery Box Example
Initially,
-
Open the red box:
-
Open the blue box:
-
Keep opening the blue box:
-
A purely greedy agent now keeps choosing the blue box because
. -
However, the red box may actually be better. For example,
.The agent does not know this because it sampled the red box only once.
Exploitation vs. Exploration
- Exploitation: Choose the action that currently has the highest estimated value.
- Exploration: Try less-sampled or unfamiliar actions to discover whether they may actually be better.
- In this example, the agent should occasionally explore the red box because it has not been sampled enough to confidently conclude that it is worse.
-Greedy Exploration
- if , then the agent will choose the greedy action with probability (Exploitation)
- And the random action with probability (Exploration).
- Policy Improvement Theorem:
- for any -greedy policy
- The -greedy policy is as good or better than the original policy :
Monte Carlo Control
- Traditional Policy Iteration:
- Fix the policy .
- Evaluate the current policy until is sufficiently close to .
- Improve the policy using the estimated action values.
- Repeat policy evaluation and policy improvement.
- Monte Carlo Control:
- Perform MC Policy Evaluation after every episode.
- Improve the policy using -greedy after every episode.
- Eventually approaches under appropriate convergence conditions.

GLIE
Greedy in the Limit with Infinite Exploration
Explore enough early -> Explore less over time -> Eventually greedy.- : How many times the state-action pair has been visited in the -th episode.
- Infinite exploration first, greedy behavior in the limit.
GILE Monte Carlo Control
- Algorithm flow:
- Run episode with policy .
- For each state-action pair in the episode:
- Improve the policy based on the new value.
- Repeat until convergence.
old estimate + step-size * (new sample - old estimate).- old estimate =
- new sample =
- step-size =
- Run Episode → Update Q → Reduce → Improve Policy
DP vs MC
- Dynamic Programming:
- Model-based
- Bootstrapping: Updating a value estimate using another estimated value instead of waiting for the final outcome.
- Lower variance
- Monte Carlo:
- Model-free
- No bootstrapping: It uses rewards that actually occurred, not an estimated value of the next state.
- Uses complete sampled returns
- Requires episodic tasks
- Higher variance