The Tabular Policy
In the tabular approach, the policy at each state is stored as an independent parameter. The state space for the excursion problem is a grid of size , indexed by position and time . Each state carries its own scalar parameter , and the policy is given by the sigmoid function,
(1)
where encodes the two possible steps. This form follows naturally from the softmax over two actions: the probability of stepping up increases with , and decreases with it for stepping down. A positive therefore encodes a preference for moving upward, and corresponds to the unbiased random walk we started from.
Training via Gradient Ascent
To improve the policy, we perform stochastic gradient ascent on the expected return. The update rule for each state parameter is,
(2)
where is the learning rate. The gradient of the objective with respect to is,
(3)
where is a full trajectory sampled under the current policy, and is the reward-to-go from timestep , the cumulative future return along that trajectory. In the language of the value function introduced earlier, plays the role of : it is a Monte Carlo estimate of the expected return from taking action in state .
In practice, the expectation in Equation 3 is approximated by averaging over sampled trajectories,
The key structural feature of the tabular setup is locality: because each is independent, a gradient step only ever modifies the parameter for the state that was actually visited at timestep . No information is shared between states.
The reward function defined in the previous section includes an entropy term . This enters the gradient through the reward-to-go and naturally encourages the policy to remain stochastic during training, preventing premature collapse onto a deterministic path and improving exploration of the trajectory space.
From Tabular to Neural Network
The tabular representation is exact and interpretable, but it does not scale. For the excursion problem the state space is finite and manageable, but in more general settings, larger grids, continuous-time systems, or higher-dimensional state spaces, storing one independent parameter per state quickly becomes infeasible. More fundamentally, the tabular policy cannot generalise: information learned at one state is entirely invisible to every other state.
The solution is to replace the lookup table with a function. Instead of storing directly, we parameterise the policy logits as the output of a neural network,
(4)
where is a feedforward network and now refers to a single shared set of weights applied to every state. The policy retains the same sigmoid form,
(5)
but is now computed from the state through one or more hidden layers rather than read from a table.
Training the Neural Network
The policy gradient objective (Equation 3) remains exactly the same as in the tabular case. What changes is how the gradient is propagated. For each timestep along a trajectory, the gradient signal at the output layer is,
where is a one-hot vector for the action taken. This follows from differentiating with respect to the logits using the softmax identity .
Rather than applying directly to a state parameter as in the tabular case, backpropagation distributes this signal backwards through every layer of the network via the chain rule. Accumulating across all timesteps in a trajectory gives the full gradient,
In practice, rather than computing this by hand, a scalar loss function,
is defined and an automatic differentiation library (such as Flux in Julia) handles the backpropagation automatically. The network parameters are then updated via,
When training on a mixture of problems with different horizon lengths , a naive sum over all transitions is biased toward longer episodes: a horizon- episode contributes twice as many gradient terms as a horizon- episode, even if both encode equally informative signal about the optimal policy. The entropy regularisation term makes this especially harmful — because the KL penalty is non-zero at every step, long episodes implicitly receive a heavier entropy bonus regardless of the reward structure.
To remove this bias, each transition from a horizon- episode is assigned a weight . Under this scheme every episode contributes a total weight of exactly to the loss, regardless of its length:
where is the number of episodes in the batch and is the horizon of the -th episode. Dividing by (not the total number of transitions) then gives a loss that is invariant to both the number of episodes and their length distribution.
In the tabular case, a gradient step at state updates only . In the neural network, because all states share the same weights , a gradient step at state also shifts the logits computed at every other state. This coupling is precisely what enables generalisation, but it also means that the network’s behaviour at unvisited states is shaped implicitly by the trajectories it has seen, for better or worse.
Both methods optimise the same objective through the same gradient ascent procedure; the difference lies entirely in how the policy is represented. The tabular approach is exact and local, making it a natural baseline, while the neural network trades locality for generalisation. In the next section, we step back from the iterative learning picture entirely and ask whether, for this specific problem, the optimal policy can be computed exactly, without any gradient steps at all.
← Back to the main article: RL Algorithms