Counterfactually-Guided Policy Search (CF-GPS)
- Counterfactually-Guided Policy Search (CF-GPS) is a reinforcement learning framework using structural causal models to perform policy evaluation and improvement in partially observable environments.
- It leverages counterfactual inference on real logged data to generate model-based rollouts, thereby reducing bias and variance compared to traditional synthetic rollouts or importance sampling methods.
- Empirical results on tasks like PO-Sokoban demonstrate that CF-GPS achieves near-zero policy evaluation error when fully conditioned on observations, outperforming conventional model-based planning algorithms.
Counterfactually-Guided Policy Search (CF-GPS) is a framework for reinforcement learning in partially-observable Markov decision processes (POMDPs) that leverages structural causal models (SCMs) to perform policy evaluation and search via counterfactual inference. Key to the method is conditioning model-based rollouts on real, logged data to reduce bias and variance, contrasting with de novo synthetic rollouts or importance sampling approaches. CF-GPS generalizes prior methods such as Guided Policy Search and can be related to value gradient approaches through the lens of counterfactual structural inference (Buesing et al., 2018).
1. Formal Foundations: POMDPs and Structural Causal Models
CF-GPS operates within the episodic POMDP setting. Let be the hidden state space, the action space, and the observation space. The agent trajectory is with the stochastic policy over the full action-observation history . Transition and observation kernels are and respectively, and the undiscounted return is , where is included in 0.
The entire generative process of the POMDP plus policy 1 is encoded as a structural causal model 2, with scenario (noise) variables 3 encoding randomness in initial state, transitions, observations, and policy actions. Deterministic mechanisms 4 map scenario variables to process variables; for instance, 5 and 6.
Interventions—substituting the policy mechanism 7 by another policy 8—correspond to the standard SCM operation 9, yielding the SCM 0 and corresponding trajectory distribution 1.
2. Counterfactual Evaluation in SCMs
Given observed variables 2, an intervention 3 (e.g., 4), and query variables 5, the counterfactual distribution 6 is obtained by:
- Inferring scenario variables 7 from 8.
- Fixing 9 to the sampled value, applying the intervention, and forward-simulating the new mechanism.
- Returning the queried variables.
Algorithmically, this involves: sampling 0, replacing 1 with a delta function at 2, altering mechanisms per 3, and simulating 4. Averaging over real data 5 ensures unbiased estimation: 6.
For policy evaluation (CF-PE), with off-policy dataset 7, the counterfactual value estimator for candidate 8 is
9
Under a correct model, 0.
3. The CF-GPS Algorithm and Policy Improvement
CF-GPS alternates between logging real experience and model-based planning, with simulated rollouts "grounded" in inferred scenarios from observed episodes. Each logged episode 1 is used to derive a posterior over scenario variables 2. Multiple counterfactual rollouts are generated for each 3 under a planner or candidate policy 4.
Policy improvement then proceeds using a return-weighted regression objective, with rollouts from the counterfactual distribution,
5
Here, each trajectory 6 is simulated conditioned on the inferred 7 ("posterior grounding") instead of starting from the prior, thereby reducing model mismatch.
CF-GPS Algorithmic Outline
4
CF-GPS can incorporate a "planner" 8 that uses an expert policy or current policy, allowing for annealed mixtures.
4. Methodological Comparisons and Theoretical Insights
CF-GPS situates itself among multiple strands of reinforcement learning:
- Vanilla model-based RL (MB-PE, MB-PS): These approaches draw scenario variables from the model prior 9, leading to biased results under model mismatch between 0 and the true environment.
- Importance-Sampling off-policy methods: Reweight logged returns according to trajectory likelihood ratios 1. While unbiased, these methods suffer from high variance if 2 and 3 differ significantly or lack mutual support.
CF-GPS achieves bias reduction by sampling from the posterior 4, grounding rollouts in real experience. Variance is reduced by generating counterfactual trajectories under fixed scenario noise, randomizing only action noise if needed, and dispensing with trajectory-level importance weighting.
Relations to Other RL Methods
- Guided Policy Search (GPS): GPS, as in Levine & Koltun (2014), is a special case of CF-GPS for fully-observed MDPs with linear-Gaussian SCMs and LQR planners. Here, linear dynamics parameters inferred from real data act as counterfactual scenario inference.
- Stochastic Value Gradient (SVG): SVG interprets policy and model computation as deterministic functions of shared noise 5, making inference over 6 and freezing 7 equivalent to counterfactual trajectory analysis and gradient estimation.
5. Empirical Evaluation and Benchmarking
CF-GPS performance is evaluated on the PO-Sokoban grid-world benchmark:
- Environment: 8 grid, 3 boxes, 3 targets, strong partial observability (each tile flipped to empty with 9 probability in observation), episode length 0, structured rewards.
- Scenario variables: The initial level layout 1, inferred for each episode.
Off-policy Evaluation (CF-PE)
- Model 2 is learned only over initial state distribution 3; transitions/observations are assumed known.
- Three policies 4 are trained under a uniform behavior 5.
- Value estimates using MB-PE (6) incur high error (7). As more transitions are conditioned on (8), error drops to near zero. Importance-sampling approaches perform poorly (error 9).
Policy Search (CF-GPS)
- Logged data are collected by 64 actors under the behavior policy 0.
- Scenario inference 1 utilizes DRAW.
- The planner 2 is an annealed mixture of the current policy and an expert.
- Each scenario supports 10 counterfactual rollouts, used for return-weighted regression policy updates.
Key Outcomes
- Counterfactual policy evaluation error approaches zero with full smoothing, versus large errors for purely prior-based simulations.
- CF-GPS learning curves surpass both vanilla model-based planning and GPS-like baselines that do not fully condition on observations.
- Given the same real data budget, CF-GPS outperforms model-free IMPALA.
6. Context, Limitations, and Generalizations
CF-GPS formalizes model-based policy learning as counterfactual inference with SCMs, centering the role of posterior scenario inference in reducing bias otherwise endemic to model-simulator approaches. The methodology assumes correct or well-calibrated models for scenario variable inference; model errors can propagate into policy search steps. The generalization to fully-observed MDPs and incorporation of planners or experts in 3 broadens applicability, subsuming Guided Policy Search and linking to Stochastic Value Gradient methods ("reparameterization-based algorithms can be interpreted as counterfactual methods"). This suggests potential for further theoretical unification and practical extensions in RL.
7. References
- Buesing, L., Weber, T., Zwols, Y., Racanière, S., Guez, A., Lespiau, J.-B., & Heess, N. (2019). "Woulda, Coulda, Shoulda: Counterfactually-Guided Policy Search" (Buesing et al., 2018).
- Pearl, J. (2009). Causality. Cambridge University Press.
- Levine, S., & Koltun, V. (2014). "Guided policy search." ICML.
- Heess, N., et al. (2015). "Learning continuous control policies by stochastic value gradients." NIPS.