Overview

9 The Calculus of Decisions: Policy Gradient Methods

This chapter introduces policy gradient methods as a way to optimize decision-making policies directly, rather than first learning action values and deriving behavior indirectly. The motivation comes from problems like data center cooling, where actions are continuous, high-dimensional, and tightly coupled across many interacting zones. In such settings, value-based methods like DQN become awkward or infeasible because discretizing the action space destroys precision and causes an explosion in the number of possible action combinations. Policy gradients avoid this bottleneck by learning a parameterized policy that maps states straight to actions, while naturally supporting stochastic behavior that can improve exploration and robustness.

The mathematical core is the policy gradient theorem, which shows how to compute the gradient of expected return without knowing the environment dynamics. Using the log-derivative trick, the update depends on the gradient of the policy’s log-probability for the actions that were taken, multiplied by the return from those actions onward. This leads to the REINFORCE algorithm, a Monte Carlo method that samples trajectories, computes return-to-go, and increases the probability of actions that led to good outcomes while decreasing the probability of poor ones. The chapter also explains how Gaussian policies handle continuous actions and how softmax policies handle discrete actions, while emphasizing the role of the reparameterization trick and the importance of correct log-probability calculations when actions are squashed into bounded ranges.

Because vanilla REINFORCE can have high variance, the chapter adds a learned baseline, usually a value network, to form advantages and make learning signals more stable and informative. Entropy regularization is then used to prevent premature collapse to overly deterministic behavior, keeping exploration alive during training. To handle the multi-zone structure of the cooling problem, the chapter introduces attention and Transformer architectures so that each zone can condition its decisions on relevant relationships with other zones. The resulting Transformer-based actor-critic agent is trained on a realistic data center cooling simulation, where it learns to balance energy use against thermal safety and outperforms a hand-crafted PI controller, demonstrating the practical strength of policy gradients for complex continuous-control tasks.

Value-Based vs. Policy-Based Reinforcement Learning.
The Policy Gradient Objective.
Mathematical proof of Policy Gradient Theorem.
The REINFORCE algorithm core steps.
Variance Reduction with Baselines.
The Attention Mechanism — Query, Key, Value.
Multi head attention architecture
Transformer architecture.
Cooling optimization problem.
REINFORCE Training Progress — Data Center Cooling
RL Policy vs. Heuristic Controller — Box Plot Comparison

Summary

  • Value-based methods like DQN require discrete, enumerable action spaces. When actions are continuous (fan speeds, valve openings, motor torques) or high-dimensional (multiple agents or zones), the action space cannot be discretized without losing precision or creating combinatorial explosion.
  • Policy gradient methods optimize the policy directly, representing it as a parameterized probability distribution over actions. This naturally handles continuous and high-dimensional action spaces without discretization.
  • The policy gradient theorem provides a way to compute ∇θJ(θ) without knowing environment dynamics. The gradient is: E[Σₜ ∇θ log πθ(aₜ|sₜ) R(τ)]. The log-derivative trick eliminates the unknown transition probabilities from the gradient.
  • The score function ∇θ log πθ(a|s) points in the direction that makes action a more likely. The return R(τ) scales this direction: positive returns reinforce actions, negative returns suppress them. This is the core mechanism of REINFORCE.
  • REINFORCE collects complete trajectories, computes returns, and updates the policy to make high-return trajectories more probable. It requires no replay buffer, no target network, and no bootstrapping—just sampling and gradient ascent.
  • Gaussian policies for continuous control output a mean μ and standard deviation σ per action dimension. Actions are sampled from Normal(μ, σ), and the standard deviation naturally adapts to control exploration without an external schedule.
  • Vanilla REINFORCE suffers from high variance because the return R(τ) can have arbitrary scale, causing all actions in a trajectory to be reinforced or suppressed regardless of their individual contribution.
  • Subtracting a baseline b(s) from the return reduces variance without introducing bias. The optimal baseline is the state-value function V(s), giving the advantage A = R - V(s), which measures how much better or worse an action was compared to expectation.
  • The actor-critic architecture uses two components: an actor (policy network) updated by the advantage-weighted policy gradient, and a critic (value network) trained to predict expected returns. The critic provides the baseline that stabilizes the actor's learning.
  • Entropy regularization adds a bonus for maintaining policy stochasticity, preventing premature convergence to deterministic behavior before adequate exploration.
  • The attention mechanism computes weighted combinations of inputs using Query-Key-Value projections. Each element queries all others, and the resulting attention weights reflect pairwise relevance. This enables dynamic, context-dependent information routing.
  • Multi-head attention runs multiple independent attention computations in parallel, each learning different relationship patterns (thermal coupling, workload correlation, pressure dynamics). Concatenating the heads captures multiple types of inter-zone interactions simultaneously.
  • The Transformer encoder stacks layers of multi-head self-attention and feedforward networks with residual connections and layer normalization. Each layer enables longer-range interactions, so two layers can capture indirect zone-to-zone effects.
  • Positional encoding adds sinusoidal identity signals to each zone, allowing the Transformer to learn spatial relationships (zone adjacency) alongside state similarity.
  • In data center case study, the Transformer-based REINFORCE agent achieved a 53.4% improvement over a hand-tuned PI controller, learning to trade slightly higher energy cost for dramatically fewer temperature violations—a trade-off directly aligned with the reward function's priorities.
  • Policy gradient methods are the foundation for modern RL algorithms (PPO, SAC, A3C) and are essential whenever actions are continuous, stochastic policies are desirable, or multi-entity coordination is required. Understanding REINFORCE deeply prepares you for these more advanced methods in subsequent chapters.

FAQ

Why is policy gradient preferred over value-based methods for continuous control problems?Policy gradient methods optimize the policy directly, which makes them well-suited for continuous actions like fan speed or valve opening. Value-based methods such as DQN rely on discrete action outputs, so continuous controls must be discretized, leading to huge action spaces and loss of precision.
What is the main idea behind policy gradient methods?They represent the policy as a parameterized function and update its parameters using calculus to maximize expected cumulative reward. Instead of learning Q-values and deriving behavior indirectly, the agent learns the action-selection strategy itself.
What is the policy gradient theorem?The policy gradient theorem shows that the gradient of expected return can be computed without knowing the environment dynamics. It reduces the problem to policy log-probabilities and observed returns, allowing the agent to learn from sampled trajectories only.
Why is the log-derivative trick important in policy gradients?The log-derivative trick rewrites the gradient of a probability as the probability times the gradient of its log. This makes the math manageable and helps remove unknown transition dynamics from the gradient expression.
How does the REINFORCE algorithm update the policy?REINFORCE collects trajectories, computes return-to-go for each time step, and updates the policy to increase the probability of actions that led to high returns and decrease the probability of actions that led to low returns.
Why does REINFORCE use return-to-go instead of the full trajectory return?Return-to-go only includes rewards from the current time step onward, which matches causality: an action can affect future rewards but not past ones. Using the full trajectory return adds noise because it credits an action for rewards that happened before it was taken.
What problem does a baseline solve in REINFORCE?A baseline reduces variance in the gradient estimate without changing its expected value. By subtracting a state-dependent baseline, usually the critic’s value estimate, the algorithm focuses on whether an action was better or worse than expected.
What is advantage, and why is it useful?Advantage is the difference between the observed return-to-go and the expected value of the state: A(s,a) = G - V(s). It gives a relative measure of action quality, making the learning signal cleaner and more stable than using raw returns alone.
Why does the chapter use attention and Transformers in the cooling problem?The cooling zones interact with each other, so the agent needs to reason about relationships between zones, not just each zone independently. Attention and Transformers let each zone focus on the most relevant neighboring or related zones, enabling coordinated cooling decisions.
What role does entropy regularization play in policy gradient training?Entropy regularization encourages the policy to stay exploratory by preventing it from becoming too deterministic too early. It helps avoid premature convergence and supports better exploration during training, especially in complex control tasks.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Applied Reinforcement Learning ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Applied Reinforcement Learning ebook for free