RL 011
· 6 min read
Model Based RL
- Model: Transition Probability, Reward Function, State, Action, Discount Factor
- Planning: use the learned models to evaluate possible actions, construct or iprove a value function or policy using Value/Policy Iteration.
- Underlying MDP: The env's actual state transitions and reward structure.
- Transition Model
- Reward Model
- Goal: Approximate the env's MDP and use if for planning.
| Aspect | Model-Free RL | Model-Based RL |
|---|---|---|
| Environment Model | No model available (transition dynamics) | Learn a model from experience |
| Learning | Directly learn a value function and/or policy from experience | Use the learned model to plan a value function and/or policy |
| Methods | Learn directly from experience | Use a simulator with DP, Model-Free RL, or Policy Search |
Advantages of Model-Based RL
- Efficient Model Learning: Supervised learning can efficiently learn transition and reward models from experience.
- Model Uncertainty: The learned model can estimate uncertainty in its prediction
Disadvantages of Model-Based RL
- Two-Step Process: First learn the environment model, then use it to construct a value function or policy.
- Two Sources of Approximation Error:
- Approximated Model Error: The learned model may inaccurately predict transitions or rewards.
- Approximated Planning Error: Planning with the learned model may produce approximate or suboptimal results.
- Compounding Error: Model and planning errors can accumulate, reducing the accuracy of the final policy.
MDP Model
- Assumption: State space and Action space are known and the env satisfies the Markov property.
- Model is parameterized by and represents state-transitions and rewards.
- Assume that the next state and reward are conditionally independent given the current state and action (not a consequence of the Markov property).
- This allows transition and reward distributions to be modeled separately.
Model Learning
- Goal: Approximate a model from experience .
- Supervised Learning: Use as input and as targets.
- Loss Function: Measure prediction errors using a loss function (e.g., MSE).
- Empirical Loss: Average prediction error over observed training data.
- Use supervised learning framework, find parameters that minimize empirical loss (MSE).
Lookup Table Model
- Underlying Model is presented as a lookup table.
- A model is an explicit
- is the number of times State-Action pair has been visited.
- : Indicator function that is 1 if the condition is true, 0 otherwise.
- is the estimated probability of transitioning from state to state under action .
- Estimated Transition Probability by counting the number of times the State-Action-Next State tuple has been observed.
- Calculate the average reward for the State-Action pair.
Single Action MRP Example
Two States and no discount, 8 episodes of learning.
- A → B: 100% transition probability, reward = 0.
- B → Terminal: 75% chance of reward 1, 25% chance of reward 0.
| Episode | Experience |
|---|---|
| 1 | A, 0, B, 0 |
| 2 | B, 1 |
| 3 | B, 1 |
| 4 | B, 1 |
| 5 | B, 1 |
| 6 | B, 1 |
| 7 | B, 1 |
| 8 | B, 0 |
- MC: Estimates values using observed complete returns.
- TD: Uses bootstrapping, updates a state's value using the estimated value of the next state.
- Requires a backup of after has been learned.
Planning with a model
- Given Model
- Solve by .
- With Planning algorithm:
- Value Iteration
- Policy Iteration
- Tree searching
- etc.
Sample-based Planning
- Generate a lot of samples or data then, use model free methods such as MC, SARSA, Q-learning, etc. to plan.
- Data Efficiency: Reduce real environment interactions by learning from simulated experiences.
Monte Carlo Search
- Given a model and simulated policy
- For each :
- Simulate episodes from current state
- Evaluate actions by mean returns (MC evaluation)
- : Return from the -th simulation.
- Select current action with max value
e.g.
| Action | Episode 1 | Episode 2 | Episode 3 |
|---|---|---|---|
| Left | 3 | 5 | 4 |
| Right | 2 | 1 | 3 |
- Select action with max value:
Expectimax Tree

- White Node: Choose action with max value.
- Black Node: Average state values of all possible actions.
- Compute Optimal values for the current state by construction an expectimax tree.
- : Transition probability.
- : Expected Reward
- : Value of the next state.
Limitations of Expectimax Tree
- Scaling Exponentially with Depth: Tree size grows exponentially with depth .
- : Number of possible states.
- : Number of possible actions.
- : Depth of the tree.
Monte Carlo Search Tree, MCTS
- Given a model
- Build a search tree rooted at the current state , sample actions and next states.
- Iteratively Construct and update the tree by performing simulation episodes starting from the root node.
- Once search is finished, select the current action with maximum value in the search tree.