|
| 1 | +#![allow(missing_docs)] |
| 2 | +//! Pillar-15 — Mexican-hat / Difference-of-Gaussians unimodality |
| 3 | +//! certification. **DEFERRED** pending Mexican-hat resonance kernel |
| 4 | +//! landing in `ndarray::hpc`. |
| 5 | +//! |
| 6 | +//! Substrate-tier pillar: when activated, this pillar will certify that |
| 7 | +//! the Difference-of-Gaussians (DoG) center-surround resonance kernel |
| 8 | +//! consumed by the dragonfly-tier cognitive shader has exactly one local |
| 9 | +//! maximum at the origin and exactly one annular minimum at the surround |
| 10 | +//! radius, across the full parameter band the production stack uses. |
| 11 | +//! |
| 12 | +//! # The unimodality claim |
| 13 | +//! |
| 14 | +//! For two centered isotropic Gaussians with standard deviations |
| 15 | +//! `σ_c < σ_s`, the Difference-of-Gaussians is |
| 16 | +//! |
| 17 | +//! ```text |
| 18 | +//! DoG(r ; σ_c, σ_s) = G(r ; σ_c) − G(r ; σ_s) |
| 19 | +//! ``` |
| 20 | +//! |
| 21 | +//! Differentiating with respect to `r` and setting to zero gives the |
| 22 | +//! single positive root `r_min(σ_c, σ_s)`. For DoG to behave as a |
| 23 | +//! center-surround kernel — peak at origin, negative annulus, decay to |
| 24 | +//! zero — we need: |
| 25 | +//! |
| 26 | +//! 1. `DoG(0) > 0` (positive at center) |
| 27 | +//! 2. `DoG'(r) < 0` for `0 < r < r_min` (monotone decrease from peak) |
| 28 | +//! 3. `DoG'(r) > 0` for `r > r_min` (monotone increase from annulus to zero) |
| 29 | +//! 4. Exactly one root in `(0, ∞)` for the equation `DoG(r) = 0` |
| 30 | +//! |
| 31 | +//! These hold for any `σ_c < σ_s`, but the *measurable* sharpness of the |
| 32 | +//! center-surround structure depends on the ratio `κ = σ_s / σ_c`. The |
| 33 | +//! production stack uses `κ ∈ [1.5, 3.0]`; values outside this band |
| 34 | +//! produce either too-broad surrounds (resonance bleeds into neighbors, |
| 35 | +//! cascade misfires) or too-sharp surrounds (numerical instability at |
| 36 | +//! the inflection point). |
| 37 | +//! |
| 38 | +//! # Why the substrate needs this |
| 39 | +//! |
| 40 | +//! The dragonfly Mexican-hat resonance is the center-surround operator |
| 41 | +//! that implements lateral inhibition in the cognitive shader. Bad |
| 42 | +//! parameter choices (κ outside the band, or accidental introduction |
| 43 | +//! of a kernel that's a sum-of-Gaussians rather than a difference) |
| 44 | +//! produce *bimodal* or *saddle* responses that look like resonance |
| 45 | +//! but bias activation toward the wrong neighborhoods. The failure |
| 46 | +//! mode is silent: the cascade still produces top-K results, just |
| 47 | +//! systematically biased. |
| 48 | +//! |
| 49 | +//! # Probe design (deferred until kernel lands) |
| 50 | +//! |
| 51 | +//! When the Mexican-hat / DoG kernel lands in `ndarray::hpc::dragonfly` |
| 52 | +//! (or wherever it ultimately lives), Pillar-15 will: |
| 53 | +//! |
| 54 | +//! 1. Sweep `κ = σ_s / σ_c ∈ {1.1, 1.3, 1.5, 1.8, 2.0, 2.5, 3.0, 4.0}`. |
| 55 | +//! 2. For each κ, evaluate the DoG kernel on a 1D radial grid of |
| 56 | +//! `N_RADIAL = 4096` samples covering `r ∈ [0, 6 σ_s]`. |
| 57 | +//! 3. Numerically locate all critical points (sign changes in `DoG'`) |
| 58 | +//! via finite differences with `h = r_max / N_RADIAL`. |
| 59 | +//! 4. Verify: |
| 60 | +//! - Exactly one positive critical point (the annular minimum). |
| 61 | +//! - `DoG(0) > 0` and is the global maximum on the grid. |
| 62 | +//! - `DoG(r) → 0` as `r → r_max` within `1e-6 · DoG(0)`. |
| 63 | +//! - For `κ ∈ [1.5, 3.0]`, the second-derivative ratio at the |
| 64 | +//! inflection point is within the production-band budget. |
| 65 | +//! |
| 66 | +//! # Activation gate |
| 67 | +//! |
| 68 | +//! Active when: |
| 69 | +//! - `ndarray::hpc::dragonfly::mexican_hat` (or canonical location) is |
| 70 | +//! exposed as a public function `dog_eval(r: f32, sigma_c: f32, sigma_s: f32) -> f32`. |
| 71 | +//! - This module's `prove_pillar_15` body is updated to call it; the |
| 72 | +//! current `DEFERRED` placeholder must be replaced with the real probe. |
| 73 | +//! |
| 74 | +//! # Pass criteria (when active) |
| 75 | +//! |
| 76 | +//! - All seven critical-point checks pass for every κ in the sweep. |
| 77 | +//! - `psd_rate ≥ 1.0` (every κ-sample contributes a binary pass/fail; |
| 78 | +//! any failure tanks the rate). |
| 79 | +//! - `lognorm_concentration` = `log(1 + max kappa-band deviation)`. |
| 80 | +//! |
| 81 | +//! # References |
| 82 | +//! |
| 83 | +//! * Marr, D., & Hildreth, E. (1980). *Theory of edge detection.* |
| 84 | +//! Proc. R. Soc. Lond. B 207(1167). (The original DoG / Marr-Hildreth |
| 85 | +//! operator, source of the Mexican-hat name.) |
| 86 | +//! * Lindeberg, T. (1994). *Scale-Space Theory in Computer Vision.* |
| 87 | +//! Kluwer. (Scale-space justification for the σ_s / σ_c ratio band.) |
| 88 | +//! |
| 89 | +//! # SEED |
| 90 | +//! |
| 91 | +//! `PILLAR_15_SEED = 0x_C15_DAD51_DEFE` (Mexican-hat unimodality, reserved). |
| 92 | +
|
| 93 | +use crate::hpc::pillar::prove_runner::PillarReport; |
| 94 | + |
| 95 | +/// Deterministic seed for all Pillar-15 RNG streams. |
| 96 | +pub const PILLAR_15_SEED: u64 = 0x_C15D_AD51_DEFE; |
| 97 | + |
| 98 | +/// Run the Pillar-15 deferred placeholder. |
| 99 | +/// |
| 100 | +/// **Currently DEFERRED.** Returns a `PillarReport` with all-zero |
| 101 | +/// numeric fields and `passed = true`, signalling "no probe ran". |
| 102 | +/// Replace the body when the Mexican-hat kernel lands; see the |
| 103 | +/// "Probe design" section in the module docs for the activation plan. |
| 104 | +/// |
| 105 | +/// # Returns |
| 106 | +/// |
| 107 | +/// A deferred-shape `PillarReport`: |
| 108 | +/// - `n_paths = 0`, `n_hops = 0` (no probe executed) |
| 109 | +/// - `psd_rate = 0.0`, `lognorm_concentration = 0.0` |
| 110 | +/// - `passed = true` (the deferral itself is not a failure) |
| 111 | +pub fn prove_pillar_15() -> PillarReport { |
| 112 | + PillarReport { |
| 113 | + pillar_id: 15, |
| 114 | + seed: PILLAR_15_SEED, |
| 115 | + n_paths: 0, |
| 116 | + n_hops: 0, |
| 117 | + psd_rate: 0.0, |
| 118 | + lognorm_concentration: 0.0, |
| 119 | + passed: true, |
| 120 | + } |
| 121 | +} |
| 122 | + |
| 123 | +// ── Tests ─────────────────────────────────────────────────────────────────── |
| 124 | + |
| 125 | +#[cfg(test)] |
| 126 | +mod tests { |
| 127 | + use super::*; |
| 128 | + |
| 129 | + #[test] |
| 130 | + fn pillar_15_seed_matches_spec() { |
| 131 | + assert_eq!(PILLAR_15_SEED, 0x_C15D_AD51_DEFE); |
| 132 | + } |
| 133 | + |
| 134 | + #[test] |
| 135 | + fn pillar_15_deferred_shape() { |
| 136 | + // DEFERRED probe must return a recognisable deferred-shape report: |
| 137 | + // zeros everywhere except pillar_id and seed, passed = true. |
| 138 | + let r = prove_pillar_15(); |
| 139 | + assert_eq!(r.pillar_id, 15); |
| 140 | + assert_eq!(r.seed, PILLAR_15_SEED); |
| 141 | + assert_eq!(r.n_paths, 0); |
| 142 | + assert_eq!(r.n_hops, 0); |
| 143 | + assert_eq!(r.psd_rate, 0.0); |
| 144 | + assert_eq!(r.lognorm_concentration, 0.0); |
| 145 | + assert!(r.passed, "deferred pillar should not be marked failed"); |
| 146 | + } |
| 147 | + |
| 148 | + #[test] |
| 149 | + fn pillar_15_seed_anchored() { |
| 150 | + let r1 = prove_pillar_15(); |
| 151 | + let r2 = prove_pillar_15(); |
| 152 | + assert_eq!(r1.passed, r2.passed); |
| 153 | + assert_eq!(r1.psd_rate, r2.psd_rate); |
| 154 | + assert_eq!(r1.lognorm_concentration, r2.lognorm_concentration); |
| 155 | + } |
| 156 | +} |
0 commit comments