Counterfactual-tracking policy ensemble
Implementation & benchmark of arXiv:2607.13029 — Online Control via Counterfactual Tracking
Source paper: Online Control via Counterfactual Tracking arXiv:2607.13029 ⓘ · analyzed Aug 30, 2026
AI-generated research hypothesis, automatically tested. Not peer-reviewed.
Idea description
Maintain a posterior over heterogeneous neural policies, simulate each policy on the same revealed disturbance sequence, and track a posterior-weighted counterfactual reference instead of directly switching among deployed policies. A stabilizing feedback correction keeps the physical state close to the reference, while exponential-weights updates favor policies with low counterfactual cost.
Formulas
Mathematical statement
The plant is the linear dynamical system \(x_{t+1}=Ax_t+Bu_t+w_t\), where \(x_t\in\mathbb{R}^n\) is the physical state, \(u_t\in\mathbb{R}^m\) is the applied control, \(A,B\) are known matrices, and \(w_t\) is the realized disturbance satisfying \(\lVert w_t\rVert\le W\). For policy \(\pi_i\), its counterfactual trajectory is \(\hat u_{i,t}=\pi_i(\hat x_{i,0:t},c_{1:t-1})\) and \(\hat x_{i,t+1}=A\hat x_{i,t}+B\hat u_{i,t}+w_t\), where \(c_s\) is the revealed cost function at time \(s\). The exponential-weights posterior has PAC-Bayes dependence \(O(\sqrt{T\,\mathrm{KL}(q\|p)})\), and for a finite class of \(N\) policies the target regret is \(O(\sqrt{T\log N})\). Here \(p\) is the prior over policies, \(q\) is the learned posterior, and \(T\) is the horizon. The tracking action is \(u_t=\bar u_t-K(x_t-\bar x_t)\), where \(K\) is selected so that \(F=A-BK\) is stable, and \((\bar x_t,\bar u_t)\) is a posterior-weighted counterfactual reference. The tracking error \(e_t=x_t-\bar x_t\) follows \(e_{t+1}=Fe_t\) when the reference uses the same disturbance sequence. A bounded impulse-response gain \(G_H=\sum_{k=0}^{H}\lVert F^k\rVert_2\) limits accumulated error over a finite horizon. If each convex cost is locally \(L_c\)-Lipschitz, tracking error contributes at most approximately \(L_c\sum_t\lVert e_t\rVert\) to excess cost.
Implementation notes
(1) Exact integration point: place the method between a neural policy ensemble and the environment action interface in an online RL or model-based control loop. Each member may be an MLP, GRU, transformer policy, or saved checkpoint with its own hidden state. Start with a known linear simulator \(x_{t+1}=Ax_t+Bu_t+w_t\), then test a locally identified model. Choose \(K\) offline using discrete LQR or pole placement so that \(F=A-BK\) has spectral radius below one. The wrapper changes the action immediately before environment execution. (2) Pseudocode: initialize \(q_i=1/N\), counterfactual states \(\hat x_i=x_0\), and hidden states \(h_i\). At each time \(t\), compute \(\hat u_i=\pi_i(\hat x_i,h_i)\) for every policy; compute \(\bar x=\sum_i q_i\hat x_i\) and \(\bar u=\sum_i q_i\hat u_i\); execute \(u=\bar u-K(x_t-\bar x)\), with optional actuator clipping; observe \(c_t\), \(x_{t+1}\), and recover the disturbance \(w_t=x_{t+1}-Ax_t-Bu_t\). Evaluate each counterfactual loss \(\ell_i=c_t(\hat x_i,\hat u_i)\), update \(q_i\leftarrow q_i\exp(-\eta\ell_i)\), normalize the weights, and advance every simulator using \(\hat x_i\leftarrow A\hat x_i+B\hat u_i+w_t\). (3) Compute counterfactual trajectories and exponential weights exactly. Estimate the finite-horizon impulse gain from \(G_H=\sum_{k=0}^{H}\lVert F^k\rVert_2\), using matrix powers; estimate the local cost Lipschitz constant from gradients or finite differences. Normalize costs to \([0,L]\) and initialize \(\eta=\sqrt{2\log N/(T L^2)}\), with a small validation grid for robustness. The mathematical prediction is the \(\sqrt{T\log N}\) selection term; the neural adaptation must empirically test whether the plant model and bounded-reference assumptions hold. (4) First cheap experiment: use a 4- to 8-dimensional stable linear system with bounded adversarial disturbances, four heterogeneous controllers consisting of an MLP, GRU, transformer policy, and poor baseline, and convex quadratic costs. Compare direct Hedge action selection, the best fixed policy, and counterfactual tracking at equal environment interactions. Record cumulative cost, maximum state norm, posterior concentration, tracking error, and action magnitude. Success means substantially lower worst-case state norm than direct switching with similar cumulative cost, plus cumulative regret approaching the best policy with an empirical slope consistent with \(\sqrt{T\log N}\).
Verification
Stage 1 · Toy mechanism gate: Passed ✓
Stage 2 · Mechanism transferred to benchmark: Confirmed ✓
Stage 2 · Practical benchmark result: Inconclusive
Methodology: 8 paired seeds, permutation test (p<0.05) against a learning-rate-tuned baseline. How verification works
Stage 1 — Mechanism check agent confidence 8/10
Built a self-contained counterfactual-tracking ensemble simulator with exponential-weights updates, disturbance sharing, LQR feedback correction, and direct-switching comparison. The stability boundary, finite-horizon impulse-gain formula, and Hedge square-root regret scaling all matched numerical predictions. Tracking reduced cumulative cost by 29.6% versus direct switching, although maximum state magnitude was identical in this benign toy setup.
- Agent confidence
- 8/10
- Baseline
- Direct posterior-argmax switching: cumulative cost 7.58885, max |state| 1.5, mean tracking error 0.01652, mean |action| 0.05286.
- Idea
- Counterfactual tracking: cumulative cost 5.34496, max |state| 1.5, mean tracking error 0.000616, mean |action| 0.04977; cost ratio 0.7043. Stability prediction matched the |gamma|=1 boundary; impulse-gain relative error was at most 2e-16; Hedge log-log regret slope was 0.5075.
Limitations: The ensemble uses fixed scalar linear-controller surrogates rather than MLP, GRU, or transformer policies. The plant is one-dimensional, known, and benign; model mismatch, actuator failure, adversarial disturbances, partial observability, neural adaptation, and larger multidimensional systems were not tested. The maximum-state metric did not distinguish tracking from switching in this run.
How to run: python3 experiment.py
Stage 2 — Benchmark vs. tuned baseline (arXiv:2607.13029)
Ahead of the baseline (−4.3%) but not statistically significant (p=0.5872, wins 6 / 8 paired seeds).
- Benchmark
- Dynamics forecasting
- Model
- rnn_small
- Paired seeds
- 8
- Baseline mean
- 0.0008
- Idea mean
- 0.0008
- Effect (Δ)
- -0 (−4.3%; negative = idea better)
- Wins
- 6 / 8 paired seeds
- p-value
- 0.5872 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±18.2%
- Mechanism
- Confirmed ✓
- Practical effect
- Inconclusive
- Baseline tuning
- swept over 3 configs
The registered dynamics benchmark is a supervised rollout-prediction task, not a live online environment with revealed disturbances and physical-state feedback. The implementation therefore tests posterior aggregation of independently trained rnn_small predictors rather than full actuator-level counterfactual tracking; model mismatch, adversarial disturbances, larger policy classes, and repeated independent benchmark replications were not tested.
How to run: python3 stage2_bench.py
Verdict computed by deterministic test code from paired-seed statistics — not by the language model.
Stage 2 — Benchmark latest Failed ✗
Agent confidence: 8/10
Implemented counterfactual exponential-weights aggregation over independently trained rnn_small policies on the registered dynamics track, with identical training budgets, shared hyperparameter sweep, tuned baseline, and 8 paired seeds. Mean test MSE improved slightly from 0.0008369722 to 0.0008009700, but the paired permutation test was non-significant (delta=-0.0000360022, p=0.5872), so the idea did not produce a validated benchmark win.
- Baseline
- Uniform rnn_small ensemble; best cfg lr=0.006, eta=2.0; mean test MSE 0.0008369722.
- Idea
- Exponential-weights rnn_small ensemble; best cfg lr=0.006, eta=2.0; mean test MSE 0.0008009700; 6/8 paired wins; p=0.5872.
Benchmark result
Ahead of the baseline (−4.3%) but not statistically significant (p=0.5872, wins 6 / 8 paired seeds).
- Benchmark
- Dynamics forecasting
- Model
- rnn_small
- Paired seeds
- 8
- Baseline mean
- 0.0008
- Idea mean
- 0.0008
- Effect (Δ)
- -0 (−4.3%; negative = idea better)
- Wins
- 6 / 8 paired seeds
- p-value
- 0.5872 (permutation test, 20 000 shuffles)
- Smallest detectable effect
- ±18.2%
- Mechanism
- Confirmed ✓
- Practical effect
- Inconclusive
- Baseline tuning
- swept over 3 configs
The registered dynamics benchmark is a supervised rollout-prediction task, not a live online environment with revealed disturbances and physical-state feedback. The implementation therefore tests posterior aggregation of independently trained rnn_small predictors rather than full actuator-level counterfactual tracking; model mismatch, adversarial disturbances, larger policy classes, and repeated independent benchmark replications were not tested.
How to run: python3 stage2_bench.py
Artifacts
- bench_report.json 3.6 KB View Raw
- experiment.py 6.2 KB View Raw
- report.md 1.5 KB View
- report_bench_2026-08-31T014423.md 5.5 KB View
- results.json 5.0 KB View Raw
- stage2_bench.py 4.7 KB View Raw