A research implementation investigating the use of negative probabilities (quasi-probabilities) for counterfactual reasoning and bidirectional temporal navigation in reinforcement learning.
This project explores whether negative Q-values can enable better learning through counterfactual reasoning - asking "what if I had acted differently?" without physically resetting the environment.
Inspiration: Feynman path integrals in quantum mechanics, where paths going "backward in time" contribute to probability amplitudes.
Key Question: Can RL agents benefit from reasoning about past decisions and hypothetical alternatives?
This repository contains:
-
qp_rl_v2/- Clean, research-grade implementation- Quasi-probability agents (with/without backward reasoning)
- Classical Q-learning baseline
- Test environments (trap mazes, corridors, four rooms)
- Visualization suite
- Experiment runner
-
qp_rl_project/- Original implementation (historical) -
Documentation:
THEORY.md- Mathematical frameworkINSIGHT.md- Why counterfactual inference is hardSTATUS.md- Project status and next stepsFINAL_SUMMARY.md- Complete analysis and recommendations
- Reset environment to past states
- Try different actions with current knowledge
- Result: -331% vs. classical Q-learning (wastes samples)
- Don't reset, just update beliefs about past
- Infer "what if I had acted differently?"
- Result: -355% vs. classical Q-learning (fabricates experience)
- Learn dynamics model P(s'|s,a)
- Use model for accurate counterfactuals
- Could actually work!
Counterfactual reasoning in model-free RL is challenging because you don't know what would have happened on alternative paths. Both backward jumps and pure inference corrupt learning.
However, this could work with:
- Model-based RL (learned dynamics)
- Simulators (can reset to any state)
- Different applications (exploration bonuses, not action selection)
# Install dependencies
pip3 install numpy matplotlib --break-system-packages
# Run main experiments (compares QP-RL vs. Classical)
python3 run_experiments.py --episodes 500 --runs 3
# Test counterfactual reasoning
python3 test_counterfactual.py
# Results saved to results_v2/| Agent | Trap Maze Performance | Success Rate |
|---|---|---|
| Classical Q-Learning | 0.86 reward, 9 steps | 98% |
| QP-RL (backward jumps) | -1.35 reward, 42 steps | 55% |
| Counterfactual (inference) | -2.18 reward, 62 steps | 72% |
Conclusion: Quasi-probability approaches underperform classical Q-learning in model-free settings.
Despite negative empirical results, this work contributes:
- Theoretical framework for quasi-probabilities in RL
- Rigorous experimental methodology with proper baselines
- Understanding of why counterfactual reasoning is hard in model-free RL
- Path forward: Model-based extensions, different applications
✅ Workshop paper: Negative results with theoretical contribution
qp_rl_v2/- Main implementationTHEORY.md- Mathematical frameworkINSIGHT.md- Analysis of challengesFINAL_SUMMARY.md- Complete summaryrun_experiments.py- Experiment runnertest_counterfactual.py- Test counterfactual approach
- Model-based RL: Learn dynamics, use for counterfactuals
- Different applications: Exploration bonuses, not action selection
- Theoretical analysis: Convergence proofs, sample complexity
MIT License