# What is the difference between a stochastic and a deterministic policy?

In reinforcement learning, there are the concepts of stochastic (or probabilistic) and deterministic policies. What is the difference between them?

A deterministic policy is a function of the form $$\pi_{\mathbb{d}}: S \rightarrow A$$, that is, a function from the set of states of the environment, $$S$$, to the set of actions, $$A$$. The subscript $$_{\mathbb{d}}$$ only indicates that this is a $${\mathbb{d}}$$eterministic policy.

For example, in a grid world, the set of states of the environment, $$S$$, is composed of each cell of the grid, and the set of actions, $$A$$, is composed of the actions "left", "right", "up" and "down". Given a state $$s \in S$$, $$\pi(s)$$ is, with probability $$1$$, always the same action (e.g. "up"), unless the policy changes.

A stochastic policy is often represented as a family of conditional probability distributions, $$\pi_{\mathbb{s}}(A \mid S)$$, from the set of states, $$S$$, to the set of actions, $$A$$. A probability distribution is a function that assigns a probability for each event (in this case, the events are actions in certain states) and such that the sum of all the probabilities is $$1$$.

A stochastic policy is a family and not just one conditional probability distribution because, for a fixed state $$s \in S$$, $$\pi_{\mathbb{s}}(A \mid S = s)$$ is a possibly distinct conditional probability distribution. In other words, $$\pi_{\mathbb{s}}(A \mid S) = \{ \pi_{\mathbb{s}}(A \mid S = s_1), \dots, \pi_{\mathbb{s}}(A \mid S = s_{|S|})\}$$, where $$\pi_{\mathbb{s}}(A \mid S = s)$$ is a conditional probability distribution over actions given that the state is $$s \in S$$ and $$|S|$$ is the size of the set of states of the environment.

Often, in the reinforcement learning context, a stochastic policy is misleadingly denoted by $$\pi_{\mathbb{s}}(a \mid s)$$, where $$a \in A$$ and $$s \in S$$ are respectively a specific action and state, so $$\pi_{\mathbb{s}}(a \mid s)$$ is just a number and not a conditional probability distribution. A single conditional probability distribution can be denoted by $$\pi_{\mathbb{s}}(A \mid S = s)$$, for some fixed state $$s \in S$$. However, $$\pi_{\mathbb{s}}(a \mid s)$$ can also denote a family of conditional probability distributions, that is, $$\pi_{\mathbb{s}}(A \mid S) = \pi_{\mathbb{s}}(a \mid s)$$, if $$a$$ and $$s$$ are arbitrary.

In the particular case of games of chance (e.g. poker), where there are sources of randomness, a deterministic policy might not always be appropriate. For example, in poker, not all information (e.g. the cards of the other players) is available. In those circumstances, the agent might decide to play differently depending on the round (time step). More concretely, the agent could decide to go "all in" $$\frac{2}{3}$$ of the times whenever it has a hand with two aces and there are two uncovered aces on the table and decide to just "raise" $$\frac{1}{3}$$ of the other times.

A deterministic policy can be interpreted as a stochastic policy that gives the probability of $$1$$ to one of the available actions (and $$0$$ to the remaining actions), for each state.

• 'A deterministic policy can be interpreted as a stochastic policy that gives the probability of 1 to one of the available actions (and 0 to the remaining actions), for each state.' don't think this is correct since the definition of stochasticity is that the event can't be predicted. Meaning : "having a random probability distribution or pattern that may be analysed statistically but may not be predicted precisely." – DuttaA May 12 '19 at 19:21
• @DuttaA You can have a probability distribution that assigns $1$ to one event and $0$ to everything else. This is mathematically possible. I said "you can interpret". I am not saying that this is a good way of thinking about it. – nbro May 12 '19 at 19:29
• The definition of stochasticity is that you cannot predict, which is not the case here. – DuttaA May 12 '19 at 19:39
• @DuttaA This is one definition of stochasticity. I have actually read one definition of PMF that states that each event must have a probability greater than 0 (but they likely meant $\geq 0$). What happens if there is only one event? In that case, that event must have probability $1$. So, a probability distribution can give probability $1$ to one event (and $0$ to the others). – nbro May 12 '19 at 19:46