Dulranga's Notes
Semester 3Artificial Intelligence

Reinforcement Learning

In RL, the Transition Probability Function T(s,a,s′)T(s,a, s') and Reward Function R(s,a,s′)R(s,a,s') are unknown. i.e. agent does not know how often a transition can go wrong

So the agent,

Act→Observe→Repeat\text{Act} \to \text{Observe} \to \text{Repeat}

Types of RL

rl-types.png

  • Active Learning - No policies given for the world
  • Passive Learning - Evaluating a given policy for the world

Episode Based Evaluation

Agent explore the world and get to the goal or terminate. That is a single episode. Then the observed world will change the current predictions.

Model Based Learning

The agent keep running episodes for some number of times. Then it finds T(s,a,s′)T(s,a, s') and R(s,a,s′)R(s,a,s') for the whole world.

  • T(s,a,s′)T(s,a, s') - Count how many times actually got from ss to s′s' when performed aa
T(s,a,s′)=count(s,a,s′)count(s,a)=No. of times Actually got into  s′No. of times triedT(s, a, s') = \frac{count(s,a,s')}{count(s,a)} = \frac{\text{No. of times Actually got into} \;s'}{\text{No. of times tried}}
  • R(s,a,s′)R(s,a,s') - Record the rewards as it explore the world.

After this, its a MDP Problem and solved for the optimal policy π(s)\pi(s)

Whole Flow:

Find T, R  →value iteration / planning  V,Q  →arg⁡max⁡  π(s)\text{Find T, R} \;\xrightarrow{\text{value iteration / planning}}\; V, Q \;\xrightarrow{\arg\max}\; \pi(s)

Caveats of Model based learning

size(T)=∣S∣2∣A∣\text{size}(T) = |\mathcal{S}|^2 |\mathcal{A}|

Size of the Transition Probabilities Space is HUGE. (ex. 1,000 states and 4 actions give 4 million parameters.) Reason - A tabular transition model needs one probability per (s,a,s′)(s,a,s')

Strengths of Model based learning

Since it has a model, it captures structure. So every sample we take helps massively.

Model Free Learning

In these algorithms, the model is gone. And it does not try to find the TT or RR for each transition. It learns what to do, or how good things are, directly from experience.

Info

Model-based: experience → model → values → policy Model-free: experience → values or policy

Analogy: A model-free agent is like a cyclist who has learned to balance by feel, with no physics equations. A model-based agent is like an engineer who writes down the dynamics first and then works out how to ride.

Passive Learning

Evaluating a given, already-defined policy π\pi

What happens,

  • You are given a fixed policy π\pi
  • The agent follows π\pi and watches what happens. It makes no choices.
  • Goal: learn the value of the policy, Vπ(s)V^\pi(s)

Direct Evaluation

  1. run the policy π\pi for several episodes
  2. for every state visit, compute GG (Total discounted reward from there to the end) Same as Markov Decision Process#Rewards & Discounting
  3. V(s)V(s) is the Average of the discounted rewards observed from the state.
Gt=rt+γ  rt+1+γ2  rt+2+γ3  rt+3+…G_t = r_t + \gamma \; r_{t+1} + \gamma^2 \; r_{t+2} + \gamma^3 \; r_{t+3} + \dots Vπ(s)≈G1(s)+G2(s)+G3(s)+G4(s)+…Iteration_Count(s)V^\pi(s) \approx \frac{G_1(s)+G_2(s)+G_3(s)+G_4(s)+\dots}{\text{Iteration\_Count}(s)}

Temporal Difference learning

Temporal Difference means, learn a little from every new experience you get. The agent samples new episodes and the New value that's obtained from that will contribute a little to the already established value we have for a state.

Agent experience, (s,π(s),s′,r)(s, \pi(s), s', r)

Sample=r+γ  V(s′)(What this one experience suggest)\text{Sample} = r + \gamma \; V(s') \qquad \text{(What this one experience suggest)} δ=Sample−V(s)V(s)←V(s)+α⋅δ\delta = \text{Sample} - V(s) \\ \\ V(s) \leftarrow V(s) + \alpha \cdot \delta

The value for that state ss from agent's current guess is updated with a little step towards the new Value from that sample.

  • α\alpha - Learning Rate (0<α<10 \lt \alpha \lt 1) This determines how much the sample will contribute to the value.
WorldEvaluation
td-grid-example.png
V(A)=V(B)=V(C)=V(E)=0V(A) = V(B) = V(C) = V(E) = 0

V(D)=8V(D) = 8

Observe (B,east,C,−2)(B, east, C, −2)

Sample = −2 + 1 × V(C) = −2 + 0 = −2
δ = sample − V(B) = −2 − 0 = −2

V(B) ← 0 + 0.5 × (−2) = −1
Info

This works fine since we already know the policy. But finding V(s)V(s) does not allow us to get the policies if its unknown. For that, Q(s,a)Q(s, a) are required

policy-from-v.png policy-from-q.png

Active Learning

What happens,

  • The optimal policy is unknown.
  • Agent must decide which action to take and find out what happens
  • Goal: learn the optimal policy

value-vs-q-iteration.png

In this case, since we do not have information about the V(s)V(s) values, we use the old QQ values assigned for each state, action pairs to get the updated QQ values.

Q Learning

Agent experience (s,a,s′,r)( s, a, s', r )

sample=r+γ  maxa′  Q(s′,a)(Best Available next Q value)δ=sample−Q(s,a)Q(s,a)←Q(s,a)+α⋅δ\text{sample} = r + \gamma\; \underset{a'}{max}\; Q(s',a) \qquad \text{(Best Available next Q value)} \\\\ \delta = \text{sample} - Q(s,a) \\\\ Q(s,a) \leftarrow Q(s,a) + \alpha \cdot\delta

How agent choose an action to continue?

In Q learning, Agent choose the best possible action for the state from the previous Q values, because of this, agent might choose actions even though due to the stochastic behavior, failures might hurt more even the action is the best.

cliff-walk-sarsa-vs-q-learning.png In this world, the Q learning would pick the blue path even though there is a huge chance that agent might fell into the cliff.

To avoid this, the agent must explore alternatives even though they might not be the "best" actions "for the moment".

SARSA

This algorithm allows agent to take other actions than the best one to explore the world more. q-learning-vs-sarsa-update.png

In SARSA, The a′a' in Q(s′,a′)Q(s', a') is chosen,

  • With probability 1−ε1-\varepsilon, exploit by taking the action with the highest Q(s,⋅)Q(s,\cdot)
  • With probability ε\varepsilon, explore by taking a random action.

Action with highest Q value is known as the "Greedy Action"

epsilon-greedy.png

P(greedy)=1−ε+εNP(greedy) = 1 − \varepsilon + \frac{\varepsilon}{N}
  • N - No. of available actions.

On this page