Interlevel Betti Token Transformer / graph_topology_track.py
Beats tuned baseline
1"""Local custom track: fixed-size graph classification with cycle topology."""
2import numpy as np
3
4META = {"name": "cycle_topology_graph", "domain": "graph_topology", "description": "Classify fixed-size relabeled graphs by independent cycle count."}
5N = 12
6
7def _one(rng, label):
8 A = np.zeros((N, N), dtype=np.float32)
9 if label == 0:
10 for i in range(N):
11 u, v = i, (i + 1) % N
12 A[u, v] = A[v, u] = 1.0
13 else:
14 for base, size in ((0, 6), (6, 6)):
15 for j in range(size):
16 u, v = base + j, base + (j + 1) % size
17 A[u, v] = A[v, u] = 1.0
18 p = rng.permutation(N)
19 A = A[p][:, p]
20 h = rng.uniform(0.05, 0.95, N).astype(np.float32)
21 return np.concatenate([A.reshape(-1), h]), int(label)
22
23def get_dataset(seed, n_train=400, n_test=400):
24 rng = np.random.RandomState(seed)
25 def make(n):
26 xs, ys = zip(*[_one(rng, i % 2) for i in range(n)])
27 order = rng.permutation(n)
28 return np.asarray(xs, np.float32)[order], np.asarray(ys, np.int64)[order]
29 xtr, ytr = make(n_train)
30 xte, yte = make(n_test)
31 return {"xtr": xtr, "ytr": ytr, "xte": xte, "yte": yte,
32 "task": "classification", "metric": "err", "out_dim": 2}