"""Claim 3: chunk-level branched rollout tightens the value-gap bound. Paper: "Towards Practical World Model-based RL for Vision-Language-Action Models" (VLA-MBPO), arXiv:2603.20607, OpenReview yKQ8GrwEhr. Four independent checks: A. Case-study constants. At gamma=0.99, k=10, n=2 the paper states the prior bound is ~4183 eps_pi^k + 18916 eps_m (Thm 4.1) and VLA-MBPO's is ~1710 eps_pi^k + 400 eps_m^{k,n} (Thm 4.2). Recompute from the formulas. B. Derivation. Thm 4.2 (Eq. 7) should follow from Lemma A.4 (Eq. 20) by substituting eps_m^{k,pre}=0 (pre-branch dynamics are real data) and eps_pi^{k,post}=0 (post-branch it is the same policy in both). Checked symbolically with sympy. C. Unit-fairness. Thm 4.1's eps_m is a *step-level* TV error; Thm 4.2's eps_m^{k,n} is a *chunk-level* one. They are not the same quantity, so the headline 18916 -> 400 comparison is not apples-to-apples. Re-do it under the honest identification eps_m^{k,n} <= k * eps_m (Lemma A.2). D. Empirical. Tabular sparse-reward L-MDP with a perturbed ("learned") model. Measure the ACTUAL value-estimation error of an n-chunk branched rollout vs a full-horizon rollout from the same data distribution, and check both theorems' bounds actually hold. """ import argparse import json import os import platform import time import numpy as np # ---------------------------------------------------------------------------- # A. Case-study constants # ---------------------------------------------------------------------------- def bound_thm41(gamma, k, rmax=1.0): """Thm 4.1 / B.1: chunk-level policy, step-level world model, full horizon. |V - V_hat| <= 2rmax/(1-g) * [ 2g^k/(1-g^k) eps_pi + 2 eps_pi + k g^k/(1-g^k) eps_m ] Returns (coef_on_eps_pi, coef_on_eps_m). """ gk = gamma ** k pre = 2.0 * rmax / (1.0 - gamma) c_pi = pre * (2.0 * gk / (1.0 - gk) + 2.0) c_m = pre * (k * gk / (1.0 - gk)) return c_pi, c_m def bound_thm42(gamma, k, n, rmax=1.0): """Thm 4.2: chunk-level policy, chunk-level world model, n-chunk branched. |V - V_hat^branch| <= 2rmax/(1-g) * [ (g^k)^{n+1}/(1-g^k) eps_pi + (g^k)^n eps_pi + n eps_m^{k,n} ] Returns (coef_on_eps_pi, coef_on_eps_m_chunk). """ gk = gamma ** k pre = 2.0 * rmax / (1.0 - gamma) c_pi = pre * (gk ** (n + 1) / (1.0 - gk) + gk ** n) c_m = pre * n return c_pi, c_m def check_case_study(): gamma, k, n = 0.99, 10, 2 c_pi_41, c_m_41 = bound_thm41(gamma, k) c_pi_42, c_m_42 = bound_thm42(gamma, k, n) paper = {"thm41_pi": 4183.0, "thm41_m": 18916.0, "thm42_pi": 1710.0, "thm42_m": 400.0} got = {"thm41_pi": c_pi_41, "thm41_m": c_m_41, "thm42_pi": c_pi_42, "thm42_m": c_m_42} rows = [] for key in paper: # The paper reports these as "approximately" N and truncates rather than # rounds (4183.32->4183, 18916.58->18916, 1710.78->1710). Compare with a # small epsilon so binary float noise (400.0 stored as 399.99999...) # does not floor to 399. ok = abs(np.floor(got[key] + 1e-6) - paper[key]) < 1e-9 rows.append({"quantity": key, "paper": paper[key], "recomputed": got[key], "floor_matches": bool(ok)}) return {"gamma": gamma, "k": k, "n": n, "rows": rows, "all_match": all(r["floor_matches"] for r in rows)} # ---------------------------------------------------------------------------- # B. Symbolic derivation check: Thm 4.2 from Lemma A.4 # ---------------------------------------------------------------------------- def check_derivation(): import sympy as sp g, k, n, rmax = sp.symbols("gamma k n r_max", positive=True) e_post_m, e_post_pi, e_pre_m, e_pre_pi = sp.symbols( "eps_m_post eps_pi_post eps_m_pre eps_pi_pre", nonnegative=True) gk = g ** k # Lemma A.4 (Eq. 20) lemA4 = 2 * rmax / (1 - g) * ( n * e_post_m + (n + 1) * e_post_pi + gk ** (n + 1) * (e_pre_m + e_pre_pi) / (1 - gk) + gk ** n * e_pre_pi ) # Branched rollout: pre-branch states come from the real offline dataset, so # pre-branch dynamics error is zero; post-branch the same policy is used in # both the real env and the model, so post-branch policy error is zero. e_m_chunk, e_pi = sp.symbols("eps_m_kn eps_pi_k", nonnegative=True) substituted = lemA4.subs({e_pre_m: 0, e_post_pi: 0, e_post_m: e_m_chunk, e_pre_pi: e_pi}) # Thm 4.2 (Eq. 7) as printed in the paper thm42 = 2 * rmax / (1 - g) * ( gk ** (n + 1) / (1 - gk) * e_pi + gk ** n * e_pi + n * e_m_chunk) diff = sp.simplify(sp.expand(substituted - thm42)) return {"lemma_A4": str(lemA4), "after_substitution": str(substituted), "theorem_4_2": str(thm42), "difference": str(diff), "identical": bool(diff == 0)} # ---------------------------------------------------------------------------- # C. Unit-fairness: chunk-level vs step-level model error # ---------------------------------------------------------------------------- def check_unit_fairness(gamma=0.99, k=10, n=2): """Thm 4.1's eps_m is per *step*; Thm 4.2's eps_m^{k,n} is per *chunk*. Lemma A.2 gives D_TV(P1(s_t)||P2(s_t)) <= t*delta, so a chunk-level model built by composing a step-level model k times satisfies eps_m^{k,n} <= k * eps_m. Re-express Thm 4.2's model term in step-level units to compare like with like. """ _, c_m_41 = bound_thm41(gamma, k) c_pi_42, c_m_42_chunk = bound_thm42(gamma, k, n) c_m_42_steplevel = c_m_42_chunk * k # eps_m^{k,n} <= k * eps_m return { "gamma": gamma, "k": k, "n": n, "thm41_model_coef_step_units": c_m_41, "thm42_model_coef_chunk_units": c_m_42_chunk, "thm42_model_coef_step_units": c_m_42_steplevel, "headline_ratio_as_printed": c_m_41 / c_m_42_chunk, "ratio_in_matched_step_units": c_m_41 / c_m_42_steplevel, } def sweep_bounds(): """Does branching tighten the bound across (gamma, k, n)? Both as printed and under matched step-level units.""" out = [] for gamma in (0.9, 0.95, 0.99, 0.995): for k in (2, 5, 10, 20): for n in (1, 2, 4, 8): c_pi41, c_m41 = bound_thm41(gamma, k) c_pi42, c_m42 = bound_thm42(gamma, k, n) out.append({ "gamma": gamma, "k": k, "n": n, "thm41_pi": c_pi41, "thm41_m": c_m41, "thm42_pi": c_pi42, "thm42_m_chunk": c_m42, "thm42_m_step": c_m42 * k, "pi_tighter": bool(c_pi42 < c_pi41), "m_tighter_as_printed": bool(c_m42 < c_m41), "m_tighter_matched_units": bool(c_m42 * k < c_m41), }) return out # ---------------------------------------------------------------------------- # D. Empirical validation on a tabular sparse-reward L-MDP # ---------------------------------------------------------------------------- class TabularLMDP: """Sparse binary reward: r(s)=1 on a single goal state, 0 elsewhere.""" def __init__(self, n_states, n_actions, gamma, rng): self.S, self.A, self.gamma = n_states, n_actions, gamma # Sparse-ish random transitions (Dirichlet -> concentrated). self.T = rng.dirichlet(np.ones(n_states) * 0.3, size=(n_states, n_actions)) self.r = np.zeros(n_states) self.goal = n_states - 1 self.r[self.goal] = 1.0 def chunk_transition(self, policy_chunk, k): """P(s'|s) after executing k steps under a chunk policy, plus the discounted in-chunk reward. policy_chunk: (S, A**k) over action chunks.""" S, A = self.S, self.A chunks = np.array(np.meshgrid(*[np.arange(A)] * k, indexing="ij")).reshape(k, -1).T Tk = np.zeros((S, S)) rk = np.zeros(S) for ci, chunk in enumerate(chunks): # distribution over states starting deterministically at each s dist = np.eye(S) rew = np.zeros(S) disc = 1.0 for a in chunk: dist = dist @ self.T[:, a, :] rew += disc * dist @ self.r disc *= self.gamma w = policy_chunk[:, ci][:, None] Tk += w * dist rk += policy_chunk[:, ci] * rew return Tk, rk def value_of_markov_chain(Tk, rk, gamma_k): """V = (I - gamma_k Tk)^-1 rk""" S = Tk.shape[0] return np.linalg.solve(np.eye(S) - gamma_k * Tk, rk) def tv_rows(P, Q): return 0.5 * np.abs(P - Q).sum(axis=-1) def run_empirical(seed, n_states=8, n_actions=2, k=3, gamma=0.9, model_noise=0.05, policy_noise=0.15, n_list=(1, 2, 3, 4, 6, 8, 12, 16)): rng = np.random.default_rng(seed) env = TabularLMDP(n_states, n_actions, gamma, rng) # A "learned" model: perturb the true step-level transitions. noise = rng.dirichlet(np.ones(n_states) * 0.3, size=(n_states, n_actions)) That = (1 - model_noise) * env.T + model_noise * noise model = TabularLMDP(n_states, n_actions, gamma, rng) model.T, model.r, model.goal = That, env.r, env.goal # step-level model error eps_m (max over s,a of TV) -- upper bound on the # data-distribution expectation used in the theorem. eps_m_step = float(tv_rows(env.T, That).max()) # Chunk policies: behaviour pi_D and target pi (a perturbation of it). n_chunks = n_actions ** k pi_D = rng.dirichlet(np.ones(n_chunks), size=n_states) pert = rng.dirichlet(np.ones(n_chunks), size=n_states) pi = (1 - policy_noise) * pi_D + policy_noise * pert eps_pi_k = float(tv_rows(pi_D, pi).max()) gk = gamma ** k Tk_true, rk_true = env.chunk_transition(pi, k) Tk_model, rk_model = model.chunk_transition(pi, k) # chunk-level model error eps_m^{k,n} eps_m_chunk = float(tv_rows(Tk_true, Tk_model).max()) V_true = value_of_markov_chain(Tk_true, rk_true, gk) V_model_full = value_of_markov_chain(Tk_model, rk_model, gk) # Offline data distribution D: occupancy of the behaviour policy. TkD, _ = env.chunk_transition(pi_D, k) d = np.ones(n_states) / n_states for _ in range(500): d = d @ TkD d = d / d.sum() # Full-horizon rollout in the model, started from D. gap_full = float(np.abs(d @ (V_model_full - V_true))) # n-chunk branched rollout: n chunks in the MODEL from s~D, then bootstrap # with the TRUE value. Same start distribution, so directly comparable. results_n = [] for n in n_list: Vb = V_true.copy() for _ in range(n): Vb = rk_model + gk * Tk_model @ Vb gap_branch = float(np.abs(d @ (Vb - V_true))) c_pi42, c_m42 = bound_thm42(gamma, k, n) bound42 = c_pi42 * eps_pi_k + c_m42 * eps_m_chunk results_n.append({ "n": n, "gap_branch": gap_branch, "bound_thm42": float(bound42), "bound_holds": bool(gap_branch <= bound42 + 1e-9), }) c_pi41, c_m41 = bound_thm41(gamma, k) bound41 = c_pi41 * eps_pi_k + c_m41 * eps_m_step return { "seed": seed, "gamma": gamma, "k": k, "eps_pi_k": eps_pi_k, "eps_m_step": eps_m_step, "eps_m_chunk": eps_m_chunk, "eps_m_chunk_le_k_eps_m_step": bool(eps_m_chunk <= k * eps_m_step + 1e-9), "gap_full_horizon": gap_full, "bound_thm41": float(bound41), "bound41_holds": bool(gap_full <= bound41 + 1e-9), "branched": results_n, } def main(): ap = argparse.ArgumentParser() ap.add_argument("--seeds", type=int, default=200) ap.add_argument("--out", default="outputs/claim3") args = ap.parse_args() os.makedirs(args.out, exist_ok=True) t0 = time.time() print("=" * 78) print("A. Case-study constants (gamma=0.99, k=10, n=2)") print("=" * 78) cs = check_case_study() for r in cs["rows"]: print(f" {r['quantity']:>10s} paper={r['paper']:>9.1f} " f"recomputed={r['recomputed']:>12.4f} floor-match={r['floor_matches']}") print(f" ALL MATCH: {cs['all_match']}") print() print("=" * 78) print("B. Theorem 4.2 derives from Lemma A.4?") print("=" * 78) dv = check_derivation() print(f" substituted - thm4.2 = {dv['difference']}") print(f" IDENTICAL: {dv['identical']}") print() print("=" * 78) print("C. Unit fairness of the 18916 -> 400 comparison") print("=" * 78) uf = check_unit_fairness() print(f" Thm4.1 model coef (step units): {uf['thm41_model_coef_step_units']:.1f}") print(f" Thm4.2 model coef (chunk units, printed): {uf['thm42_model_coef_chunk_units']:.1f}") print(f" Thm4.2 model coef (step units, eps^kn<=k*eps_m): {uf['thm42_model_coef_step_units']:.1f}") print(f" ratio as printed: {uf['headline_ratio_as_printed']:.1f}x") print(f" ratio in matched units: {uf['ratio_in_matched_step_units']:.1f}x") sweep = sweep_bounds() n_pi = sum(r["pi_tighter"] for r in sweep) n_m_print = sum(r["m_tighter_as_printed"] for r in sweep) n_m_match = sum(r["m_tighter_matched_units"] for r in sweep) print(f" sweep over {len(sweep)} (gamma,k,n) configs:") print(f" policy-error coef tighter under Thm4.2: {n_pi}/{len(sweep)}") print(f" model-error coef tighter (as printed): {n_m_print}/{len(sweep)}") print(f" model-error coef tighter (matched): {n_m_match}/{len(sweep)}") print() print("=" * 78) print(f"D. Empirical tabular L-MDP validation ({args.seeds} random MDPs)") print("=" * 78) emp = [run_empirical(s) for s in range(args.seeds)] b41_ok = sum(e["bound41_holds"] for e in emp) b42_ok = sum(all(b["bound_holds"] for b in e["branched"]) for e in emp) chunk_ok = sum(e["eps_m_chunk_le_k_eps_m_step"] for e in emp) print(f" Thm 4.1 bound held: {b41_ok}/{len(emp)}") print(f" Thm 4.2 bound held (all n): {b42_ok}/{len(emp)}") print(f" eps_m^(k,n) <= k*eps_m held: {chunk_ok}/{len(emp)}") ns = [b["n"] for b in emp[0]["branched"]] print() print(" Actual value-estimation error vs rollout length (mean over seeds):") mean_full = float(np.mean([e["gap_full_horizon"] for e in emp])) curve = [] for i, n in enumerate(ns): m = float(np.mean([e["branched"][i]["gap_branch"] for e in emp])) curve.append({"n": n, "mean_gap_branch": m, "ratio_vs_full": m / mean_full if mean_full else float("nan")}) print(f" n={n:>3d} chunks: gap={m:.5f} ({m / mean_full * 100:5.1f}% of full-horizon)") print(f" full horizon : gap={mean_full:.5f} (100.0%)") payload = { "meta": { "paper": "arXiv:2603.20607 (OpenReview yKQ8GrwEhr)", "claim": "Claim 3 - chunk-level branched rollout tightens the value-gap bound", "python": platform.python_version(), "numpy": np.__version__, "seconds": time.time() - t0, }, "A_case_study": cs, "B_derivation": dv, "C_unit_fairness": uf, "C_sweep": sweep, "D_empirical_summary": { "n_seeds": len(emp), "thm41_bound_held": b41_ok, "thm42_bound_held": b42_ok, "eps_chunk_le_k_eps_step_held": chunk_ok, "mean_gap_full_horizon": mean_full, "curve": curve, }, "D_empirical_runs": emp, } path = os.path.join(args.out, "claim3_results.json") with open(path, "w", encoding="utf-8") as f: json.dump(payload, f, indent=2) print(f"\nWrote {path} ({time.time() - t0:.1f}s)") if __name__ == "__main__": main()