-
Notifications
You must be signed in to change notification settings - Fork 0
Pillar-11 W1 + W4: the cross-repo signature parity bridge, and PSD at depth-infinity #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| target/ | ||
| Cargo.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # sigker-parity — the cross-repo gate for the Pillar-11 signature lanes. | ||
| # | ||
| # `ndarray::hpc::pillar::signature::signature_d2_deg3` (hardware: f32, fixed | ||
| # d=2/deg-3, Chen accumulation) and lance-graph `sigker::signature_truncated` | ||
| # (reference: f64, any d/depth) compute the SAME iterated integrals and had | ||
| # zero cross-checks — census finding F-4 of | ||
| # `pillar11-signature-certification-unification-v1`. The workspace's own | ||
| # architecture rule (ndarray = hardware, lance-graph = thinking) blesses the | ||
| # split but demands the parity test it never got. This crate is that test | ||
| # (W1), plus the depth-infinity PSD leg (W4) that needs the same sibling. | ||
| # | ||
| # EXCLUDED from the workspace (see root Cargo.toml `exclude`) because its | ||
| # `sigker` dep is a PATH into a sibling checkout. An unconditional path dep | ||
| # whose target is absent fails manifest resolution for the WHOLE workspace — | ||
| # ndarray CI does not check lance-graph out, so an in-workspace dep here | ||
| # would break every ndarray build on a fresh clone. Excluded, it costs | ||
| # nothing when the sibling is missing and runs on demand: | ||
| # | ||
| # cargo test --manifest-path crates/sigker-parity/Cargo.toml | ||
| # | ||
| # Same shape as `crates/wasm-simd-parity` and `crates/neon-simd-parity`. | ||
| [package] | ||
| name = "sigker-parity" | ||
| version = "0.0.0" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| ndarray = { path = "../..", default-features = false, features = ["std", "hpc-extras", "pillar"] } | ||
|
|
||
| [dev-dependencies] | ||
| sigker = { path = "../../../lance-graph/crates/sigker" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //! Diagnostic only: is the W1 gap a FORMULA difference or f32 accumulation? | ||
| use ndarray::hpc::pillar::signature::signature_d2_deg3; | ||
| use sigker::signature_truncated; | ||
|
|
||
| const NAMES: [&str; 15] = [ | ||
| "s0", "1x", "1y", "2xx", "2xy", "2yx", "2yy", "3xxx", "3xxy", "3xyx", "3xyy", "3yxx", "3yxy", "3yyx", "3yyy", | ||
| ]; | ||
|
|
||
| fn cmp(tag: &str, flat: &[f32], n: usize) { | ||
| let hw = signature_d2_deg3(flat, n); | ||
| let pts: Vec<Vec<f64>> = (0..n) | ||
| .map(|k| vec![flat[2 * k] as f64, flat[2 * k + 1] as f64]) | ||
| .collect(); | ||
| let refr: Vec<f64> = signature_truncated(&pts, 3) | ||
| .levels | ||
| .iter() | ||
| .flat_map(|l| l.iter().copied()) | ||
| .collect(); | ||
| println!("--- {tag} (n={n}) ---"); | ||
| for i in 0..15 { | ||
| let (h, r) = (hw[i] as f64, refr[i]); | ||
| let d = (h - r).abs(); | ||
| let rel = if r.abs() > 1e-12 { d / r.abs() } else { d }; | ||
| if rel > 1e-6 { | ||
| println!(" {:>5}: hw {:+.9} ref {:+.9} rel {:.3e} <== DIFFERS", NAMES[i], h, r, rel); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| // Single segment: closed form, zero accumulation — any gap here is FORMULA. | ||
| cmp("one segment", &[0.0, 0.0, 1.0, 0.5], 2); | ||
| // Two segments: Chen composition enters. | ||
| cmp("two segments", &[0.0, 0.0, 1.0, 0.5, 1.3, -0.2], 3); | ||
| // Three, exact small values (representable in f32) — still formula-only. | ||
| cmp("three segments", &[0.0, 0.0, 0.5, 0.25, 0.75, -0.5, 0.25, 0.125], 4); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //! Pre-registration sweep: how does the hardware-vs-reference error scale, | ||
| //! and under WHICH normalization is it a stable gate? | ||
| use ndarray::hpc::pillar::signature::signature_d2_deg3; | ||
| use sigker::signature_truncated; | ||
|
|
||
| struct Rng(u64); | ||
| impl Rng { | ||
| fn f(&mut self) -> f32 { | ||
| let mut x = self.0; | ||
| x ^= x >> 12; | ||
| x ^= x << 25; | ||
| x ^= x >> 27; | ||
| self.0 = x; | ||
| ((x.wrapping_mul(0x2545_F491_4F6C_DD1D) >> 40) as f32 / (1u32 << 24) as f32) - 0.5 | ||
| } | ||
| } | ||
|
|
||
| // level of each of the 15 coefficients | ||
| const LEVEL: [usize; 15] = [0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3]; | ||
|
|
||
| fn main() { | ||
| println!("{:>6} {:>12} {:>14} {:>16}", "N", "worst |abs|", "worst /coeff", "worst /levelmax"); | ||
| for &n in &[16usize, 32, 64, 128, 256] { | ||
| let mut rng = Rng(0x9E37_79B9_7F4A_7C15); | ||
| let (mut wa, mut wc, mut wl) = (0.0f64, 0.0f64, 0.0f64); | ||
| for _ in 0..1000 { | ||
| let (mut x, mut y) = (0.0f32, 0.0f32); | ||
| let mut flat = Vec::with_capacity(n * 2); | ||
| let mut pts = Vec::with_capacity(n); | ||
| for _ in 0..n { | ||
| flat.push(x); | ||
| flat.push(y); | ||
| pts.push(vec![x as f64, y as f64]); | ||
| x += rng.f(); | ||
| y += rng.f(); | ||
| } | ||
| let hw = signature_d2_deg3(&flat, n); | ||
| let refr: Vec<f64> = signature_truncated(&pts, 3) | ||
| .levels | ||
| .iter() | ||
| .flat_map(|l| l.iter().copied()) | ||
| .collect(); | ||
| // characteristic magnitude per level, from the REFERENCE | ||
| let mut lvmax = [0.0f64; 4]; | ||
| for i in 0..15 { | ||
| lvmax[LEVEL[i]] = lvmax[LEVEL[i]].max(refr[i].abs()); | ||
| } | ||
| for i in 0..15 { | ||
| let d = (hw[i] as f64 - refr[i]).abs(); | ||
| wa = wa.max(d); | ||
| if refr[i].abs() > 1e-12 { | ||
| wc = wc.max(d / refr[i].abs()); | ||
| } | ||
| let s = lvmax[LEVEL[i]].max(1e-12); | ||
| wl = wl.max(d / s); | ||
| } | ||
| } | ||
| println!("{n:>6} {wa:>12.3e} {wc:>14.3e} {wl:>16.3e}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| //! Does depth-inf self-kernel concentration shrink like 1/sqrt(N) (a sample- | ||
| //! size effect) or plateau (a genuine heavy tail)? Measure, do not assume. | ||
| use ndarray::hpc::pillar::signature::brownian_path_d2; | ||
| use ndarray::hpc::pillar::SplitMix64; | ||
| use sigker::{signature_kernel_pde, signature_truncated}; | ||
|
|
||
| const SEED: u64 = 0x5EED_1111_5164_A7AB; | ||
| const N_STEPS: usize = 50; | ||
|
|
||
| fn pool(n: usize) -> Vec<Vec<Vec<f64>>> { | ||
| let mut rng = SplitMix64::new(SEED); | ||
| (0..n) | ||
| .map(|_| { | ||
| let p = brownian_path_d2(&mut rng, N_STEPS); | ||
| (0..=N_STEPS) | ||
| .map(|k| vec![p[2 * k] as f64, p[2 * k + 1] as f64]) | ||
| .collect() | ||
| }) | ||
| .collect() | ||
| } | ||
|
|
||
| fn stats(v: &[f64]) -> (f64, f64, f64) { | ||
| let n = v.len(); | ||
| let h = n / 2; | ||
| let m1 = v[..h].iter().sum::<f64>() / h as f64; | ||
| let m2 = v[h..].iter().sum::<f64>() / (n - h) as f64; | ||
| let mean = v.iter().sum::<f64>() / n as f64; | ||
| let var = v.iter().map(|x| (x - mean).powi(2)).sum::<f64>() / n as f64; | ||
| // half-mean gap, and the coefficient of variation that predicts it | ||
| ((m1 - m2).abs() / mean, var.sqrt() / mean, mean) | ||
| } | ||
|
|
||
| fn main() { | ||
| println!("depth-INFINITY (Goursat PDE)"); | ||
| println!("{:>6} {:>12} {:>10} {:>14} {:>12}", "N", "concentr", "CV", "predicted", "mean K"); | ||
| for &n in &[64usize, 128, 256, 512, 1000] { | ||
| let p = pool(n); | ||
| let k: Vec<f64> = p.iter().map(|x| signature_kernel_pde(x, x)).collect(); | ||
| let (c, cv, mean) = stats(&k); | ||
| // For independent samples the expected half-mean gap ~ CV * sqrt(8/(pi*N)) | ||
| let pred = cv * (8.0 / (core::f64::consts::PI * n as f64)).sqrt(); | ||
| println!("{n:>6} {c:>12.4} {cv:>10.3} {pred:>14.4} {mean:>12.4e}"); | ||
| } | ||
| println!("\ndepth-3 TRUNCATED (the existing battery's kernel, f64 reference)"); | ||
| println!("{:>6} {:>12} {:>10} {:>14} {:>12}", "N", "concentr", "CV", "predicted", "mean K"); | ||
| for &n in &[64usize, 1000] { | ||
| let p = pool(n); | ||
| let k: Vec<f64> = p | ||
| .iter() | ||
| .map(|x| { | ||
| let s = signature_truncated(x, 3); | ||
| s.levels | ||
| .iter() | ||
| .flat_map(|l| l.iter()) | ||
| .map(|v| v * v) | ||
| .sum::<f64>() | ||
| }) | ||
| .collect(); | ||
| let (c, cv, mean) = stats(&k); | ||
| let pred = cv * (8.0 / (core::f64::consts::PI * n as f64)).sqrt(); | ||
| println!("{n:>6} {c:>12.4} {cv:>10.3} {pred:>14.4} {mean:>12.4e}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| pub fn sibling_is_wired() -> bool { | ||
| true | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Document
sibling_is_wired.Add a
///API comment and a/// # Examplessection before this public function.As per coding guidelines, “All public APIs (public functions and methods) must have
///doc comments with examples.”🤖 Prompt for AI Agents
Source: Coding guidelines