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:
When applying window functions $w[n]$, energy is attenuated by the noise power bandwidth gain:
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:
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$: 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}$:
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:
Analytical gradients computed in virtual registers are validated against central finite differences:
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, orfreepost-initialization. - Compile-time static ceilings:
SOFIA_MAX_FFT_LEN = 1024,SOFIA_N_STAT_FEATURES = 14.