Spectral-Edge Criticality Controller / spectral_edge.py
Mechanism confirmed, baseline not beaten
1import numpy as np
2
3class SpectralEdgeController:
4 """Multiplicative edge controller for h'=tanh(g W h + input)."""
5 def __init__(self, target=0.9, alpha=0.25, g_min=1e-3, g_max=3.0):
6 self.target = float(target)
7 self.alpha = float(alpha)
8 self.g_min, self.g_max = float(g_min), float(g_max)
9 self.g = 1.0
10
11 @staticmethod
12 def edge_estimate(W, derivative, iterations=5, rng=None):
13 # Singular edge of D W is robust when the nonlinear local Jacobian is nonsymmetric.
14 rng = np.random.default_rng() if rng is None else rng
15 v = rng.normal(size=W.shape[0]); v /= np.linalg.norm(v)
16 for _ in range(iterations):
17 u = derivative * (W @ v)
18 nu = np.linalg.norm(u)
19 if nu == 0: return 0.0
20 u /= nu
21 v = W.T @ (derivative * u)
22 nv = np.linalg.norm(v)
23 if nv == 0: return 0.0
24 v /= nv
25 return float(np.linalg.norm(derivative * (W @ v)))
26
27 def update(self, edge):
28 self.g *= np.exp(self.alpha * (self.target - self.g * edge))
29 self.g = float(np.clip(self.g, self.g_min, self.g_max))
30 return self.g