The Core Problem

In Reinforcement Learning, we want to maximize the expected total reward, denoted as . The objective function is defined as: where is a trajectory (a sequence of states and actions), is our policy parameterized by , and is the total reward of that trajectory.

To maximize this, we need the gradient of the objective with respect to our parameters: .

The Dilemma

The expected return depends on two things:

  1. Our policy (which we control).
  2. The environment’s transition dynamics (which we do not know and cannot differentiate).

If we naively try to take the derivative of the expectation, we run into the problem that the distribution of trajectories itself depends on .

The Theorem

The Policy Gradient Theorem proves that we can compute the gradient of the expected return without knowing the derivative of the state distribution (the environment dynamics).

The gradient elegantly simplifies to:

The Derivation (Log-Derivative Trick)

The proof relies on a simple calculus trick.

  1. Expand the expectation into a sum over all trajectories:
  2. Apply the log-derivative trick: Recall that , which means . Substitute this into our equation:
  3. Decompose the trajectory probability: The probability of a trajectory is the product of initial state probability, policy probabilities, and environment transition probabilities:
  4. Take the log: The product becomes a sum:
  5. Take the gradient: Because the initial state and environment dynamics do not depend on , their derivatives are zero. This is the crucial step. They vanish entirely:

Why this is brilliant

  • We completely bypassed the environment dynamics.
  • We only need to differentiate our own policy network.
  • This formula mathematically justifies trial-and-error: we run trajectories in the environment, collect rewards , and push the log-probabilities of the actions we took up or down proportional to the reward received.