sofia / docs /SCIENTIFIC_VALIDATION.md
rootcastleengineering's picture
release: publish Sofia Engine 3.0.0a1 artifacts, manifests, and documentation
876458a
|
Raw
History Blame Contribute Delete
3.5 kB

Sofia Engine Scientific Validation

All algorithms in Sofia Engine are backed by deterministic mathematical verification, golden test vectors, and physical conservation laws.


1. Digital Signal Processing Correctness

Parseval Energy Conservation

For discrete signals, Parseval's theorem dictates that total energy in the time domain must equal total energy in the frequency domain: βˆ‘n=0Nβˆ’1∣x[n]∣2=1Nβˆ‘k=0Nβˆ’1∣X[k]∣2\sum_{n=0}^{N-1} |x[n]|^2 = \frac{1}{N} \sum_{k=0}^{N-1} |X[k]|^2

When applying window functions $w[n]$, energy is attenuated by the noise power bandwidth gain: S2=βˆ‘n=0Nβˆ’1w[n]2S_2 = \sum_{n=0}^{N-1} w[n]^2

Sofia's welch_psd implementation normalizes power spectral density by $S_2$ and frequency resolution $\Delta f = f_s / N$. Energy conservation across Hann, Hamming, and Blackman windows is continuously verified in tests/unit/test_dsp_golden.py: ∣∫PSD(f) dfVar(x)βˆ’1.0∣<0.05\left| \frac{\int \text{PSD}(f)\,df}{\text{Var}(x)} - 1.0 \right| < 0.05

Exact Amplitude Recovery

For unwindowed integer-bin tones ($f_0 = k \cdot f_s / N$), the one-sided FFT magnitude recovers the exact continuous amplitude $A$: A^=2N∣X[k]∣\hat{A} = \frac{2}{N} |X[k]| Sofia verifies peak tone amplitude recovery to machine precision ($< 10^{-14}$ relative error).

3-Phase Symmetrical Components (Fortescue Transformation)

Unbalanced 3-phase voltages $V_a, V_b, V_c$ are decomposed using the complex operator $a = e^{j 120^\circ} = -\frac{1}{2} + j \frac{\sqrt{3}}{2}$: [V0V1V2]=13[1111aa21a2a][VaVbVc]\begin{bmatrix} V_0 \\ V_1 \\ V_2 \end{bmatrix} = \frac{1}{3} \begin{bmatrix} 1 & 1 & 1 \\ 1 & a & a^2 \\ 1 & a^2 & a \end{bmatrix} \begin{bmatrix} V_a \\ V_b \\ V_c \end{bmatrix} VUF=∣V2∣∣V1βˆ£Γ—100%\text{VUF} = \frac{|V_2|}{|V_1|} \times 100\% Golden vectors generated in tests/golden/dsp_golden.json assert that positive ($V_1$), negative ($V_2$), and zero ($V_0$) sequence components match theoretical values within $10^{-5}$ tolerance across Python, TypeScript, and C99 runtimes.


2. In-Situ Neural Training & Gradient Verification

Sofia's virtual assembly neural network (AssemblyNeuralNetwork) implements 2-layer analytical backpropagation directly in virtual bytecode: βˆ‚Lβˆ‚W2=βˆ‚Lβˆ‚y^β‹…hT,βˆ‚Lβˆ‚B2=βˆ‚Lβˆ‚y^\frac{\partial L}{\partial W_2} = \frac{\partial L}{\partial \hat{y}} \cdot h^T, \quad \frac{\partial L}{\partial B_2} = \frac{\partial L}{\partial \hat{y}} βˆ‚Lβˆ‚h=W2Tβ‹…βˆ‚Lβˆ‚y^,βˆ‚Lβˆ‚z1=βˆ‚Lβˆ‚hβŠ™I(z1>0)\frac{\partial L}{\partial h} = W_2^T \cdot \frac{\partial L}{\partial \hat{y}}, \quad \frac{\partial L}{\partial z_1} = \frac{\partial L}{\partial h} \odot \mathbb{I}(z_1 > 0) βˆ‚Lβˆ‚W1=βˆ‚Lβˆ‚z1β‹…xT,βˆ‚Lβˆ‚B1=βˆ‚Lβˆ‚z1\frac{\partial L}{\partial W_1} = \frac{\partial L}{\partial z_1} \cdot x^T, \quad \frac{\partial L}{\partial B_1} = \frac{\partial L}{\partial z_1}

Analytical gradients computed in virtual registers are validated against central finite differences: βˆ‚Lβˆ‚ΞΈiβ‰ˆL(ΞΈi+Ο΅)βˆ’L(ΞΈiβˆ’Ο΅)2Ο΅,Ο΅=10βˆ’5\frac{\partial L}{\partial \theta_i} \approx \frac{L(\theta_i + \epsilon) - L(\theta_i - \epsilon)}{2\epsilon}, \quad \epsilon = 10^{-5} The relative error $\frac{|\nabla_{\text{analytical}} - \nabla_{\text{numerical}}|}{|\nabla_{\text{analytical}}| + |\nabla_{\text{numerical}}|}$ is proven to be $< 10^{-5}$ in tests/unit/test_neural_gradients.py.


3. Microcontroller Fixed-Point Conformance

The C99 embedded runtime (embedded/src/sofia_features.c) implements Q16.16 fixed-point arithmetic:

  • Fixed-point resolution: $1/65536 \approx 1.526 \times 10^{-5}$
  • Dynamic range: $[-32768.0, +32767.99998]$
  • Zero heap allocation: no calls to malloc, calloc, or free post-initialization.
  • Compile-time static ceilings: SOFIA_MAX_FFT_LEN = 1024, SOFIA_N_STAT_FEATURES = 14.