#!/usr/bin/env python3 """Conditioning / amplification analysis of split patterns (Phase 3, Gate 3). Output: results/tables/weights_analysis.csv""" import sys, pathlib import numpy as np, pandas as pd ROOT = pathlib.Path(__file__).resolve().parents[1]; sys.path.insert(0, str(ROOT / "src")) from pamle.jackknife import vandermonde_weights_exact, leading_bias_coefficient, amplification_constant, weight_l1, vandermonde_condition_number PATTERNS = [(1,), (1, 2), (1, 2, 4), (1, 2, 4, 8), (1, 2, 4, 8, 16), (1, 2, 3), (1, 2, 3, 4), (1, 3), (1, 3, 9), (1, 2, 6), (1, 4)] rows = [] for s in PATTERNS: w = vandermonde_weights_exact(s); r = len(s) rows.append({"pattern": "-".join(map(str, s)), "r": r, "weights": " ".join(str(x) for x in w), "beta_r": str(leading_bias_coefficient(s)), "beta_r_float": float(leading_bias_coefficient(s)), "A_r": str(amplification_constant(s)), "A_r_float": float(amplification_constant(s)), "sum_abs_w": float(weight_l1(s)), "cond_vandermonde": vandermonde_condition_number(s), "local_fits": sum(s), "data_passes": r, "finest_block_fraction": f"1/{s[-1]}", "float64_moment_residual": max(abs(float(sum(float(wj) * sj ** a for wj, sj in zip(w, s)))) for a in range(1, r)) if r > 1 else 0.0}) df = pd.DataFrame(rows); (ROOT / "results" / "tables").mkdir(parents=True, exist_ok=True) df.to_csv(ROOT / "results" / "tables" / "weights_analysis.csv", index=False) print(df[["pattern", "r", "weights", "beta_r", "A_r", "sum_abs_w", "cond_vandermonde", "local_fits"]].to_string(index=False))