SPB Git

spb/wp28_uqo

Public
1.6 KB · 21 lines python
1#!/usr/bin/env python32"""Conditioning / amplification analysis of split patterns (Phase 3, Gate 3). Output: results/tables/weights_analysis.csv"""3import sys, pathlib4import numpy as np, pandas as pd5ROOT = pathlib.Path(__file__).resolve().parents[1]; sys.path.insert(0, str(ROOT / "src"))6from pamle.jackknife import vandermonde_weights_exact, leading_bias_coefficient, amplification_constant, weight_l1, vandermonde_condition_number78PATTERNS = [(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)]9rows = []10for s in PATTERNS:11    w = vandermonde_weights_exact(s); r = len(s)12    rows.append({"pattern": "-".join(map(str, s)), "r": r, "weights": " ".join(str(x) for x in w),13                 "beta_r": str(leading_bias_coefficient(s)), "beta_r_float": float(leading_bias_coefficient(s)),14                 "A_r": str(amplification_constant(s)), "A_r_float": float(amplification_constant(s)),15                 "sum_abs_w": float(weight_l1(s)), "cond_vandermonde": vandermonde_condition_number(s),16                 "local_fits": sum(s), "data_passes": r, "finest_block_fraction": f"1/{s[-1]}",17                 "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})18df = pd.DataFrame(rows); (ROOT / "results" / "tables").mkdir(parents=True, exist_ok=True)19df.to_csv(ROOT / "results" / "tables" / "weights_analysis.csv", index=False)20print(df[["pattern", "r", "weights", "beta_r", "A_r", "sum_abs_w", "cond_vandermonde", "local_fits"]].to_string(index=False))21
Files · 27188423c707f5f19fb53683c5442b8519ad5506
Menu

Theme