I was recently recommended to take a look at David Silver’s (from DeepMind) YouTube series on Reinforcement Learning. The whole course (10 videos) can be found here.
The full lesson is the following:
In this series, I am going to :
- summarize the important notions taught in each class
- add examples and code
- illustrate some concepts with home made schemas
- do a Deep RL project
- go a bit further by exploring Twin Delayed DDPG and other SOTA models
Introduction to RL
Reinforcement Learning is at the intersection of many fields of science :
- Machine Learning
- Reward System
- Classical/Operant conditioning
- Bounded Rationality
- Operations Research
- Optimal Control
How is RL different from other ML paraddigms ?
- There is no supervisor, only a reward signal
- Feedback is delayed, not instantaneous
- Time matters, since we consider sequences
- The agent’s actions affect the data it sees
Where is RL applied ?
- manage an investment portfolio
- make a robot walk
- control a power station
- play games (Atari, Go…)
Here is a simulation environment in which we trained an agent to run :
The RL learning problem
A reward is a feedback value. In indicates how well the agent is doing at step . The job of the agent is to maximize the cumulative reward.
Reward Hypothesis : All goals can be described by the maximisation of expected cumulative reward.
Some reward examples :
- give reward to the agent if it defeats the Go champion
- give reward to the agent for each dollar that gets in the bank (investment portfolio)
- give reward to the agent if the score of the game increases
The reward might be at the end of the whole process, or at each step, depending on the type of problem we consider.
This is a Sequential Decision Making process. We select actions to maximise the total future reward.
Actions can have long term consequences, and the reward might be delayed. It may be better to sacrifice immediate reward to gain more long-term reward.
- The agent makes an observation .
- The agent then takes action .
- Based on this action, it gets a reward .
- There is a new environment, and a new observation is made
It can be represented in the following way :
The only leverage the agent has on its environment and the reward it gets is the action it takes.
History and State
The history is the sequence of observations, actions and rewards. It’s all the observable variables up to time :
What happens next depends on this history. Our aim is simply to find the right action to take based on the history.
We don’t always use the whole history. Instead, we use the state. It is the information that is used to determine what happens next. It captures all necessary information, and is a function of the history.
The environment state is what is used inside of the environment to determine what should come next : .
If you want to go from A to B, to decide where to turn, you don’t need a map of the whole world, but simply things that are relevant around you. This is the idea behind environment state.
The environment state is however not usually visible to the agent. An agent being in an environment state does not mean that the agent gets data from the whole environment around him or captures data from this whole environment. Only the observations are sent to the agent.
The agent state is the agent’s internal representation. It is all the information used by the agent to take the action. It is a function of the history :
The environment state and the agent state are both information states. An information state is a Markov State. It contains all information from the history :
A state is a Markov State if and only if
Once a state is known, the history may be thrown away. The current state is a sufficient statistic of the future. The environment state is Markov. The history is Markov.
A fully observable environment is an environment in which the agent directly observes the environment state : . This is a Markov Decision Process (MDP).
A partially observed environment is an environment in which the agent indirectly observes the environment. This could be the casr for a robot with limited vision, a trading agent that only knows the current prices… This is called a Partially Observed Markov Decision Process (POMDP). The agent must then construct its own state representation , either by :
- taking the complete history :
- beliefs of environment state :
- recurrent neural network :
The RL Agent
An RL agent includes one or more of these components :
- Policy : agent’s bevavior function
- Value function : how good is each state and/or action
- Model : Agent’s representation of the environment
To illustrate those concepts, suppose that we are facing a really simple maze and want to go from the start position to the end by shifting by at most 1 square each time.
The policy is the agent’s behavior. It maps the state to the action. The policy can be :
- deterministic :
- stochastic :
The arrows represent the policy for each state .
The value function is a prediction of expected future reward. It depends on the way we are behaving, and therefore on .
The value function for a policy gives us the total reward we expect by selecting this policy. It is the sum of the discounted rewards associated to a specific policy.
For example, in the maze example, we could attach the value -1 to the goal, and remove 1 at each step. Some paths as the upper right one are therefore not optimal since the value diminishes.
The numbers represent value of each state .
A model predicts what the environment will do next. The transitions predicts the next state.
The rewards predicts the next reward :
The grid layout represents transition model . The numbers represent immediate reward from each state (same for all action). This is a 1 step prediction of the reward, and describes what the agent understood of the environment.
The reward can however be different for each action.
There is not always a model in the environment. In such case, we talk of model-free environments.
A RL agent can be :
- Value Based : works with the value function itself. No policy (implicit)
- Policy Based : works with the arrows directly, in a structured way, and tries to adjust it. No value function.
- Actor Critic : combines both value andd policy based.
A RL agent can be :
- Model Free : Policy and/or value function. We do not model the environment around a helicopter for example.
- Model Based : Policy and/or value function, but has a model.
Problems in RL
There are 2 fundamental problems in sequential decision making :
- Reinforcement learning : the environment is initially unknows, the agents interacts with the environment and it improves its policy.
- Planning : a model of the environment is known, the agent performs computations with its model and improves its policy.
Planning can be seen as a tree-based search to find the optimal policy.
Reinforcement Learning is a trial and error learning problem. The agent should discover a good policy wthout losing too much reward.
An RL agent must balance between Exploration and Exploitation.
Exploration finds more information about the environment. Exploitation exploits known information to maximise the reward.
Like it? Buy me a coffee