SPB Git

spb/wp29_uqo

Public
3.4 KB · 84 lines python
1"""Replication entry point for F5-conf-03.2Run from workspace root:  ~/wp29/venv/bin/python out/analysis.py3Reads only data/, writes out/results.json and out/counterexample.csv deterministically.45Counterexample to A: X ~ N(0,1); W independent of X with P(W=1)=P(W=-1)=1/2; Y = W*X.6Y ~ N(0,1) by symmetry of N(0,1); X+Y = (1+W)X equals 0 w.p. 1/2 and 2X otherwise,7so it has an atom of mass 1/2 at 0 and is not a constant -> not normal (not even degenerate).8"""9import json, os10import numpy as np11import pandas as pd12from scipy import stats1314ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))15DATA = os.path.join(ROOT, "data")16OUT = os.path.join(ROOT, "out")1718props = pd.read_csv(os.path.join(DATA, "propositions.csv"))19design = pd.read_csv(os.path.join(DATA, "design.csv"))20data_issues = []21assert set(props["id"]) == {"A", "B"}, "unexpected proposition ids"22d = dict(zip(design["parameter"], design["value"]))23seed, n = int(d["seed"]), int(d["n"])2425# Verdicts: from the mathematical argument in out/argument.md (not from the simulation).26statement_true = False      # A is false (counterexample below)27statement_b_true = True     # B is true (characteristic-function / convolution proof)2829# ---- Counterexample sample (order of draws fixed: x first, then w) ----30rng = np.random.default_rng(seed)31x = rng.standard_normal(n)32w = rng.choice(np.array([-1.0, 1.0]), size=n)33y = w * x34s = x + y3536def ks_vs_fitted_normal(v):37    m, sd = v.mean(), v.std(ddof=1)38    return float(stats.kstest(v, "norm", args=(m, sd)).statistic)3940pd.DataFrame({"x": x, "y": y}).to_csv(os.path.join(OUT, "counterexample.csv"), index=False)4142cv = {43    "construction": ("X ~ N(0,1); W independent of X with P(W=1)=P(W=-1)=1/2; Y = W*X. "44                     "Then Y ~ N(0,1), and X+Y = (1+W)X is 0 with probability 1/2 and 2X otherwise "45                     "(atom of mass 1/2 at 0, non-constant), hence not normal."),46    "n": int(len(x)),47    "seed": seed,48    "mean_x": float(x.mean()), "sd_x": float(x.std(ddof=1)),49    "mean_y": float(y.mean()), "sd_y": float(y.std(ddof=1)),50    "mean_sum": float(s.mean()), "sd_sum": float(s.std(ddof=1)),51    "ks_sum_vs_normal": ks_vs_fitted_normal(s),52}5354# ---- Supplementary diagnostics (same KS rule) ----55# Baseline for B: independent normal partner Z drawn AFTER the counterexample draws from the same rng56z = rng.standard_normal(n)57supp = {58    "ks_x_vs_normal": ks_vs_fitted_normal(x),59    "ks_y_vs_normal": ks_vs_fitted_normal(y),60    "share_sum_exactly_zero": float(np.mean(s == 0.0)),61    "baseline_ks_independent_sum_vs_normal": ks_vs_fitted_normal(x + z),62    "corr_x_y": float(np.corrcoef(x, y)[0, 1]),63    "note": ("baseline_* uses Z ~ N(0,1) independent of X (proposition B setting), drawn after x and w "64             "from the same generator; KS statistics use parameters estimated from the sample."),65}6667results = {68    "task_id": "F5-conf-03",69    "statement_true": statement_true,70    "counterexample_provided": True,71    "counterexample_values": cv,72    "statement_b_true": statement_b_true,73    "feasibility": "complete",74    "feasibility_reason": None,75    "data_issues": data_issues,76    "n_input_rows": {"propositions.csv": int(len(props)), "design.csv": int(len(design))},77    "n_analysed": int(len(x)),78    "random_seed": seed,79    "supplementary": supp,80}81with open(os.path.join(OUT, "results.json"), "w") as f:82    json.dump(results, f, indent=2)83print(json.dumps(results, indent=2))84
Files · main
Menu

Theme