Skip to content

Latest commit

 

History

History
203 lines (163 loc) · 12.5 KB

VALIDATION.md

File metadata and controls

203 lines (163 loc) · 12.5 KB

Validation report

Generated by python docs/validate.py; rerun in CI on every push.

105 / 105 checks pass.

Every from-scratch algorithm is compared with SciPy/NumPy/statsmodels, with exact analytic results, with NIST certified values, or with its theoretical order of convergence (the slope of log(error) against log(step size)).

Root finding

Check Reference engmath Expected Tolerance Status
bisection: root of x^3 - 2x - 5 scipy brentq 2.094551482 2.094551482 1e-11 pass
Newton: root of x^3 - 2x - 5 scipy brentq 2.094551482 2.094551482 1e-11 pass
secant: root of x^3 - 2x - 5 scipy brentq 2.094551482 2.094551482 1e-11 pass
Brent: root of x^3 - 2x - 5 scipy brentq 2.094551482 2.094551482 1e-11 pass
Newton convergence order (cos x = x) theory: 2 1.99803193 2 0.2 pass
secant convergence order theory: 1.618 1.680279093 1.618 0.3 pass
bisection: error halves each step (median ratio) theory: 0.5 0.3942053058 0.5 0.3 pass
Colebrook f (eps/D 1e-3, Re 5e5) vs Haaland Haaland (1983), ±2 % 1.001892231 1 0.02 pass
Colebrook residual at computed root exact: 0 4.076206039e-11 0 1e-10 pass

Optimisation

Check Reference engmath Expected Tolerance Status
Nelder-Mead: Rosenbrock minimum x exact: 1 1 1 1e-05 pass
Nelder-Mead: Rosenbrock minimum y exact: 1 1 1 1e-05 pass
golden section: min of (x-2)^2 + sin 3x scipy minimize_scalar 1.649428381 1.649428371 1e-06 pass

Linear systems and eigenvalues

Check Reference engmath Expected Tolerance Status
Gauss elimination vs numpy.linalg.solve (max diff) numpy 2.081668171e-17 0 1e-12 pass
Gauss with a zero pivot (pivoting needed) numpy 1.165734176e-15 0 1e-10 pass
Thomas algorithm, n = 200 (max diff) numpy 1.665334537e-16 0 1e-12 pass
jacobi iteration (diagonally dominant) numpy 3.016753514e-12 0 1e-09 pass
gauss-seidel iteration (diagonally dominant) numpy 1.814159933e-12 0 1e-09 pass
power iteration: largest eigenvalue of spring chain exact: 2 + 2cos(pi/11) 3.918985947 3.918985947 1e-08 pass

Interpolation

Check Reference engmath Expected Tolerance Status
natural cubic spline vs scipy (max diff) scipy CubicSpline natural 6.661338148e-16 0 1e-12 pass
spline derivative vs scipy (max diff) scipy 3.330669074e-16 0 1e-11 pass
spline integral vs scipy scipy 1.428391731 1.428391731 1e-12 pass
linear interpolation vs numpy.interp numpy 0 0 1e-15 pass
spline convergence order (sin on [0, pi]) theory: 4 4.033358178 4 0.3 pass
Lagrange through 5 points of a quartic is exact exact -0.2919 -0.2919 1e-14 pass

Integration

Check Reference engmath Expected Tolerance Status
trapezoid: observed order of accuracy theory: 2 2.001061538 2 0.1 pass
midpoint: observed order of accuracy theory: 2 2.001856693 2 0.1 pass
simpson: observed order of accuracy theory: 4 4.002587339 4 0.1 pass
Romberg (6 levels) exact 0.1848746759 0.1848746759 1e-10 pass
Gauss-Legendre 12 points exact 0.1848746759 0.1848746759 1e-12 pass
Simpson, 42 unequal points vs scipy.simpson scipy 0.1849559485 0.1849559485 1e-10 pass
Simpson, uneven spacing, quadratic (exact) exact 4.5 4.5 1e-10 pass
Simpson, EQUAL spacing, cubic (exact by symmetry) exact 20.25 20.25 1e-12 pass
trapezoid, uneven points vs scipy.trapezoid scipy 0.1856604401 0.1856604401 1e-14 pass
cumulative trapezoid end value trapezoid 0.1856604401 0.1856604401 1e-14 pass

Differentiation

Check Reference engmath Expected Tolerance Status
uneven gradient vs numpy.gradient (2nd-order edges) numpy 0 0 1e-10 pass
uneven-grid gradient: observed order theory: 2 1.969503111 2 0.2 pass
Richardson extrapolation of d/dx e^x sin 3x at 1 exact -7.689631888 -7.689631888 1e-09 pass
second derivative of a quadratic (exact) exact 1.572075803e-13 0 1e-09 pass

Smoothing

Check Reference engmath Expected Tolerance Status
Savitzky-Golay (15 pts, cubic, deriv 0) vs scipy scipy savgol_filter 5.773159728e-15 0 1e-09 pass
Savitzky-Golay (15 pts, cubic, deriv 1) vs scipy scipy savgol_filter 1.232347557e-14 0 1e-09 pass
Savitzky-Golay (15 pts, cubic, deriv 2) vs scipy scipy savgol_filter 4.085620731e-14 0 1e-09 pass
LOWESS reduces error vs the true signal (RMS ratio) should be < 0.6 0.4532236684 0.6 0.6 pass
LOWESS reproduces a straight line exactly exact 1.421085472e-14 0 1e-10 pass

Least-squares fitting

Check Reference engmath Expected Tolerance Status
linear least squares vs numpy.lstsq (max diff) numpy 1.776356839e-15 0 1e-12 pass
standard errors vs s^2 (X'X)^-1 formula 2.255065327e-15 0 1e-10 pass
Huber IRLS slope with an edge outlier (true 2) truth ±0.15 2.025264216 2 0.1 pass
... while ordinary least squares is pulled away OLS error > 0.3 0.3 0.3 1e-09 pass
LM: NIST Misra1a b1 (start 1) NIST certified 1 1 1e-06 pass
LM: NIST Misra1a b2 (start 1) NIST certified 0.9999999997 1 1e-06 pass
LM: NIST Misra1a SE(b1) NIST certified 0.9999998954 1 0.0001 pass
LM: NIST Misra1a residual SD NIST certified 1 1 1e-08 pass

Ordinary differential equations

Check Reference engmath Expected Tolerance Status
Euler: observed order theory: 1 1.008600088 1 0.2 pass
RK4: observed order theory: 4 4.072785345 4 0.2 pass
adaptive RK23 (rtol 1e-8) vs exact exact exp(-t^2) 0.01831563566 0.01831563889 1e-07 pass
RK4 Lotka-Volterra system vs solve_ivp scipy (rtol 1e-12) 0 0 1e-07 pass
backward Euler stable on stiff ODE (h = 0.02, lambda h = -20) y - cos t small 0.0008354542167 0
... explicit Euler with the same step blows up y > 1e6 1000000 1000000

Diffusion PDE (vs erf solution of a semi-infinite medium)

Check Reference engmath Expected Tolerance Status
FTCS (r = 0.4) max error erfc solution 3.41466789e-05 0 0.005 pass
Crank-Nicolson (r = 2.5, beyond the FTCS limit) max error erfc solution 8.99232107e-06 0 0.01 pass
FTCS refuses an unstable step (r = 0.6) raises 1 1 0 pass

Systems of nonlinear equations

Check Reference engmath Expected Tolerance Status
three-reservoir junction head vs 1D reduction (Brent) independent formulation 105.2119062 105.2119062 1e-08 pass
continuity satisfied (sum of flows) exact: 0 1.387778781e-17 0 1e-12 pass
flows vs scipy.optimize.root (max diff) scipy 2.775557562e-17 0 1e-09 pass
Newton for systems: observed order near the root theory: 2 2.007479289 2 0.3 pass

Boundary-value problems (pin fin with convective tip)

Check Reference engmath Expected Tolerance Status
shooting: max T - exact (K) analytic cosh/sinh solution 3.836930773e-13 0
shooting: fin heat rate -kA T'(0) (W) analytic 1.482490222 1.482490222 1e-09 pass
finite differences with Robin tip: observed order theory: 2 1.999944782 2 0.1 pass
variable-coefficient check: y'' + y' - 2y = 0, Neumann + Dirichlet exact exponentials 1.908986905e-06 0 1e-05 pass

Fourier analysis

Check Reference engmath Expected Tolerance Status
radix-2 FFT vs numpy.fft (N = 1024, max diff) numpy 5.728578677e-14 0 1e-10 pass
DFT from the definition vs numpy.fft (N = 256) numpy 2.838099198e-12 0 1e-09 pass
amplitude of a 3.0 sine on a frequency bin (rectangular window) exact: 3 3 3 1e-09 pass
Hann window: peak amplitude and DC offset preserved (peak) exact: 3 3 3 1e-09 pass
... DC component exact: 1 1 1 1e-09 pass
FFT low-pass removes the 120 Hz component exactly exact 3.008704397e-14 0 1e-10 pass
Parseval's theorem (energy in time = energy in frequency) exact 1007.090433 1007.090433 1e-09 pass

Linear programming and constrained optimisation

Check Reference engmath Expected Tolerance Status
simplex: optimal profit vs scipy linprog scipy (HiGHS) 2600 2600 1e-09 pass
simplex: optimal plan (max diff) scipy (HiGHS) 0 0 1e-09 pass
simplex: shadow prices vs linprog duals (max diff) scipy marginals 0 0 1e-09 pass
simplex on a random 6x5 LP: objective scipy (HiGHS) 36.73713533 36.73713533 1e-08 pass
penalty method: tank radius (h <= 1 m active) vs SLSQP scipy SLSQP 0.5641895827 0.5641861948 0.0001 pass
... exact radius with h = 1: sqrt(1/pi) analytic 0.5641895827 0.5641895835 0.0001 pass
penalty method, no height limit: h/r = 2 analytic (Lagrange) 2.000000019 2 0.001 pass

Monte Carlo

Check Reference engmath Expected Tolerance Status
volume of the unit ball in 2 dimensions (within 4 SE) pi^(d/2)/Gamma(d/2+1) 0.297475139 0 4 pass
volume of the unit ball in 5 dimensions (within 4 SE) pi^(d/2)/Gamma(d/2+1) 0.4502544068 0 4 pass
volume of the unit ball in 10 dimensions (within 4 SE) pi^(d/2)/Gamma(d/2+1) 0.06852726313 0 4 pass
random walk: mean squared displacement after 400 steps (within 4 SE) theory: n = 400 0.9525062044 0 4 pass
1D walk: kurtosis of end positions (Gaussian limit: 3) central limit theorem 2.952270333 3 0.1 pass

Sparse matrices and 2D PDEs

Check Reference engmath Expected Tolerance Status
5-point Poisson solver: observed order (manufactured solution) theory: 2 2.001304388 2 0.1 pass
quadratic solution reproduced exactly (non-square domain) exact 1.398881011e-14 0 1e-10 pass
Kronecker Laplacian vs dense assembly (max diff) direct construction 0 0 1e-09 pass
conjugate gradient vs sparse direct solve (max rel diff) scipy spsolve 8.215781574e-13 0 1e-09 pass

Reporting and uncertainty propagation

Check Reference engmath Expected Tolerance Status
format_uncertainty(2.29987, 0.08907) -> '2.30 ± 0.09' rounding rule 1 1 0 pass
format_uncertainty(10523.4, 156.7) -> '10520 ± 160' rounding rule 1 1 0 pass
format_uncertainty(0.348, 0.0081) -> '0.348 ± 0.008' rounding rule 1 1 0 pass
format_uncertainty(9.87654, 0.0963) -> '9.88 ± 0.10' rounding rule 1 1 0 pass
format_uncertainty(1234.5, 23.0) -> '1230 ± 20' rounding rule 1 1 0 pass
propagation for PV/RT vs analytic relative formula analytic 0.03655437351 0.0365543735 1e-08 pass

Real data files (NIST StRD, read from the bundled files; certified values parsed from their headers)

Check Reference engmath Expected Tolerance Status
Chwirut2 (ultrasonic calibration), start [0.1, 0.01, 0.02]: max rel. parameter error NIST certified 1.674604899e-09 0 1e-06 pass
Chwirut2 (ultrasonic calibration), start [0.15, 0.008, 0.01]: max rel. parameter error NIST certified 3.91554319e-08 0 1e-06 pass
Chwirut2 residual standard deviation NIST certified 3.171713304 3.171713304 1e-08 pass
ENSO (Pacific pressure record, 9 parameters): max b - certified / SE NIST certified 1.503830861e-05 0
ENSO standard errors: max relative difference NIST certified 2.615097179e-06 0 0.0001 pass
ENSO residual standard deviation NIST certified 2.22696424 2.22696424 1e-07 pass
Mauna Loa CO2 file: first monthly mean (March 1958) NOAA record: 315.71 ppm 315.71 315.71 1e-09 pass
Mauna Loa CO2 file: consecutive months, no gaps 821 months, spacing 1/12 year 0.006633333333 0 0.01 pass