validation and profiles

This commit is contained in:
Miha Kralj
2026-02-26 22:02:52 -08:00
parent 9ab37c1200
commit 8a1ba95173
317 changed files with 18704 additions and 622 deletions
+28
View File
@@ -42,6 +42,34 @@ where $t = z + g - \frac{1}{2}$
**Default parameters:** period = 50, alpha = 2.0, beta = 2.0.
## Performance Profile
### Operation Count (Streaming Mode)
Beta distribution CDF uses a regularized incomplete beta function evaluated via continued fraction expansion.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (alpha, beta > 0; x in [0,1]) | 3 | 2 cy | ~6 cy |
| Regularized incomplete beta (Lentz CF) | ~20 iter | 15 cy | ~300 cy |
| Log-beta normalization constant | 1 | 25 cy | ~25 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~333 cy** |
O(1) per bar — cost is fixed by the continued fraction convergence threshold regardless of input. log-Gamma dominates setup; each Lentz iteration is ~15 cy.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| Input validation | Yes | Vector range check |
| Continued fraction iteration | No | Sequential convergence |
| Log-Gamma computation | No | Transcendental function; scalar |
| Output assignment | Yes | Trivial |
Transcendental math blocks SIMD. Batch is a simple scalar loop. For large datasets use parallel outer loop (PLINQ) for throughput.
## Resources
- Abramowitz, M. & Stegun, I. (1964). *Handbook of Mathematical Functions*, Chapter 26
+28
View File
@@ -36,6 +36,34 @@ $$P(X \leq k) = \sum_{i=0}^{k} \exp\!\left[\ln\binom{n}{i} + i\ln(p) + (n-i)\ln(
**Default parameters:** period = 50, trials = 20, threshold = 10 (symmetric: $k = n/2$).
## Performance Profile
### Operation Count (Streaming Mode)
Binomial distribution PMF/CDF uses log-gamma for large n; direct factorial for small n.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (n, k integers; p in [0,1]) | 3 | 2 cy | ~6 cy |
| Log-binomial coefficient via log-Gamma | 2 | 25 cy | ~50 cy |
| k * log(p) + (n-k) * log(1-p) | 2 | 8 cy | ~16 cy |
| exp() for PMF | 1 | 20 cy | ~20 cy |
| CDF sum over k terms (optional) | k | 90 cy | ~90k cy |
| **Total (PMF only)** | **O(1)** | — | **~92 cy** |
PMF is O(1); CDF requires summing k+1 PMF values — O(k) where k = successes. For large cumulative queries, use regularized incomplete beta instead.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| Log-Gamma computation | No | Transcendental; scalar |
| exp() for PMF | Partial | _mm256_exp_pd with SVML |
| CDF accumulation | No | Sequential sum dependency |
PMF batch can use SVML exp vectorization. CDF must remain scalar.
## Resources
- Bernoulli, J. (1713). *Ars Conjectandi*
+27
View File
@@ -48,6 +48,33 @@ $$P \approx \frac{2\pi s}{\omega_0}$$
**Default parameters:** scale = 10.0, omega = 6.0 (corresponding to period $\approx 10.5$ bars).
## Performance Profile
### Operation Count (Streaming Mode)
CWT (Continuous Wavelet Transform) computes inner products of the signal against scaled/shifted wavelets — O(N*S) per bar where S = scale count.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Ring buffer update | 1 | 3 cy | ~3 cy |
| Wavelet coefficient computation (N*S inner products) | N*S | 3 cy | ~3*N*S cy |
| Scale normalization (1/sqrt(scale)) | S | 14 cy | ~14S cy |
| Peak scale identification | S | 2 cy | ~2S cy |
| **Total (N=64, S=16)** | **O(N*S)** | — | **~3128 cy** |
O(N*S) per bar — expensive. Suitable for batch analysis, not tick-by-tick hot paths. Precomputed wavelet tables reduce the inner loop to multiply-accumulate only.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| Inner product (dot product) per scale | Yes | Vector<double> FMA — dominant operation |
| Scale normalization | Yes | Vector divide by precomputed sqrt table |
| All scales independent | Yes | Outer scale loop parallelizable |
Strong SIMD candidate for batch: inner products are FMA-vectorizable. AVX2 processes 4 doubles per cycle; expected 3-4× speedup over scalar for N>=64.
## Resources
- Morlet, J. et al. (1982). "Wave propagation and sampling theory." *Geophysics*, 47(2): 203-236
+27
View File
@@ -60,6 +60,33 @@ DWT(source, levels, output):
else: return d[output] // detail at selected level
```
## Performance Profile
### Operation Count (Streaming Mode)
DWT (Discrete Wavelet Transform) applies a 2-band filter bank recursively — O(N) per bar for a single decomposition level.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Ring buffer update | 1 | 3 cy | ~3 cy |
| Low-pass filter convolution (N/2 outputs) | N/2 * L | 2 cy | ~N*L cy |
| High-pass filter convolution (N/2 outputs) | N/2 * L | 2 cy | ~N*L cy |
| Downsampling (stride-2 access) | N | 0 cy | ~0 cy |
| **Total (N=32, L=4 Haar/D4)** | **O(N*L)** | — | **~256 cy** |
O(N*L) per bar where L = filter length. Haar wavelet (L=2) is cheapest; Daubechies D4 (L=4) doubles cost. Single decomposition level.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| LP/HP convolution | Yes | FMA inner loop; no feedback dependency |
| Downsampling | Yes | Gather with stride-2 mask |
| Multi-level recursion | Partial | Each level halves data size |
First decomposition level fully SIMD. Deeper levels become too small for effective vectorization. Expect 3× batch speedup for L1 decomposition.
## Resources
- Mallat, S. "A Theory for Multiresolution Signal Decomposition: The Wavelet Representation." IEEE Trans. PAMI, 1989.
+28
View File
@@ -63,6 +63,34 @@ EXPDIST(source, period, lambda):
return 1.0 - exp(-lambda * x)
```
## Performance Profile
### Operation Count (Streaming Mode)
Exponential distribution CDF = 1 - exp(-lambda * x) — a trivially cheap closed-form evaluation.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (lambda > 0; x >= 0) | 2 | 2 cy | ~4 cy |
| lambda * x multiply | 1 | 3 cy | ~3 cy |
| exp(-lambda*x) | 1 | 20 cy | ~20 cy |
| 1 - exp result | 1 | 1 cy | ~1 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~30 cy** |
Cheapest distribution implementation — single exp() call dominates. No series expansion, no iterative solver.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| lambda * x | Yes | Vector<double> multiply |
| exp() | Partial | _mm256_exp_pd with SVML; or scalar loop |
| 1 - result | Yes | Vector subtract |
With SVML exp: 4 outputs per AVX2 cycle. Without SVML: scalar loop but still O(1) per output. Batch is trivially parallelizable.
## Resources
- Erlang, A.K. "The Theory of Probabilities and Telephone Conversations." Nyt Tidsskrift for Matematik B, 1909.
+27
View File
@@ -64,6 +64,33 @@ FDIST(source, period, d1, d2):
return betaReg(t, d1/2, d2/2)
```
## Performance Profile
### Operation Count (Streaming Mode)
F-distribution CDF uses regularized incomplete beta function — same cost structure as BetaDist.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (d1, d2 > 0; x >= 0) | 3 | 2 cy | ~6 cy |
| Transform x to beta variable | 1 | 3 cy | ~3 cy |
| Regularized incomplete beta (Lentz CF, ~20 iter) | ~20 | 15 cy | ~300 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~311 cy** |
O(1) per evaluation. Dominated by the continued fraction solver, same as Beta/T distributions. Degrees-of-freedom parameters affect convergence speed slightly.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| x transformation | Yes | Vector arithmetic |
| Continued fraction | No | Sequential convergence |
| Output assignment | Yes | Trivial |
No SIMD benefit for the core evaluation. Outer loop across observations parallelizable with PLINQ for bulk p-value computation.
## Resources
- Fisher, R.A. "On a Distribution Yielding the Error Functions of Several Well Known Statistics." Proc. International Mathematical Congress, Toronto, 1924.
+29
View File
@@ -85,6 +85,35 @@ FFT(source, windowSize, minPeriod, maxPeriod):
return clamp(dominantPeriod, minPeriod, maxPeriod)
```
## Performance Profile
### Operation Count (Streaming Mode)
FFT (DFT dominant cycle detector) evaluates B frequency bins, each requiring N multiply-accumulates — O(N*B) per bar.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Hanning window multiply | N | 2 cy | ~2N cy |
| DFT inner loop (B bins * N samples) | B*N | 4 cy | ~4*N*B cy |
| cos/sin evaluation (precomputed table) | 2*B*N | 0 cy | ~0 cy |
| Magnitude comparison + peak track | B | 2 cy | ~2B cy |
| Parabolic interpolation (3 points) | 1 | 5 cy | ~5 cy |
| **Total (N=64, B=10)** | **O(N*B)** | — | **~2617 cy** |
O(N*B) per bar where B = active frequency bins. Precomputed sin/cos tables eliminate transcendental cost. Suitable for 1-minute+ timeframes; not tick-data hot paths.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| Hanning window application | Yes | Vector multiply with precomputed weights |
| DFT inner dot product | Yes | FMA with sin/cos table lookup |
| Magnitude squared | Yes | Vector FMA (re^2 + im^2) |
| Peak search | Partial | Max reduction; SIMD-friendly |
Strong batch SIMD: inner dot products are FMA-vectorizable. AVX2 processes 4 complex outputs per 2 cycles. Expected 3-4× speedup for N=64.
## Resources
- Cooley, J.W. & Tukey, J.W. "An Algorithm for the Machine Calculation of Complex Fourier Series." Mathematics of Computation, 1965.
+27
View File
@@ -69,6 +69,33 @@ GAMMADIST(source, period, shape, rate):
return 1.0 - gammaCF(shape, scaled) // continued fraction
```
## Performance Profile
### Operation Count (Streaming Mode)
Gamma distribution CDF uses regularized incomplete gamma function via series or continued fraction.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (alpha, beta > 0; x >= 0) | 3 | 2 cy | ~6 cy |
| Log-Gamma normalization (lgamma) | 1 | 25 cy | ~25 cy |
| Regularized incomplete gamma (series, ~20 iter) | ~20 | 12 cy | ~240 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~273 cy** |
O(1) per evaluation. Switches between series expansion (x <= alpha+1) and continued fraction (x > alpha+1) for numerical stability. lgamma() is the setup cost.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| lgamma() | No | Transcendental; scalar |
| Series/CF iteration | No | Sequential convergence |
| Output assignment | Yes | Trivial |
No practical SIMD benefit. Parallelism via PLINQ on the outer observation loop.
## Resources
- Pearson, K. "Contributions to the Mathematical Theory of Evolution." Phil. Trans. Royal Society, 1893.
+27
View File
@@ -81,6 +81,33 @@ IFFT(source, windowSize, numHarmonics):
return result
```
## Performance Profile
### Operation Count (Streaming Mode)
IFFT (Inverse DFT reconstruction) sums B frequency components back into the time domain — O(N*B) per bar.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Complex multiply-accumulate (N * B) | N*B | 4 cy | ~4*N*B cy |
| cos/sin table lookup (precomputed) | 2*N*B | 0 cy | ~0 cy |
| Division by N for normalization | N | 1 cy | ~N cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total (N=64, B=10)** | **O(N*B)** | — | **~2626 cy** |
Same complexity as forward FFT. Precomputed trig tables allow the inner loop to reduce to 4 FMAs per bin. Paired with FFT for frequency-domain filtering.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| Complex MAC (re*cos - im*sin) | Yes | FMA with precomputed table |
| Normalization | Yes | Vector divide by N |
| Output time-domain signal | Yes | Full SIMD reconstruction |
Same SIMD profile as FFT forward pass. 3-4× batch speedup expected over scalar using Vector<double> FMA.
## Resources
- Fourier, J.B.J. "Theorie Analytique de la Chaleur." Firmin Didot, 1822.
+28
View File
@@ -66,6 +66,34 @@ LOGNORMDIST(source, period, mu, sigma):
return normalCdf(z)
```
## Performance Profile
### Operation Count (Streaming Mode)
Log-Normal CDF = Normal CDF of (ln(x) - mu) / sigma — one log() plus an erfc() evaluation.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (x > 0; sigma > 0) | 2 | 2 cy | ~4 cy |
| log(x) | 1 | 8 cy | ~8 cy |
| z = (log(x) - mu) / sigma | 1 | 4 cy | ~4 cy |
| Normal CDF via erfc (rational approximation) | 1 | 15 cy | ~15 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~33 cy** |
O(1) — reduces to Normal CDF after log transform. erfc() rational approximation dominates; log() is secondary cost.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| log(x) | Partial | _mm256_log_pd with SVML |
| z normalization | Yes | Vector FMA |
| erfc() | No | Rational polynomial; scalar |
Limited vectorization — erfc blocks full SIMD. With SVML log: partial vectorization for the transform step.
## Resources
- Galton, F. "The Geometric Mean, in Vital and Social Statistics." Proc. Royal Society, 1879.
+27
View File
@@ -86,6 +86,33 @@ NORMDIST(source, period, mu, sigma):
return 0.5 * (1 + erf)
```
## Performance Profile
### Operation Count (Streaming Mode)
Normal distribution CDF uses an erfc() rational approximation (Abramowitz & Stegun) — O(1) closed form.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| z = (x - mu) / sigma | 1 | 4 cy | ~4 cy |
| erfc(z / sqrt(2)) rational approx | 1 | 15 cy | ~15 cy |
| Scale by 0.5 | 1 | 1 cy | ~1 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~22 cy** |
O(1) per evaluation. The rational polynomial erfc approximation has 7-term expansion, accurate to 1e-7. Division by sigma precomputed as multiplication by 1/sigma.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| z = (x - mu) / sigma | Yes | Vector<double> FMA |
| erfc() rational polynomial | Partial | Polynomial evaluable via Horner + Vector |
| Final scale | Yes | Vector multiply |
The Horner polynomial evaluation in erfc() is SIMD-vectorizable. Expected 3× batch speedup over scalar using Vector<double> for the polynomial terms.
## Resources
- Gauss, C.F. "Theoria Motus Corporum Coelestium." 1809.
+28
View File
@@ -64,6 +64,34 @@ POISSONDIST(source, period, k, lambda_scale):
return 1.0 - gammaP(k + 1, lambda)
```
## Performance Profile
### Operation Count (Streaming Mode)
Poisson PMF = e^(-lambda) * lambda^k / k! computed via log-space to avoid overflow.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (lambda > 0; k >= 0) | 2 | 2 cy | ~4 cy |
| k * log(lambda) - lgamma(k+1) - lambda | 3 | 10 cy | ~30 cy |
| exp() of log-PMF | 1 | 20 cy | ~20 cy |
| CDF cumulative sum (k terms) | k | 50 cy | ~50k cy |
| **Total (PMF only)** | **O(1)** | — | **~54 cy** |
PMF is O(1) via log-space computation. CDF is O(k) — expensive for large k. For k > 30, use Normal approximation. lgamma() dominates for small k.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| log(lambda) | Partial | _mm256_log_pd with SVML |
| lgamma(k+1) | No | Transcendental; scalar |
| exp() | Partial | _mm256_exp_pd with SVML |
| CDF sum | No | Sequential dependency |
PMF batch: partial SIMD with SVML. CDF must be scalar. For large lambda, Normal approximation enables full vectorization.
## Resources
- Poisson, S.D. "Recherches sur la probabilite des jugements en matiere criminelle et en matiere civile." 1837.
+28
View File
@@ -76,6 +76,34 @@ TDIST(source, period, df):
else: return 0.5 * ibeta
```
## Performance Profile
### Operation Count (Streaming Mode)
T-distribution CDF uses regularized incomplete beta — same continued fraction as BetaDist/FDist.
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (df > 0) | 1 | 2 cy | ~2 cy |
| Transform t to beta variable | 1 | 4 cy | ~4 cy |
| Regularized incomplete beta (Lentz CF, ~20 iter) | ~20 | 15 cy | ~300 cy |
| Two-tailed adjustment | 1 | 2 cy | ~2 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~310 cy** |
O(1). Same continued fraction as FDist. For df > 30, Normal approximation is faster (~22 cy) and accurate to 1e-4.
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| t-to-beta transformation | Yes | Vector arithmetic |
| Continued fraction | No | Sequential convergence |
| Two-tailed flip | Yes | Vector conditional |
Dominated by sequential CF solver. Outer loop PLINQ for bulk p-value computation.
## Resources
- Student (Gosset, W.S.). "The Probable Error of a Mean." Biometrika, 1908.
+29
View File
@@ -77,6 +77,35 @@ WEIBULLDIST(source, period, shape, scale):
return 1.0 - exp(-raised)
```
## Performance Profile
### Operation Count (Streaming Mode)
Weibull CDF = 1 - exp(-(x/lambda)^k) — closed form with one pow() + one exp().
| Operation | Count | Cost (cycles) | Subtotal |
| :--- | :---: | :---: | :---: |
| Input validation (k, lambda > 0; x >= 0) | 3 | 2 cy | ~6 cy |
| (x / lambda)^k via exp(k * log(x/lambda)) | 1 | 30 cy | ~30 cy |
| exp(negated power) | 1 | 20 cy | ~20 cy |
| 1 - exp result | 1 | 1 cy | ~1 cy |
| NaN guard + state update | 1 | 2 cy | ~2 cy |
| **Total** | **O(1)** | — | **~59 cy** |
O(1) closed-form evaluation. pow() via exp(k*log(x)) is the dominant cost (~30 cy). When k is an integer, integer pow() reduces to repeated multiply (~5 cy).
### Batch Mode (SIMD Analysis)
| Operation | Vectorizable? | Notes |
| :--- | :---: | :--- |
| log(x/lambda) | Partial | _mm256_log_pd with SVML |
| k * log result | Yes | Vector multiply with broadcast k |
| exp() | Partial | _mm256_exp_pd with SVML |
| 1 - exp | Yes | Vector subtract |
With SVML: nearly full vectorization. Without SVML: scalar loop but trivially parallelizable. Expected 3× batch speedup with SVML.
## Resources
- Weibull, W. "A Statistical Distribution Function of Wide Applicability." Journal of Applied Mechanics, 1951.