concept stochastic policy in category reinforcement learning

appears as: stochastic policy, stochastic policies
Grokking Deep Reinforcement Learning

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

ŘŁ

With An RL Accent

Reward vs. Return vs. Value function

Reward: Refers to the one-step reward signal the agent gets: the agent observes a state, selects an action, and it receives a reward signal. The reward signal is the core of RL, but it is not what the agent is trying to maximize! Again, the agent is not trying to maximize the reward! Realize that while your agent maximizes the one-step reward, in the long-term, is getting less than it could.

Return: Refers to the total discounted rewards. Returns are calculated from any state and usually go until the end of the episode. That is when a terminal state is reached the calculation stops. Returns are often referred to as total reward, cumulative reward, sum of rewards, and are commonly discounted: total discounted reward, cumulative discounted reward, sum of discounted reward. But, it is basically the same: a return tells you how much reward your agent obtained in an episode. As you can see, returns are better indicators of performance because they contain a long-term sequence, a single-episode history of rewards. But the return is not what an agent tries to maximize, either! An agent that attempts to obtain the highest possible return may find a policy that takes it through a noisy path; sometimes, this path will provide a high return, perhaps most of the time a low one.

Value function: Refers to the expectation of returns. That means, sure, we want high returns, but high in expectation (on average). So, if the agent is in a very noisy environment, or if the agent is using a stochastic policy, it’s all just fine. The agent is trying to maximize the expected total discounted reward, after all: value functions.

Miguel's Analogy

Rewards, returns, value functions, and life

How do you approach life? Do you select actions that are the best for you, or are you one of those kind folks that prioritize others before themselves?

There is no shame either way! Being selfish, to me, is an excellent reward signal. It takes you places. It drives you around. Early on in life, going after the immediate reward can be a pretty solid strategy.

Lots of people judge others for being “too selfish,” but to me, that’s the way to get going. So, go on and do what you want, what you dream of, what gives you satisfaction, go after the rewards! You’ll look selfish and greedy. But you shouldn’t care.

As you keep going, you’ll realize that going after the rewards is not the best strategy, even for your benefit. You start seeing a bigger picture. If you overeat candy, your tummy hurts, if you spend all of your money on online shopping, you can go broke.

So, you start looking at the returns. You start understanding that there is more to your selfish and greedy motives. You drop the greedy side of you because it harms you in the long run, and now you can see that. But you stay selfish, you still only think in terms of rewards, just now “total” rewards, returns. No shame about that, either!

At one point, you’ll realize that the world moves without you, that the world has many more moving parts than you initially thought, that the world has some underlying dynamics that are very difficult to comprehend. You now know that “what goes around comes around,” one way or another, one day or another, but it does.

You step back once again, now instead of the going after rewards or returns, you go after value functions. You wise up! You learn that the more you help others learn, the more you learn, not sure why, but it works, the more you love your significant other, the more they love you, crazy! The more you don’t spend (save,) the more you can. How strange! Notice, you are still selfish!

But you become aware of the complex underlying dynamics of the world and can understand that the best for yourself is to better others — a perfect win-win situation.

I’d like the differences between rewards, returns, and value functions to be ingrained in you, so hopefully this should get you thinking for a bit.

Follow the rewards!

Then, the returns!

Then, the value functions.

A Concrete Example

The Random Walk environment

The primary environment we will use through this chapter is called the Random Walk (RW). This is a walk, single-row grid-world environment, with five non-terminal states. But it’s peculiar, so I want to explain it in two ways.

On the one hand, you can think of the RW as an environment in which the probability of going left when taking the left action is equal to the probability of going right when taking the left action, and the probability of going right when taking the right action is equal to the probability of going left when taking the right action. In other words, the agent has no control of where it goes! The agent will go left with 50% and right with 50% regardless of the action it takes. It’s a random walk, after all. Crazy!

05_01

Figure 5.1 Random walk environment MDP

But to me, that was a very unsatisfactory explanation of the RW, maybe because I like the idea of agents “controlling” something. What’s the point of studying RL (a framework for learning optimal control) in an environment in which there is no possible control!?

Therefore, you can think of the RW as an environment with a deterministic transition function (meaning that if the agent chooses left, the agent moves left, and it moves right if it picks right – as expected.) But pretend the agent wants to evaluate a stochastic policy that selects actions uniformly at random. That’s half the time, it chooses left, the other half, right.

Either way, the concept is the same: we have a five non-terminal state walk in which the agent moves left and right uniformly at random. The goal is to estimate the expected total discounted reward the agent can obtain given these circumstances.

Policy-based methods, on the other hand, can more easily learn stochastic policies, which in turn has multiple additional advantages. First, learning stochastic policies means better performance under partially observable environments. The intuition is that because we can learn arbitrary probabilities of actions, the agent is less dependent on the Markov assumption. For example, if the agent can’t distinguish a handful of states from their emitted observations, the best strategy is often to act randomly with specific probabilities.

Figure 11.3 Learning stochastic policies could get us out of trouble
11_03

Interestingly, even though we are learning stochastic policies, nothing prevents the learning algorithm from approaching a deterministic policy. This is unlike value-based methods, in which, throughout training, we have to force exploration with some probability to ensure optimality. In policy-based methods with stochastic policies, exploration is embedded in the learned function and converging to a deterministic policy for a given state while training is possible.

Another advantage of learning stochastic policies is that it could be more straightforward for function approximation to represent a policy than a value function. Sometimes value functions are too much information for what is truly needed. It could be that calculating the exact value of a state or state-action pair is complicated, or just unnecessary.