Policy Parameterization and Objectives
Imagine teaching a robot arm to pour water into a cup. There is no lookup table large enough to hold a value for every joint angle, velocity, and cup position combination. Even if there were, computing a Value function-maximizing action from it at every timestep would be too slow for real-time control. What the robot needs instead is a compact function that directly outputs "how much torque to apply." This function should be tuned so that pouring succeeds more often than it spills. This is the central shift that policy-based reinforcement learning makes. Instead of learning values and deriving actions from them, we learn the action-selection rule itself. We treat it as a differentiable function of a parameter vector. This chapter introduces the mathematical objects that make this possible. These are a parameterized stochastic policy , and a scalar performance measure that tells us how good is. Nearly every modern deep reinforcement learning system is, at its core, a search over some . This includes game-playing agents, robotic controllers, and RLHF-tuned language models. Each maximizes some version of . Understanding precisely what and mean is the foundation for everything that follows in policy-gradient methods. Understanding why they are defined the way they are matters just as much. The big picture is an optimization problem hiding inside a control problem. We treat the policy as a black box parameterized by a real vector — perhaps the weights of a neural network. We treat "expected total reward when acting according to this policy" as a function of that we want to climb. This turns reinforcement learning into stochastic optimization: pick a , run it in the environment, observe how well it did, adjust , repeat. The subtlety, which this article sets up but does not yet resolve, is that depends on through a complicated chain. The policy affects which states get visited, and those visited states affect which rewards are seen. Differentiating through that dependency is the subject of the Policy-Gradient Theorem. By the end of this article you will be able to write down for discrete and continuous action spaces. You will define correctly for both episodic and continuing tasks. You will explain why we parameterize action preferences rather than probabilities directly. You will also see precisely where the optimization difficulty comes from — setting up the gradient-based methods that follow.
- A policy is a function, with tunable parameters , that outputs a probability distribution over actions given a state.
- Policy-based RL directly optimizes , in contrast to value-based RL which derives a policy indirectly from learned or values.
- The objective is the expected return under , defined differently for episodic tasks (return from a start state) versus continuing tasks (average reward per step).
- Discrete actions typically use a softmax over learned action preferences; continuous actions typically use a Gaussian policy whose mean and variance are learned functions of the state.
- Softmax over preferences (not raw probabilities) guarantees valid distributions automatically and supports smooth, unconstrained gradient-based optimization.
- is generally non-concave and cannot be evaluated in closed form, which is exactly why gradient estimation, not exact optimization, drives the algorithms built on top of this chapter.
A policy-based agent replaces the question "what is this state worth?" with "what should I do here?", encoding the answer as a differentiable function whose parameters are tuned to directly maximize expected return .
The idea
A parameterized policy is a function that maps a state to a probability distribution over actions , where is a real-valued parameter vector — for instance the weights and biases of a neural network, or the coefficients of a linear feature map. This is a generalization of the tabular policies used in Markov Decision Processes: instead of storing a separate probability for every state-action pair, we store a compact, differentiable rule that computes those probabilities on demand, generalizing across states that share structure. The word "stochastic" matters: outputs a distribution, not a single deterministic action, both because randomized exploration is often necessary and because in many domains (e.g. games with hidden information) the optimal policy genuinely is stochastic. Two canonical parameterizations recur throughout the field. For discrete action spaces, we compute a real-valued preference for each action — typically the output of a neural network with one number per action — and convert preferences to probabilities with the softmax:
For continuous action spaces, we instead parameterize the moments of a distribution directly, most commonly a Gaussian:
where and are themselves outputs of a function approximator. This chapter foreshadows, but does not fully develop, the machinery of Continuous Action Spaces and Gaussian Policies — the key point for now is simply that parameterizing a distribution's parameters rather than an action directly is what makes the policy differentiable and hence trainable by gradient methods. The objective is the scalar we are trying to maximize by choosing : the expected return obtained by following . Its precise definition depends on the task structure. In the episodic case, with a designated start-state distribution, we define
the expected discounted return from the start. In the continuing case, where there is no terminal state and episodes never end, discounted return can diverge or lose meaning, so the standard objective becomes the average reward rate:
where is the stationary state distribution induced by following forever. Both formulations share the same essential shape: is an expectation, under trajectories generated by , of accumulated reward. Policy-based reinforcement learning is precisely the problem of finding , or more realistically, of climbing 's gradient as far as we can, since is rarely reachable in closed form.
How it works
Turning "maximize " into an algorithm requires answering three separate questions, and the clean separation between them is exactly what makes the framework modular and reusable across problem types.
Question 1: How do we represent ? We choose a functional form (linear-softmax, neural softmax, Gaussian head) and initialize , typically at random or near zero so the initial policy is close to uniform/exploratory.
Question 2: How do we evaluate , or at least estimate it? We cannot compute the expectation over all possible trajectories in closed form for any nontrivial MDP. Instead, we sample trajectories by rolling the current policy out in the environment (or a simulator) and use the empirical return as an unbiased (Monte Carlo) estimate of .
Question 3: How do we improve ? This chapter sets up the objective but defers the differentiation itself to the Policy-Gradient Theorem; here we simply establish the loop structure that every policy-gradient method shares, so that later chapters can slot in the actual gradient estimator. ``` PolicyOptimizationLoop(theta_init, num_iterations, episodes_per_batch): theta <- theta_init for iteration = 1 to num_iterations: batch_trajectories <- empty list
# --- Question 2: estimate J(theta) by sampling rollouts --- for episode = 1 to episodes_per_batch: trajectory <- empty list s <- sample initial state from d0 while s is not terminal (and episode not truncated): a <- sample action from pi_theta( . | s ) # stochastic policy s', r <- step environment(s, a) trajectory.append( (s, a, r) ) s <- s' batch_trajectories.append(trajectory) J_hat <- average total (discounted) return over batch_trajectories
# J_hat is an unbiased Monte Carlo estimate of J(theta)
# --- Question 3: improve theta using J_hat / trajectories --- grad_estimate <- EstimatePolicyGradient(batch_trajectories, theta)
# <- defined by the Policy-Gradient Theorem, deferred here theta <- theta + alpha grad_estimate # gradient ASCENT on J(theta) return theta ``` Notice the loop's structure: it alternates between acting (sampling actions from the current stochastic policy, which supplies exploration for free) and learning* (nudging using information gathered from those actions' outcomes). Nothing in this loop depends on knowing the environment's transition dynamics — only the ability to sample from them. This is what makes policy-based methods model-free, and it is the same property that lets the same skeleton support both discrete-action softmax policies and continuous-action Gaussian policies, since neither the sampling step nor the update step depends on which parameterization is used.
Complexity & correctness
Representational complexity. If is a linear-softmax policy over actions with a -dimensional feature vector, then evaluating for all actions costs time (one dot product per action) and space for . For a neural policy with layers and width , a forward pass costs time and the parameter count dominates storage — independent of the size of the state space, which is the entire point: a tabular policy over states would need parameters, intractable for continuous or combinatorially large state spaces, whereas a parameterized policy's cost depends only on the chosen function class.
Sampling complexity of estimating . Because has no closed form for general MDPs, we estimate it by Monte Carlo: draw trajectories, average their returns. This estimator is unbiased, since each trajectory's return is drawn from exactly the distribution induced by , and by the law of large numbers its variance shrinks as , so its standard error shrinks as — the same rate as any Monte Carlo estimator, regardless of state or action space size. This is a genuine tradeoff worth stating honestly: policy-based methods pay for their model-freedom and scalability with statistically noisy objective and gradient estimates, one motivation for the variance-reduction techniques (baselines, actor-critic) developed later.
Correctness of the objective's definition. A subtlety worth checking carefully: is actually a well-defined, finite number for all ? In the episodic case with a proper policy (one that reaches termination with probability 1) and bounded per-step reward, is a finite random variable with bounded expectation, so is well-defined. In the continuing case, the average-reward limit exists whenever the Markov chain induced by is ergodic (irreducible and aperiodic), guaranteeing a unique stationary distribution — this is precisely the technical condition under which the average-reward formula above is valid; without ergodicity, may depend on the start state or fail to converge, which is why textbook treatments typically restrict attention to ergodic MDPs when using this objective.
Non-concavity, honestly stated. Even once is well defined, it is essential to be upfront that is, in general, a highly non-concave function of for any nonlinear parameterization (in particular, any neural-network policy). Gradient ascent on is therefore only guaranteed to find a local maximum (or, in the noisy stochastic setting, a stationary point of the expected objective), not the global optimum — a real limitation shared with the rest of deep learning, and not something this framework circumvents. What can be shown rigorously (and is the content of the Policy-Gradient Theorem) is that the direction is well-defined and computable from sampled trajectories alone, without needing a model of the environment — that theorem is what turns "climb " from a slogan into an algorithm.
Worked example
Consider a tiny discrete-action MDP: a 1-D "gridworld corridor" with states , where state is terminal (goal, reward ), and state gives reward per step to discourage lingering. Two actions are available in state : `left` and `right`. We use a linear-softmax policy with a single scalar feature per action: , , so
Suppose we initialize , giving : uniform, maximally exploratory, as expected at initialization.
| Iteration | Sampled action | Return | Effect on estimate | |||
|---|---|---|---|---|---|---|
| 1 | 0.00 | 0.00 | 0.500 | right (reaches goal in 1 step) | high-return sample pulls estimate up | |
| 1 | 0.00 | 0.00 | 0.500 | left (wanders, times out) | low-return sample pulls estimate down | |
| 2 | 0.31 | −0.31 | 0.652 | right | reinforces preference for `right` | |
| 2 | 0.31 | −0.31 | 0.652 | right | reinforces further | |
| 3 | 0.58 | −0.58 | 0.761 | right | policy increasingly deterministic toward `right` | |
| … | → +∞ | → −∞ | → 1.000 | right (always) | (optimal for this toy MDP) |
Two things this trace makes concrete. First, at iteration 1 is genuinely estimated from noisy samples — the two episodes shown gave wildly different returns ( and ) from the same , purely because the stochastic policy sampled different actions; this is exactly the Monte-Carlo variance discussed above. Second, as is pushed up relative to (by whatever gradient rule the later chapter supplies), the softmax smoothly moves probability mass toward the better action without ever violating — a guarantee that comes for free from the softmax's construction, and would have to be re-derived from scratch if we instead tried to parameterize probabilities directly and clip them into .
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Parameterizing raw probabilities instead of preferences/logits | Seems more "direct" | Requires ad-hoc constraints/clipping to keep and ; breaks unconstrained gradient ascent |
| Using discounted-return in a continuing (non-episodic) task | Copying the episodic formula without checking task type | Sum diverges or becomes ill-defined; must use average-reward formulation instead |
| Treating as if it can be computed exactly | Confusing the definition of an expectation with the ability to evaluate it | Leads to non-stochastic "closed-form" implementations that silently ignore environment stochasticity |
| Letting the policy become deterministic too early | Preferences drift to extreme logits, softmax saturates near 0/1 | Loses exploration; agent gets stuck in a local optimum of with no way to escape |
| Assuming a Gaussian policy's can be ignored or fixed forever | Treating variance as a hyperparameter rather than a learnable, state-dependent quantity | Prevents the policy from learning where more/less exploration noise is useful, hurting sample efficiency in continuous control |
Pioneers & history
The idea of directly parameterizing and optimizing a policy, rather than deriving one from value functions, has roots that predate deep learning and connects reinforcement learning to statistics, control theory, and stochastic approximation.
Origins · 1 minRonald J. Williams and how this was discovered
Williams's 1992 work on connectionist reinforcement learning established that the expected-return objective for a stochastic policy could be differentiated using only sampled trajectories, without a model of the environment — the algorithmic seed from which the entire policy-gradient family, and the objective formalized in this article, eventually grew.
Where this matters
Nearly every large-scale application of modern reinforcement learning rests on exactly the framework introduced here. Robotic control systems use Gaussian-parameterized continuous-action policies to output joint torques or motor commands, because tabular or discretized action representations are infeasible for high-dimensional actuators. Game-playing agents in complex action spaces (e.g. real-time strategy or continuous-control benchmarks) use softmax or Gaussian policies parameterized by deep networks, trained by maximizing sample-estimated . Reinforcement learning from human feedback (RLHF), used to align large language models, casts token generation itself as a stochastic policy and fine-tunes to maximize an expected-reward objective structurally identical to here. Simulation-based training pipelines in autonomous driving and industrial control likewise define an explicit reward signal and a parameterized controller, then run the same sample-estimate-and-improve loop. Any system where "what to do" must be learned directly, rather than derived from an intermediate value table, depends on the concepts in this article — the policy representation and the expected-return objective are the shared substrate underneath the entire actor-critic and policy-gradient literature, including the theorem that differentiates and the Gaussian policies used for continuous control.
Ask the tutor: How does the Policy-Gradient Theorem let us compute using only sampled trajectories, without ever differentiating through the environment's unknown transition dynamics?
What exactly is θ in "policy parameterization"?
is a real-valued vector holding every tunable number that defines the policy: weights and biases of a neural network, coefficients of a linear feature map, or any other differentiable function's parameters. It plays the same role as weights in supervised learning, except here the "training signal" is not a labeled dataset but the reward accumulated by acting in an environment. Everything the policy "knows" — how to map a given state to an action distribution — is encoded entirely in ; changing changes behavior, and the entire learning problem is the search for a that produces high expected return.
Why use a stochastic policy at all — why not just parameterize a deterministic action-selection function?
Stochastic policies serve two purposes simultaneously. First, they provide built-in exploration: sampling from naturally tries different actions without needing a separate exploration heuristic like -greedy. Second, in some environments — particularly those with partial observability or adversarial elements — the truly optimal policy is provably stochastic, so a deterministic parameterization could not represent it at all. Deterministic policy variants do exist (used in algorithms like DPG/DDPG) but they require external exploration noise and different mathematical treatment, both deferred to later, more specialized methods.
How does J(θ) relate to the value function V(s) from value-based RL?
They are tightly linked: for the episodic case, is precisely averaged (or evaluated) at the start-state distribution, i.e. . The difference is one of use: value-based methods estimate or as an intermediate quantity and then derive a policy (e.g. greedy) from it, while policy-based methods treat as the direct optimization target and never need an explicit greedy maximization step over actions — which becomes especially important when the action space is continuous and "take the argmax" is not computationally trivial.
Can J(θ) ever be computed exactly, without sampling?
Only in special, small cases — for instance, a finite MDP with known transition probabilities and reward function, small enough that the policy-evaluation equations can be solved exactly via dynamic programming (as in tabular methods). In general, especially once is a neural network and the environment is a black-box simulator or the real world, there is no closed-form expression for the expectation defining . This is precisely why the field relies on Monte Carlo estimation from sampled trajectories, and why the resulting gradient estimates are noisy — a foundational tradeoff, not an implementation shortcut.
What's the difference between a softmax policy's "preferences" and a value function's Q-values?
They look superficially similar (both assign a real number to each action) but serve different roles and are trained differently. Q-values are trained to approximate expected return conditioned on taking a specific action, satisfying a Bellman equation. Preferences have no such semantic constraint — they need not approximate any particular quantity, only need to rank actions in a way that, after the softmax, produces high expected return. In fact, adding any state-dependent constant to all of a state's preferences leaves the policy completely unchanged, a degree of freedom Q-values do not have.
Does a higher-dimensional θ (e.g., a bigger neural network) always give a better policy?
Not necessarily, and this is an important practical caveat. A larger can represent more complex policies (lower approximation error, in principle reaching a higher at the optimum), but it also enlarges the non-concave optimization landscape, increases the variance of gradient estimates, and raises the risk of overfitting to a limited number of sampled trajectories. In practice, policy architecture size is chosen to balance representational capacity against the sample efficiency and stability of the optimization procedure used to climb .
Is the objective J(θ) the same thing as the "reward" the agent receives at each timestep?
No — reward is a single-step scalar signal from the environment, while is a long-horizon, policy-level summary: the expectation of accumulated (discounted or average) reward over an entire trajectory or the long-run behavior of the policy. Many different reward sequences, from many different episodes, are averaged together (implicitly, via the expectation) to produce the one number . Confusing per-step reward with the objective is a common early mistake; the whole point of the policy-gradient framework is to relate changes in the long-run objective to observed short-run rewards, which is the content of the theorem that follows this article.