concept time in category reinforcement learning

appears as: time, times, time, times, The time, A times
Grokking Deep Reinforcement Learning

This is an excerpt from Manning's book Grokking Deep Reinforcement Learning.

I want to unpack this definition for you one bit at a time. But, don’t get too caught up with the details as it’ll take me the whole book to get you grokking deep reinforcement learning. The following is just the introduction of what you learn about in this book. As such, it’s repeated and explained in detail in the chapters ahead.


A Concrete Example

The Bandit Walk environment

Let’s make these concepts concrete with our first RL environment: I created this very simple environment for this book; I call it the Bandit Walk (BW).

BW is a very simple grid-world (GW) environment. GWs are a common type of environments for studying RL algorithms that are grids of any size. GWs can have any model (transition and reward functions) you can think of, and can make any kind of actions available.

But, they all commonly make move actions available to the agent: LEFT, DOWN, RIGHT, UP (or WEST, SOUTH, EAST, NORTH, which is more precise because the agent has no heading and usually has no visibility of the full grid, but cardinal directions can also be more confusing). And, of course, each action with the logical transitions; E.g. a left moves the agent left most of the time, etc. Also, they all tend to have a fully-observable discrete state and observation spaces (that is state == observation) with integers representing the cell id location of the agent. A “Walk” is a special case of grid-world environments with a single row. In reality, what I call a “Walk,” is more commonly referred to as a “Corridor.” But, in this book, I use the term “Walk” for all the grid-world environments with a single row.

The Bandit Walk (BW) is a walk with 3 states, but only 1 non-terminal state. Environments that have a single non-terminal state are called “bandit” environments. “Bandit” here is an analogy to slot machines, which are also known as “one-armed bandits”; they have one arm and, if you like gambling, can empty your pockets, just like a bandit would.

The BW environment has just 2 actions available: a left (action 0) and an right (action 1) action. BW has a deterministic transition function: a left actions always moves the agent to the left, and a right action always moves the agent to the right. The reward signal is a +1 when landing on the rightmost cell, 0 otherwise. The agent starts in the middle cell.

02_03

Figure 2.3 The bandit walk (BW) environment

Because of the possibility of infinite sequences of time steps in infinite horizon tasks, we need a way to discount the value of rewards over time; that is, we need a way to tell the agent that getting +1’s is better sooner than later. So, we commonly use a positive real value less than one to exponentially discount the value of future rewards. The further into the future we receive the reward, the less valuable it is in the present.

This number is called the discount factor, or gamma. The discount factor adjusts the importance of rewards over time. The later we receive rewards, the less attractive they are to present calculations. Another important reason why the discount factor is commonly used is to reduce the variance of return estimates. Given that the future is uncertain, and that the later we look into the future, the more stochasticity we accumulate and the more variance our value estimates will have, the discount factor helps reducing the degree to which future rewards affect our value function estimates which stabilizes learning for most agents.

Figure 2.18 Effect of discount factor and time on the value of rewards
02_18
Deep Reinforcement Learning in Action

This is an excerpt from Manning's book Deep Reinforcement Learning in Action.

The basic idea is that in PyTorch we create a computational graph, similar to the diagrams we used in the previous section, where relations between inputs, outputs, and connections between different functions are made explicit and kept track of so we can easily apply the chain rule automatically to compute gradients. Fortunately, switching from numpy to PyTorch is simple, and most of the time we can just replace numpy with torch. Let’s translate our neural network from above into PyTorch.

Figure 1.9. The input data (which is the state of the environment at some point in time) is fed into the agent (implemented as a deep neural network in this book), which then evaluates that data in order to take an action. The process is a little more involved than shown here, but this captures the essence.

After the game is over, the return for that episode is the sum of all the rewards acquired, multiplied by their respective discount rate, where γt exponentially decays as a function of time. For example, if action 1 was taken in state A and resulted in a return of +10, the probability of action 1 given state A will be increased a little, whereas if action 2 was taken in state A and resulted in a return of –20, the probability of action 2 given state A will decrease. Essentially, we minimize this loss function:

As with the rest of the deep learning methods, we generally must use batches of data in order to effectively train. Training with a single example a time introduces too much noise, and the training will likely never converge. To introduce batch training with Q-learning we used an experience replay buffer that could randomly select batches of previous experiences. We could have used experience replay with actor-critic, but it is more common to use distributed training with actor-critic (and, to be clear, Q-learning can also be distributed). Distributed training in actor-critic models is more common because we often want to use a recurrent neural network (RNN) layer as part of our reinforcement learning model in cases where keeping track of prior states is necessary or helpful in achieving the goal. But RNNs need a sequence of temporally related examples, and experience replay relies on a batch of independent experiences. We could store entire trajectories (sequences of experiences) in a replay buffer, but that just adds complexity. Instead, with distributed training and each process running online with its own environment, the models can easily incorporate RNNs.