# Deep Dive: The Koopman Spectral-Constraint Layer

## 1. Architectural Role
The Koopman layer is the "governance substrate" of the Aevion Shield. While the world model (JEPA/Genie) provides the predictive latent core, the Koopman layer approximates the hidden-state dynamics as a linear operator in a higher-dimensional observable space. This enables us to apply classical control-theory guarantees (stability, dissipativity) to a deep neural network.

## 2. Estimating the Operator (NN-ResDMD)
Following the **NN-ResDMD** (Neural Network Residual Dynamic Mode Decomposition) approach, we train a neural network to learn a dictionary of dictionary functions $\phi(x)$ that define a Koopman-invariant subspace.

- **Objective:** Minimize the spectral residual between the current state lifting and the predicted next state lifting.
- **Operator Matrix:** We derive a finite-dimensional matrix $\tilde{K}$ such that $\phi(x_{t+1}) \approx \tilde{K} \phi(x_t)$.
- **Explainability:** The eigenvalues $\lambda_i$ of $\tilde{K}$ provide a direct, linear description of the long-timescale behavior of the nonlinear world model.

## 3. Safety Gating & Governance
### 3.1 Spectral Radius Gate
We monitor the spectral radius $\rho(\hat{K})$.
- **Stability Threshold:** We enforce $\rho(\hat{K}) < 1.0589$.
- **Halt Condition:** If the hidden-state dynamics show non-contracting or unstable behavior, the **Constitutional Halt** is triggered before the action is emitted to the environment.

### 3.2 Dissipativity Constraints
To guarantee safety even under adversarial conditions, we utilize **Dissipativity-Guaranteed Neural Koopman Operators**.
- **LMI Projection:** Periodically, the learned operator $\tilde{K}$ is projected into a set of dissipative operators using Linear Matrix Inequalities (LMIs).
- **Storage Function:** This ensures that the energy (norm) of the state transitions remains bounded by a characterizable storage function, preventing catastrophic divergence.

### 3.3 Spectral Residual Anomaly Detection
Inspired by the NN-ResDMD residual minimization objective, we maintain a baseline distribution of spectral residuals.
- **3σ Gate:** If the runtime residual of a trajectory's induced operator exceeds $3\sigma$ over the baseline, it indicates a distribution shift or model failure, triggering a fallback.

## 4. Hardware-Isolated Attestation (VLAN 30)
The Koopman estimates and safety verdicts are verified and signed by the **Pi Sheriff** (Zymbit hardware loop).
1. **Agent Proposes:** Hidden-state trajectory is lifted and $\tilde{K}$ is estimated.
2. **Spectral Check:** $\rho(\hat{K})$ and residuals are calculated in the sandbox (VLAN 20).
3. **Hardware Sign:** The "Pi Sheriff" verifies the calculation and signs the **Type-2 Proof** receipt.
4. **Action Emission:** Only signed actions are admitted to the production environment.

---
*Reference Implementation grounding: NN-ResDMD (arXiv:2501.00701v1), Dissipativity-Guaranteed Koopman (arXiv:2509.07294).*
