Chern-Gap Monitor for Finite-Horizon Collapse / run_experiment.py
Unverified
1import json
2import numpy as np
3from chern_gap_monitor import monitor_field, qwz_field, fixed_point_parity
4
5
6def main():
7 np.random.seed(7)
8 # Prediction 1: the spherical formula gives the exact octant area pi/2.
9 e1, e2, e3 = np.eye(3)
10 from chern_gap_monitor import spherical_area
11 area = float(spherical_area(e1, e2, e3))
12
13 K = 80
14 masses = [-3.0, -1.5, -0.5, 0.5, 1.5, 3.0]
15 rows = []
16 for mass in masses:
17 gap, ch = monitor_field(qwz_field(K, mass))
18 rows.append({"mass": mass, "gap": gap, "chern": ch,
19 "rounded_chern": int(np.rint(ch)),
20 "parity_proxy": fixed_point_parity(mass)})
21
22 # Prediction 2: sector is stable away from the three gap-closing masses;
23 # prediction 3: at a sampled critical momentum the gap is |delta mass|.
24 critical = []
25 for mc in (-2.0, 0.0, 2.0):
26 deltas = np.array([-0.20, -0.10, -0.05, 0.05, 0.10, 0.20])
27 gaps = np.array([monitor_field(qwz_field(K, mc+d))[0] for d in deltas])
28 slope = float(np.dot(np.abs(deltas), gaps) / np.dot(deltas, deltas))
29 critical.append({"critical_mass": mc, "min_gap_at_transition": float(monitor_field(qwz_field(K, mc))[0]),
30 "deltas": deltas.tolist(), "gaps": gaps.tolist(),
31 "fit_slope_gap_vs_abs_delta": slope,
32 "predicted_slope": 1.0})
33
34 # Finite-batch/EMA sanity: additive mean noise should be reduced by EMA.
35 true_field = qwz_field(40, 1.0)
36 rng = np.random.default_rng(11)
37 raw_errors, ema_errors = [], []
38 ema = np.zeros_like(true_field)
39 alpha = 0.15
40 for _ in range(100):
41 observed = true_field + rng.normal(0, 0.20, true_field.shape)
42 ema = (1-alpha)*ema + alpha*observed
43 raw_errors.append(np.mean((observed-true_field)**2))
44 ema_errors.append(np.mean((ema-true_field)**2))
45 result = {
46 "octant_area": area, "octant_area_error": abs(area-np.pi/2),
47 "sector_rows": rows, "critical_sweeps": critical,
48 "ema_noise_mse": float(np.mean(ema_errors[20:])),
49 "raw_noise_mse": float(np.mean(raw_errors[20:])),
50 "ema_reduction_fraction": float(1-np.mean(ema_errors[20:])/np.mean(raw_errors[20:]))
51 }
52 print(json.dumps(result, indent=2))
53
54if __name__ == '__main__':
55 main()