1 of 46

Deep Reinforcement Learning: An Overview!

By Akhil Devarashetti

2 of 46

Who am I?

Computer Vision Engineer at BioTrillion

Masters degree in Artificial Intelligence�from University of Cincinnati in 2020

Websites: akhil.ai, ml.gallery

3 of 46

What I’ll cover today

RL Concepts:

- Environments

- Policy Gradients

- Q Learning

- Curiosity

- Model-Based

For each RL concept:

- Some theory

- Code

- Demo

4 of 46

What is Reinforcement Learning?

Any algorithm that learns by trial and error

Random Moves

Learn

Good Moves

Win/Lose

5 of 46

Why Care?

Any business value? Practicality?

6 of 46

But why I love RL is because …

It’s fun!

7 of 46

Closest thing to Artificial General Intelligence

8 of 46

But why I love RL is because … It is challenging!

9 of 46

Let’s get the basics out of the way

Env (state)

Agent

Actions: up, down, left, right

Reward:

+10 if green box is reached

-10 if red box is reached

Next state

Objective: Maximize rewards

10 of 46

State Transitions

LEFT

DOWN

0

Reward

0

Reward

(s1, a1, r1)

(s2, a2, r2)

(s3, a3, r3)

… (st,at,rt)

Episode

11 of 46

Working with environments - gym.Env class

Takes an action

Returns next_state and reward

12 of 46

Working with environments - Demo run

Is this agent intelligent?

13 of 46

What does an agent do?

Agent chooses an action given a state

action = agent(state)

Can we replace this agent with a neural network?

14 of 46

Neural network as agent

Neural Network

Up

Down

Left

Right

Softmax

(sampled, not argmax)

(4, 4, 4)

(objects, height, width)

15 of 46

Neural Net Agent

Neural Network in PyTorch

Replaced random agent with neural net agent

Is this agent intelligent?

16 of 46

How do we TRAIN this network?

The objective is to maximize rewards. So that is what we’ll do.

Object/Loss function = Maximize rewards!��maximize(r1 + r2 + r3 + r4 + … + rt)

But neural networks like to MINIMIZE the objective/loss

So let’s minimize(-1 * (r1 + r2 + r3 + r4 + … + rt))

There’s no gradient attached!

Probabilities: p1 p2 p3pt

minimize(-1 * (r1*p1 + r2*p2 + r3*p3 + … + rt*pt))

Reward weighting with probabilities

Policy Gradients!

17 of 46

Code Sample

Sampling actions

Loss function

minimize(-1 * (r1*p1 + r2*p2 + r3*p3 + … + rt*pt))

18 of 46

Oh, and there’s credit assignment

Some games win in the last step

Ex: gridworld?

Steps leading up to the end are most significant.

Weights: … , 0.77, 0.81, 0.86, 0.9, 0.95, 1

λ = 0.95

Weights = reversed(λ, λ2, λ3, λ4, …)

Some games lose in the last step

Ex: balancing a pole

Steps leading up to the end are least significant.

Weights: 1, 0.95, 0.9, 0.86, 0.81, 0.77, …

Objective function: minimize(-1 * (r1*p1*λ + r2*p22 + r3*p33 + … + rt*ptt))

19 of 46

Problem with PG?

I can learn only after playing the whole episode :(

20 of 46

Let’s predict reward

For every action, there is an equal and op… reward

Ex: Stock investing.

Actions: [invest , don’t invest ]

Reward: [stock up , stock down ]

Let’s predict tomorrow’s reward i.e. reward for current action.

21 of 46

Reward Predictor

Neural Network

Up

Down

Right

Left

-1

-1

10

-1

Predicted rewards

22 of 46

But there’s no immediate reward :(

We get a reward only after navigating and reaching the end position.

-1 reward for all actions.

So which action is the best?

Psst! taking left has a higher long-term reward.

23 of 46

Immediate and Long Term Rewards

return(statet) = Rt = rt + (𝞬 . rt+1) + (𝞬2 . rt+2) + …

Prediction

Rt = rt + 𝞬 . Rt+1

Return = reward … plus a tiny bit of future rewards

𝞬 = small number b/w 0 to 1

Predict

Label

24 of 46

Return Predictor

Q Learning!

Qt

st

env.step

rt

st+1

Qt+1

Rt ← rt + 𝞬 . Rt+1

25 of 46

Let’s look at some code

Random action 10% of the time

Next state’s Q value

rt + 𝞬Rt+1

MSE loss

26 of 46

Ways to improve

Q Learning:

  • Experience replay
  • Target network
  • Rainbow DQN

Policy Gradients:

  • Credit assignment
  • Proximal Policy Optimization

Combining PG and DQN: Advantage Actor Critic

27 of 46

Q Learning Revolution

The famous Atari paper by DeepMind

0%!!??

28 of 46

Sparse Reward Problem

  • Lots of planning
  • No guidance via rewards
  • Random exploration will not help

29 of 46

Curiosity!

Our agent is too reliant on external rewards.

No motivation to explore.

How is a human curious?

30 of 46

Curiosity!

  • Reducing uncertainty about the world
  • Intrinsic rewards from high loss
  • Increase the reward frequency?

LEFT

31 of 46

Intrinsic Curiosity Module

MSE( , )

Qt

st

env.step

rt

st+1

Qt+1

Qt

st

step

rt

st+1

Qt+1

Extrinsic reward

st

~st+1

at

~st+1

st+1

Intrinsic reward

32 of 46

DQN with intrinsic reward

Rt ← (rt ex + rt in ) + 𝞬 . Rt+1

33 of 46

Noisy TV Problem

Random events in the environment.

Examples:

  • Random blowing leaves, mist, etc
  • Non-Player Characters interaction

How is this a problem?

  • Every random event increases the intrinsic reward.
  • The agent stares without exploration

34 of 46

How to solve noisy TV?

st

~st+1

at

~at

st

st+1

st

st+1

st

st+1

35 of 46

Other techniques

  • Random Network Distillation
  • Episodic Memory
  • Agent 57

36 of 46

Model Based

Can you ask a neural network that plays chess - What’s your plan?

Neural Networks lack planning.

37 of 46

Game Tree

38 of 46

Demo

39 of 46

Curse of Dimensionality

  1. Too Broad
  2. Too Deep

40 of 46

  1. Too Broad

Narrow down the search space with probability distribution over valid actions.

Sources:

41 of 46

2. Too Deep

After a certain depth is reached,

predict the value of that branch with value network.

Sources:

42 of 46

43 of 46

What if we don’t have an emulator for planning?

Well, we can learn the dynamics - learned model

44 of 46

MuZero

h(s) → ~s

f(~s) → p, v

g(~st, a) → ~st+1, r

p = probability distribution over actions�v = value of the state

45 of 46

Other techniques

  • Dreamer V2
  • GameGAN

Other topics:

  • Inverse RL
  • Offline RL

Sources:

46 of 46

The End

Resources: