---
title: GRU Policy in Reinforcement Learning
url: https://www.emergentmind.com/topics/gated-recurrent-unit-gru-policy
type: topic
---

# GRU Policy in Reinforcement Learning

A Gated Recurrent Unit (GRU) Policy in reinforcement learning leverages the GRU neural architecture as a recurrent function approximator within fitted Q-iteration schemes, facilitating efficient policy learning in partially observable environments. The essence of the GRU policy is the use of GRU networks to estimate value functions, either $Q$-values or Advantage-values, from fixed-length sequences of discrete, one-hot encoded observations. Distinct from classical memoryless approaches, a GRU-based policy is capable of utilizing temporal memory to infer unobserved state information, thereby improving sample complexity and final policy quality in non-Markovian domains [1512.05509].

## 1. GRU Cell Architecture

The GRU cell operates at each time step $t$ on input $x_t$ and previous hidden state $h_{t-1}$, executing the following computations:
- Update gate:  
  $$ z_t = \sigma(W_z x_t + U_z h_{t-1} + b_z) $$
- Reset gate:  
  $$ r_t = \sigma(W_r x_t + U_r h_{t-1} + b_r) $$
- Candidate activation:  
  $$ \tilde{h}_t = \tanh(W_h x_t + U_h (r_t \odot h_{t-1}) + b_h) $$
- Hidden state update:  
  $$ h_t = (1-z_t) \odot h_{t-1} + z_t \odot \tilde{h}_t $$

Here, $\sigma$ denotes the logistic sigmoid, $\odot$ is element-wise multiplication, and $W_*$, $U_*$, $b_*$ are trainable parameters. In the examined architecture, each GRU layer is configured with 100 units.

## 2. Integration into Fitted Q-Iteration

The GRU policy is implemented as the function approximator $\hat Q(o; \theta)$ within the Neural Fitted Q-Iteration (NFQ) paradigm. The protocol comprises:
- Data collection: For each of 5000 episodes (max 500 steps per episode), the agent observes $o_t$, selects $a_t$ via softmax over $\hat Q(o_t; \theta)$ (temperature 0.5), receives $r_{t+1}$, and stores $(o_t, a_t, r_{t+1}, o_{t+1})$.
- Batch target computation: Every 10 episodes, for each transition, the target label is
  $$
  y_t = \hat Q(o_t, a_t; \theta_{\text{old}}) + \alpha \left[r_{t+1} + \gamma \max_{a'} \hat Q(o_{t+1}, a'; \theta_{\text{old}}) - \hat Q(o_t, a_t; \theta_{\text{old}}) \right]
  $$
  with update parameters $\alpha = 0.2$, $\gamma = 0.9$.
- Offline training: Sequences of up to 10 one-hot encoded observations (padded/truncated as needed) are fed into the network:  
  Input → Dense(100, tanh) → GRU(100) → Dense($|A|$, linear).  
  The mean-squared error between estimated and target values forms the loss. Optimization is performed with RMSProp or Adam, using batch size 10 and 2 epochs per update.

## 3. Advantage-Learning Variant

An alternative training regime is provided by Advantage-learning, where the value function takes the form $A(s, a) = Q(s, a) - V(s)$ with $V(s) = \max_{a} Q(s, a)$. The parameter update involves the temporal difference error:
$$
\delta_t = \max_{a} A(o_t, a) + \frac{r_{t+1} + \gamma \max_{a} A(o_{t+1}, a) - \max_{a} A(o_t, a)}{\kappa} - A(o_t, a_t)
$$
where $\kappa = 0.3$. The regression target is updated by  
$$
A_{k+1}(o_t, a_t) = A_k(o_t, a_t) + \alpha \delta_t
$$
with similar batch procedure as $Q$-learning. This approach tends to yield lower variance and faster convergence relative to standard $Q$-learning, except in stochastic environments where $Q$-learning may exhibit marginally faster learning [1512.05509].

## 4. Implementation Details and Hyperparameters

Key parameters and design choices follow:
- Input representation: Each observation scalar (e.g., $x \in \{0,\dots,9\}$, orientation $\in \{0,\dots,3\}$) is one-hot encoded and concatenated, yielding an input vector up to length 15.
- Sequence window: All training sequences are of fixed length 10 (with initial padding).
- Network layers: Dense(100, tanh) → GRU(100) → Dense($|A|$, linear); a softmax output is used for action selection during experience collection.
- Training regime:  
  - 5000 episodes per experiment  
  - Max 500 steps per episode  
  - Batch update every 10 episodes  
  - 2 training epochs per batch  
  - Batch size 10  
  - Per-update learning rate $\alpha = 0.2$, discount $\gamma = 0.9$  
- Computational profile: On the referenced hardware, GRU agents completed the full training sequence in approximately half the CPU time required by LSTM agents.

## 5. Empirical Results and Performance Metrics

Performance was quantified using two primary metrics:
- Learning time: The earliest step at which the mean reward over the ensuing 1000 steps surpasses –15 (with standard deviation $<$ 20).
- Learning performance: Maximum average reward achieved in any 1000-step interval.

Across multiple environments—especially partially observable grid worlds—GRU policies achieved faster convergence and higher final rewards than both LSTM and the evolutionary MUT1 architecture, with most pairwise improvements statistically significant at $p \leq 0.003$ (final reward $p < 10^{-4}$ versus LSTM). Advantage-learning further reduced reward variance and improved convergence speed, except in the stochastic variant. Reward curves confirm that GRU-based policies achieve superior early and final rewards relative to alternatives [1512.05509].

## 6. Practical Recommendations and Insights

- GRU cells combine parameter efficiency with robust temporal memory, making them well-suited for partially observable tasks with non-Markovian structure.
- Maintaining fixed-length (e.g., 10-step) history windows for recurrent input provides a favorable balance of representational capacity and computational cost.
- One-hot encoding of discrete observations is effective for input preprocessing.
- Small-batch, low-epoch retraining (every 10 episodes, 2 epochs) helps prevent overfitting.
- Monitoring both learning time and learning performance is critical when optimizing hyperparameters.
- Empirical evidence supports the use of GRUs over LSTM and evolved architectures (MUT1) under the fitted Q-iteration protocol in partially observable environments, both in terms of sample efficiency and computational overhead [1512.05509].

Source: https://www.emergentmind.com/topics/gated-recurrent-unit-gru-policy