Poisson-Kernel Random Attractor Regularizer / pk_regularizer.py

Failed on benchmark

Raw ⬇ ZIP
 1"""Poisson-kernel random-attractor regularizer for complex latent ensembles."""
 2import numpy as np
 3
 4
 5def poisson_density(phases, x, eps=1e-8):
 6    phases = np.asarray(phases)
 7    x = complex(x)
 8    r2 = min(abs(x) ** 2, 1.0 - eps)
 9    u = np.exp(1j * phases)
10    den = 1.0 + r2 - 2.0 * np.real(np.conj(x) * u)
11    return (1.0 - r2) / np.maximum(den, eps)
12
13
14def poisson_nll(phases, x, eps=1e-8):
15    return float(-np.mean(np.log(poisson_density(phases, x, eps))))
16
17
18def compose_affine(maps, z):
19    """Apply maps in chronological order; each map is (q, a), T(z)=q*z+a."""
20    for q, a in maps:
21        z = q * z + a
22    return z
23
24
25def estimate_attractor(maps, probes):
26    """Finite backward-composition estimate, with stopped-gradient semantics in numpy."""
27    vals = [compose_affine(maps, complex(p)) for p in probes]
28    return complex(np.mean(vals))
29
30
31def pk_loss(phases, xhat, eps=1e-8):
32    return poisson_nll(phases, xhat, eps)
33
34
35def sample_poisson_phases(x, n, rng):
36    """Exact boundary sampling via the disk automorphism of uniform circle points."""
37    u = np.exp(2j * np.pi * rng.random(n))
38    x = complex(x)
39    w = (u + x) / (1.0 + np.conj(x) * u)
40    return np.angle(w)