dsfb_debug/dsa.rs
1//! DSFB-Debug: Deterministic Structural Accumulator (DSA) — paper §5
2//! and Appendix D.
3//!
4//! The DSA is the running scalar score that aggregates five rolling
5//! structural features into a single value the policy engine consumes:
6//!
7//! ```text
8//! DSA(k) = w1·boundary_density(k)
9//! + w2·drift_persist(k)
10//! + w3·slew_density(k)
11//! + w4·ewma_occupancy(k)
12//! + w5·motif_recurrence(k)
13//! ```
14//!
15//! Default weights are unit (w_i = 1.0), reproducing the paper's
16//! reference scoring. Operators tuning per-site can adjust weights
17//! via the `EngineConfig` (see `config.rs`).
18//!
19//! The DSA score is one input to the `PolicyState` decision in
20//! `policy.rs`; higher scores escalate from `Silent`→`Watch`→
21//! `Review`→`Escalate`. The score is a pure function of its inputs;
22//! Theorem 9 deterministic replay holds trivially.
23
24/// Compute DSA score from rolling features. Unit weights (all w=1.0).
25#[inline]
26pub fn compute_dsa_score(
27 boundary_density: f64,
28 drift_persistence: f64,
29 slew_density: f64,
30) -> f64 {
31 // Unit weights per semiconductor crate convention
32 boundary_density + drift_persistence + slew_density
33}
34
35/// Check DSA directional consistency gate
36/// Returns true if DSA score >= τ
37#[inline]
38pub fn consistency_gate(dsa_score: f64, tau: f64) -> bool {
39 dsa_score >= tau
40}