Harmonic Global Latent Channels / custom_harmonic_track.py

Mechanism confirmed, baseline not beaten

Raw ⬇ ZIP
 1import numpy as np
 2
 3META = {
 4    "name": "harmonic_cycle_circulation",
 5    "domain": "pde",
 6    "description": "Regression on a discretized annulus-like one-cycle: a local source encodes randomized global circulation and the target is the corresponding harmonic edge 1-form."
 7}
 8
 9
10def harmonic_basis(n=24):
11    # Vertices/edges of a periodic annulus skeleton. B1 is vertex-edge incidence;
12    # there are no filled 2-cells in this minimal annulus skeleton.
13    B1 = np.zeros((n, n), dtype=np.float64)
14    for e in range(n):
15        B1[e, e] = -1.0
16        B1[(e + 1) % n, e] = 1.0
17    masses = 0.5 + np.linspace(0.2, 1.4, n)
18    M = np.diag(masses)
19    h = np.linalg.solve(M, np.ones(n))
20    h /= np.sqrt(h @ M @ h)
21    return B1, M, h[:, None]
22
23
24def get_dataset(seed, n_train=400, n_test=400):
25    rng = np.random.RandomState(seed)
26    _, _, H = harmonic_basis()
27    atr = rng.uniform(-2.0, 2.0, n_train).astype(np.float32)
28    ate = np.random.RandomState(seed + 5000).uniform(-2.0, 2.0, n_test).astype(np.float32)
29    xtr = np.zeros((n_train, len(H), 1), dtype=np.float32)
30    xte = np.zeros((n_test, len(H), 1), dtype=np.float32)
31    # A source is local (one edge); four graph layers cannot directly reach the
32    # opposite side, while global pooling can encode the circulation coefficient.
33    xtr[:, 0, 0] = atr
34    xte[:, 0, 0] = ate
35    ytr = atr[:, None] * H[:, 0][None, :].astype(np.float32)
36    yte = ate[:, None] * H[:, 0][None, :].astype(np.float32)
37    return {"xtr": xtr, "ytr": ytr, "xte": xte, "yte": yte,
38            "task": "regression", "metric": "mse", "out_dim": len(H)}