Stochastic policy

On this page 7

A stochastic policy is a decision rule in reinforcement learning that maps each state to a probability distribution over actions, written as π(a|s), so the agent samples its action rather than always selecting the same one. It contrasts with a deterministic policy, which returns a single action for every state.

Stochastic policies are central to policy gradient methods, actor-critic algorithms and maximum entropy reinforcement learning. They provide built-in exploration, make the objective differentiable with respect to policy parameters, and can be strictly better than any deterministic policy when the agent cannot fully observe the state or faces an adaptive opponent.

How a stochastic policy selects actions

Formally, a stochastic policy assigns a probability π(a|s) to every action a in state s, with the probabilities summing to one. At each time step the agent observes the state, evaluates the distribution and samples an action from it. Two visits to the same state may therefore produce different actions.

In deep reinforcement learning, the distribution is produced by a policy network whose outputs are distribution parameters. The form of those parameters depends on the action space, as the table below shows.

Action spaceTypical distributionNetwork output
Discrete actionsCategoricalOne logit per action, passed through softmax
Continuous actionsDiagonal GaussianMean and log standard deviation per dimension
Bounded continuous actionsSquashed Gaussian or BetaGaussian parameters with tanh, or Beta shape values
Multi-discrete actionsIndependent categoricalsSeparate logits for each sub-action
Hybrid actionsMixed categorical and GaussianParameters for each component
Common distribution families for stochastic policies

A key quantity is the policy entropy, which measures how spread out the distribution is. High entropy means near-uniform choices and broad exploration, while low entropy means the policy has concentrated probability on a few actions.

Stochastic policies also define the value functions used to evaluate them. The state value V(s) and the action value Q(s,a) are expectations taken over the policy’s own action probabilities, so any change to the distribution changes the values. This coupling is why actor-critic methods update the policy and the critic together, with the critic estimating values for the current stochastic behavior rather than for an idealized greedy one.

Why stochastic policies are useful

The first benefit is exploration without extra machinery. A deterministic agent needs an external mechanism such as epsilon-greedy or added noise, whereas a stochastic policy explores naturally because lower-probability actions are still tried. As learning progresses, entropy usually falls and behavior becomes more consistent.

The second benefit is mathematical. The policy gradient theorem expresses the gradient of expected return as an expectation of the gradient of log π(a|s) weighted by returns or advantages. This score-function estimator requires a policy with non-zero probabilities, which is why algorithms such as REINFORCE, A3C and proximal policy optimization rely on stochastic policies.

The third benefit concerns optimality. In a fully observed Markov decision process, an optimal deterministic policy always exists. In partially observable problems and in games, however, randomization can be necessary: in rock-paper-scissors the only unexploitable strategy is uniform play, and in aliased states a random choice avoids getting stuck.

Stochastic and deterministic policies compared

The choice between the two policy types shapes the whole learning algorithm. The table below contrasts their properties.

PropertyStochastic policyDeterministic policy
OutputDistribution π(a|s)Single action μ(s)
ExplorationBuilt into samplingRequires added noise or schedules
Gradient estimatorScore function, higher variancePathwise through the critic
Partial observabilityCan represent mixed strategiesMay loop or be exploited
Typical algorithmsPPO, TRPO, SAC, A2CDDPG, TD3
Deployment behaviorOften switched to mean or modeUsed as learned
Stochastic versus deterministic policies

In practice the line is blurred. A trained stochastic policy is frequently deployed in greedy mode, taking the most likely action or the Gaussian mean, while deterministic methods such as TD3 add exploration noise during training. Value-based methods like Q-learning learn a deterministic greedy policy but act with an epsilon-greedy stochastic behavior policy.

Controlling randomness during training

Too much randomness wastes samples, while too little causes premature convergence to a poor solution. Algorithms therefore use explicit mechanisms to manage the distribution, summarized in the table below.

MechanismHow it worksUsed in
Entropy bonusAdds a reward term for higher entropyA2C, A3C, PPO
Temperature parameterScales logits to sharpen or flatten choicesSoft actor-critic, softmax policies
Automatic entropy tuningAdjusts temperature toward a target entropySoft actor-critic
Learned standard deviationNetwork shrinks variance as confidence growsGaussian policies
KL constraintsLimit how far each update moves the distributionTRPO, PPO
Mechanisms for managing policy randomness

In maximum entropy reinforcement learning, entropy is part of the objective itself. The agent maximizes reward plus a weighted entropy term, which yields more robust policies that keep several good behaviors available instead of committing to one fragile solution.

Limitations and common pitfalls

Stochastic policies bring their own difficulties. Score-function gradients have high variance, which is why baselines, advantage functions and generalized advantage estimation are essential. Off-policy learning with stochastic policies also requires importance sampling or careful corrections when data come from a different policy.

  • Entropy collapse: the distribution becomes nearly deterministic too early and exploration stops.
  • Unbounded Gaussians: sampled actions fall outside valid ranges unless they are squashed or clipped consistently.
  • Log-probability errors: forgetting the tanh correction term produces biased gradients.
  • Unsafe sampling at deployment: random actions may be unacceptable in safety-critical control.

These pitfalls are usually caught by monitoring entropy and action statistics during training alongside the reward curve. A sudden drop in entropy without a matching rise in return is an early warning of premature convergence, while persistently high entropy late in training suggests that the entropy coefficient is too large or that the reward signal is too weak to shape the distribution. Comparing the stochastic and greedy versions of the same policy on evaluation episodes also reveals how much performance depends on sampling noise.

The short version

A stochastic policy is a set of odds for what to do next. The agent rolls weighted dice instead of following a fixed rule. Good choices get higher odds over time.

Think of a new visitor trying restaurants in a city. Mostly they return to the favorite place. Sometimes they try somewhere new. That small chance of trying something different helps them discover better options. Later, they stick with what works.

Where it makes a difference

An engineering team trains a simulated robotic arm to pick up objects of different shapes using proximal policy optimization. The policy network outputs the mean and standard deviation of a Gaussian for each of seven joint velocities. Early in training, the standard deviations are large, so the arm tries a wide range of movements and occasionally succeeds by chance.

After about 20 million simulation steps, the learned standard deviations shrink and the success rate rises above 90 percent in simulation. An entropy bonus of 0.01 prevented the variance from collapsing during the first million steps, which earlier runs had shown led to a stuck, low-reward policy. For deployment on the physical robot, the team uses the Gaussian mean as the action, removing sampling noise while keeping the behavior learned through stochastic exploration.