본문으로 건너뛰기

RL 011

· 약 6분

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 P(s′∣s,a)P(s'|s,a)
    • Reward Model R(s,a)R(s,a)
    • Goal: Approximate the env's MDP and use if for planning.
AspectModel-Free RLModel-Based RL
Environment ModelNo model available (transition dynamics)Learn a model from experience
LearningDirectly learn a value function and/or policy from experienceUse the learned model to plan a value function and/or policy
MethodsLearn directly from experienceUse 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​

MDP=⟨S,A,P,R⟩η\text{MDP} = \langle S, A, P, R \rangle_{\eta}

  • Assumption: State space SS and Action space AA are known and the env satisfies the Markov property.
  • Model μ=⟨Pη,Rη⟩\mu = \langle P_{\eta}, R_{\eta} \rangle is parameterized by η\eta and represents state-transitions and rewards.
    • Pη≈PP_{\eta} \approx P
    • Rη≈RR_{\eta} \approx R

St+1∼Pη(st+1∣st,at)S_{t+1} \sim P_{\eta}(s_{t+1} | s_t, a_t) Rt+1∼Rη(rt+1∣st,at)R_{t+1} \sim R_{\eta}(r_{t+1} | s_t, a_t)

P(st+1,Rt+1∣st,at)=P(st+1∣st,at)P(Rt+1∣st,at)P(s_{t+1}, R_{t+1} | s_t, a_t) = P(s_{t+1} | s_t, a_t) P(R_{t+1} | s_t, a_t)

  • 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 μη\mu_\eta from experience {S1,A1,R2,…,ST}\{S_1, A_1, R_2, \ldots, S_T\}.
  • Supervised Learning: Use (St,At)(S_t, A_t) as input and (Rt+1,St+1)(R_{t+1}, S_{t+1}) 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 η\eta that minimize empirical loss (MSE).
η∗=arg⁡min⁡ηL(η)\eta^* = \arg \min_\eta L(\eta)

Lookup Table Model​

  • Underlying Model is presented as a lookup table.
  • A model is an explicit MDP,P^,R^\text{MDP}, \hat{P}, \hat{R}

P^ss′a=1N(s,a)∑t=1T1((St,At,St+1)=(s,a,s′))\hat{P}_{ss'}^a = \frac{1}{N(s,a)} \sum_{t=1}^T 1((S_t, A_t, S_{t+1}) = (s,a,s'))

  • N(s,a)N(s,a) is the number of times State-Action pair has been visited.
  • 11: Indicator function that is 1 if the condition is true, 0 otherwise.
  • P^ss′a\hat{P}_{ss'}^a is the estimated probability of transitioning from state ss to state s′s' under action aa.

P^(s′∣s,a)=N(s,a,s′)N(s,a)\hat{P}(s'|s,a) = \frac{N(s,a,s')}{N(s,a)}

  • Estimated Transition Probability by counting the number of times the State-Action-Next State tuple has been observed.
R^sa=1N(s,a)∑t=1T1((St,At)=(s,a))Rt+1\hat{R}_s^a = \frac{1}{N(s,a)} \sum_{t=1}^T 1((S_t, A_t) = (s,a)) R_{t+1}
  • Calculate the average reward for the State-Action pair.

Single Action MRP Example​

Two States {A,B}\{A, B\} 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.
EpisodeExperience
1A, 0, B, 0
2B, 1
3B, 1
4B, 1
5B, 1
6B, 1
7B, 1
8B, 0
  • MC: Estimates values using observed complete returns.
    • V(B)=6/8=0.75V(B) = 6/8 = 0.75
    • V(A)=0V(A) = 0
  • TD: Uses bootstrapping, updates a state's value using the estimated value of the next state.
    • V(B)=0.75V(B) = 0.75
    • V(A)←γ+γV(B)=0+0.75=0.75V(A) \leftarrow \gamma + \gamma V(B) = 0 + 0.75 = 0.75
    • Requires a backup of AA after V(B)V(B) has been learned.

Planning with a model​

  • Given Model μη=⟨Pη,Rη⟩\mu_\eta = \langle P_{\eta}, R_{\eta} \rangle
  • Solve MDP⟨S,A,Pη,Rη⟩\text{MDP} \langle S, A, P_{\eta}, R_{\eta} \rangle by η\eta.
  • 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.
  • St+1∼Pη(St+1∣St,At)S_{t+1} \sim P_{\eta}(S_{t+1} | S_t, A_t)
  • Rt+1∼Rη(Rt+1∣St,At)R_{t+1} \sim R_{\eta}(R_{t+1} | S_t, A_t)
  • Data Efficiency: Reduce real environment interactions by learning from simulated experiences.
  • Given a model μv\mu_v and simulated policy π\pi
  • For each a∈Aa \in A:
Q(St,a)=1K∑k=1KGtQ(S_t, a) = \frac{1}{K} \sum_{k=1}^K G_t
  • Simulate kk episodes from current state st:{st,a,Rt+1k,…,STk}∼μv,πs_t: \{ s_t, a, R_{t+1}^k, \ldots, S_T^k \} \sim \mu_v, \pi
  • Evaluate actions by mean returns (MC evaluation)
  • Gt(k)G_t^{(k)}: Return from the kk-th simulation.
  • Select current action with max value

at=arg⁡max⁡a∈AQ(st,a)a_t = \arg\max_{a \in A} Q(s_t, a)

e.g.

ActionEpisode 1Episode 2Episode 3
Left354
Right213
  • Q(st,Left)=3+5+43=4Q(s_t, \text{Left}) = \frac{3 + 5 + 4}{3} = 4
  • Q(st,Right)=2+1+33=2Q(s_t, \text{Right}) = \frac{2 + 1 + 3}{3} = 2
  • Select action with max value: Left\text{Left}

Expectimax Tree​

Expectimax Tree

  • White Node: Choose action with max value.
  • Black Node: Average state values of all possible actions.
  • Compute Optimal Q(s,a)Q(s,a) values for the current state by construction an expectimax tree.
Q(s,a)=∑s′Pν(s′∣s,a)[Rν(s,a,s′)+γV(s′)]Q(s,a)=\sum_{s'}P_\nu(s'|s,a) \left[R_\nu(s,a,s')+\gamma V(s')\right] V(s)=max⁡aQ(s,a)V(s)=\max_a Q(s,a)
  • Pν(s′∣s,a)P_\nu(s'|s,a): Transition probability.
  • Rν(s,a,s′)R_\nu(s,a,s'): Expected Reward
  • V(s′)V(s'): Value of the next state.

Limitations of Expectimax Tree​

O((∣S∣×∣A∣)H)O((|\mathcal S|\times|\mathcal A|)^H)
  • Scaling Exponentially with Depth: Tree size grows exponentially with depth HH.
  • ∣S∣|\mathcal S|: Number of possible states.
  • ∣A∣|\mathcal A|: Number of possible actions.
  • HH: Depth of the tree.

Monte Carlo Search Tree, MCTS​

  • Given a model μv\mu_v
  • Build a search tree rooted at the current state sts_t, sample actions and next states.
  • Iteratively Construct and update the tree by performing KK simulation episodes starting from the root node.
  • Once search is finished, select the current action with maximum value in the search tree.

at=arg⁡max⁡a∈AQ(st,a)a_t = \arg\max_{a \in A} Q(s_t, a)