본문으로 건너뛰기

RL 006

· 약 4분

Known MDP vs Unknown MDP

AspectKnown MDPUnknown MDP
Environment Knowledge (P,RP, R)Full knowledge of state transition dynamics PP and reward function RRPP and RR are unknown; agent must explore the environment
Problem ApproachWell-defined optimization problem \rightarrow Pure planning via computationTrial-and-error interaction \rightarrow Must learn and optimize simultaneously
Primary GoalDirectly compute the optimal policy (π\pi_*)Learn and optimize policies without prior model knowledge
Representative MethodsValue Iteration, Policy Iteration (Dynamic Programming)Monte Carlo, Q-Learning, SARSA (Reinforcement Learning)
ParadigmModel-based (Planning)Model-free (Reinforcement Learning)

Model-based vs Model-free

AspectModel-Based LearningModel-Free Learning
Model Access (P,RP, R)Has full access to transition dynamics PP and reward function RRNo access to environment dynamics (PP and RR are unknown)
Optimization ApproachDirect mathematical computation and planning using the known modelDirect learning and trial-and-error optimization through interaction
Estimation SourceComputes values and optimal policy π\pi_* via dynamic programming equationsEstimates vπ,qπv_\pi, q_\pi, and π\pi_* directly from sampled experience
Computation vs. SamplingPure computation / Planning (requires no real-time environment sampling)Sample-based learning (requires trajectories / episodic experience)
Typical MethodsPolicy 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 π\pi by Sampling (Monte Carlo Simulation)

  • Mechanism:
    • Generate uniform random points (x,y)[1,1]×[1,1](x, y) \in [-1, 1] \times [-1, 1].
    • Count points falling inside the unit circle (x2+y21x^2 + y^2 \le 1).
    • Estimate π\pi via area proportions:
AreacircleAreasquare=π4π4×#points inside circle#total points\begin{aligned} \frac{\text{Area}_{circle}}{\text{Area}_{square}} = \frac{\pi}{4} \\ & \pi \approx 4 \times \frac{\text{\#points inside circle}}{\text{\#total points}} \end{aligned}
  • Empirical Validation:
    • Total samples (nn): 30003000 points
    • Estimated value: π=3.1386666666666665\pi = 3.1386666666666665
    • Relative error: 0.0931%-0.0931\% from true value (3.14159265\approx 3.14159265)

Monte Carlo

Monte Carlo Prediction

vπ(s)=Eπ[GtSt=s]1Ni=1N(s)G(i)v_\pi(s) = \mathbb{E}_{\pi}[G_t | S_t = s] \approx \frac{1}{N} \sum_{i=1}^{N(s)} G^{(i)}

  • 1Ni=1N(s)G(i)\frac{1}{N} \sum_{i=1}^{N(s)} G^{(i)}: Mean of the returns/rewards
  • Model-Free Learning: Operates without prior knowledge of transition dynamics PP or reward function RR.
  • Learning from Complete Episodes: Learns state-value functions vπv_\pi exclusively from full trajectories under policy π\pi. Only works for episodic tasks where termination at step TT is guaranteed.
  • No Bootstrapping: Does not update estimates using other value estimates v(s)v(s'); instead, updates rely solely on actual empirical returns observed at the end of the episode.
  • Empirical Mean Returns: The value of state ss is estimated by the sample average of all observed returns starting from ss:

An Episode of Experience & Return Formulation

  • Trajectory Structure: S0A0,R1S1A1,R2S2AT1,RTSTS_0 \xrightarrow{A_0, R_1} S_1 \xrightarrow{A_1, R_2} S_2 \dots \xrightarrow{A_{T-1}, R_T} S_T
  • Discounted Return (GtG_t): Gt=Rt+1+γRt+2+γ2Rt+3++γTt1RTG_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + \dots + \gamma^{T-t-1} R_T
  • Discount Factor (γ=1\gamma = 1): For episodic tasks with terminal-only rewards (such as Blackjack), setting γ=1\gamma = 1 is standard practice because the episode length is finite.

First-Visit Monte Carlo

  • First-Visit MC estimates the value function V(s)V(s) by averaging returns following only the first occurrence of state ss within each sampled episode.
  • Algorithmic Flow:
    • Initialize counters N(s)0N(s) \leftarrow 0 and accumulate returns: G(s)0sSG(s) \leftarrow 0 \quad \forall s \in S
    • Sample a complete episode i={Si,0,Ai,1,Ri,2,,Si,Ti}i = \{S_{i,0}, A_{i,1}, R_{i,2}, \dots, S_{i,T_i}\} generated under policy π\pi
    • Compute return Gi,t=k=t+1Tiγkt1Ri,kG_{i,t} = \sum_{k=t+1}^{T_i} \gamma^{k-t-1} R_{i,k} from step tt to termination.
    • Only for the first time step tt where state ss appears in episode ii:
      • N(s)N(s)+1N(s) \leftarrow N(s) + 1 (Increment counter for total first visits)
      • G(s)G(s)+Gi,tG(s) \leftarrow G(s) + G_{i,t} (Increment total return)
      • V(s)G(s)N(s)V(s) \leftarrow \frac{G(s)}{N(s)} (Update the value by mean return)

AR1=1BR2=2AR3=1CR4=1terminalA \xrightarrow{R_1=1} B \xrightarrow{R_2=2} A \xrightarrow{R_3 = 1} C \xrightarrow{R_4 = 1} \text{terminal}

State sN(s)N(s)G(s)G(s)V(s)=G(s)N(s)V(s) = \frac{G(s)}{N(s)}
A199.00
B188.00
C155.00

Every-Visit Monte Carlo