hardware-counters
significance.py
"""
Do the hardware counters genuinely add predictive value, or is the residual
model mostly riding the analytic cycles/peak-clock term?
Within the residual framing the "mean baseline" already inherits the cycle
count (it predicts a constant efficiency factor), so it is a strong control.
The question is whether counter-driven models beat it by a margin that is
meaningful given only 40 configurations.
Tests:
1. paired per-configuration comparison of error factors (Wilcoxon)
2. permutation test: shuffle the target within the training set and see how
often a "model" beats the constant baseline by chance
"""
import numpy as np, pandas as pd
from scipy.stats import wilcoxon
D = "/work/project/project/user"
p = pd.read_csv(f"{D}/analysis/out/predictions.csv")
p = p[p.approach == "residual"].copy()
p["factor"] = np.maximum(p.predicted_s / p.actual_s, p.actual_s / p.predicted_s)
base = p[p.model == "Mean baseline"].set_index(["app", "ncore"]).factor
print("Paired comparison against the constant-efficiency baseline")
print("(both inherit the analytic cycle term; difference = counter contribution)")
print()
print(f"{'model':20s} {'median factor':>14s} {'wins/40':>9s} {'p (Wilcoxon)':>13s}")
for m in ["Lasso", "Random Forest", "Gradient Boosting", "Ridge"]:
f = p[p.model == m].set_index(["app", "ncore"]).factor
common = base.index.intersection(f.index)
a, b = f.loc[common].values, base.loc[common].values
wins = int((a < b).sum())
try:
stat, pv = wilcoxon(a, b)
except ValueError:
pv = float("nan")
print(f"{m:20s} {np.median(a):14.3f} {wins:6d}/{len(common):<3d} {pv:13.4f}")
print(f"\n{'Mean baseline':20s} {np.median(base):14.3f}")
print("\nInterpretation: p < 0.05 and wins clearly above 20/40 would indicate")
print("the counters carry real signal beyond the cycle count alone.")