| Title: | Representation-Level Control Surfaces for Reliability Sensing |
|---|---|
| Description: | Implements the Representation-Level Control Surfaces (RLCS) paradigm for ensuring the reliability of autonomous systems and AI models. It provides three deterministic sensors: Residual Likelihood (ResLik) for population-level anomaly detection, Temporal Consistency Sensor (TCS) for drift and shock detection, and Agreement Sensor for multi-modal redundancy checks. These sensors feed into a standardized control surface that issues 'PROCEED', 'DEFER', or 'ABSTAIN' signals based on strict safety invariants, allowing systems to detect and react to out-of-distribution states, sensor failures, and environmental shifts before they propagate to decision-making layers. |
| Authors: | MD. Arshad [aut, cre] |
| Maintainer: | MD. Arshad <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-06-07 09:18:56 UTC |
| Source: | https://github.com/cran/resLIK |
The Agreement Sensor measures the alignment between two latent representations, typically from different modalities or redundant sensors. It uses cosine similarity to quantify agreement.
agreement(z1, z2, eps = 1e-08)agreement(z1, z2, eps = 1e-08)
z1 |
Numeric vector or matrix. The first representation. |
z2 |
Numeric vector or matrix. The second representation. Must have the same shape as |
eps |
Numeric. Small constant for numerical stability. Defaults to 1e-8. |
Agreement Sensor
The sensor computes the cosine similarity between z1 and z2:
Values close to 1 indicate strong agreement, 0 indicates orthogonality (no agreement),
and -1 indicates opposition. In the context of RLCS, high positive agreement is generally
required for a PROCEED signal.
A list containing:
agreement |
The cosine similarity score (-1 to 1). |
# Example 1: Perfect Agreement z1 <- c(1, 2, 3) z2 <- c(2, 4, 6) agreement(z1, z2) # Example 2: Disagreement (Orthogonal) z3 <- c(1, 0, 0) z4 <- c(0, 1, 0) agreement(z3, z4)# Example 1: Perfect Agreement z1 <- c(1, 2, 3) z2 <- c(2, 4, 6) agreement(z1, z2) # Example 2: Disagreement (Orthogonal) z3 <- c(1, 0, 0) z4 <- c(0, 1, 0) agreement(z3, z4)
The Residual Likelihood (ResLik) sensor measures the conformity of a latent representation against a population reference distribution. It acts as a soft gate, suppressing "out-of-distribution" (OOD) signals while preserving "in-distribution" (ID) fidelity.
reslik(z, ref_mean = 0, ref_sd = 1, lambda = 1, tau = 0.05)reslik(z, ref_mean = 0, ref_sd = 1, lambda = 1, tau = 0.05)
z |
Numeric vector or matrix. The latent representation to evaluate. |
ref_mean |
Numeric or vector. The reference mean of the population. Defaults to 0. |
ref_sd |
Numeric or vector. The reference standard deviation of the population. Defaults to 1. |
lambda |
Numeric. The sensitivity of the gate. Higher values suppress OOD samples more aggressively. Defaults to 1.0. |
tau |
Numeric. The dead-zone threshold. Discrepancies below this value are ignored. Defaults to 0.05. |
Population-Level Sensor (ResLik)
The sensor operates in four steps:
Normalization: The input z is Z-score normalized using ref_mean and ref_sd.
Discrepancy: The Mean Absolute Deviation (MAD) is computed for each sample.
Gating: A gating factor is computed as exp(-lambda * max(0, discrepancy - tau)).
This creates a "dead-zone" tau where minor deviations are ignored.
Output: The original z is scaled by the gating factor.
This implementation is fully deterministic and stateless.
A list containing:
gated |
The gated representation (same shape as |
diagnostics |
A list of diagnostic metrics:
|
# Example 1: In-Distribution Sample z_id <- c(0.1, -0.2, 0.05) out_id <- reslik(z_id) print(out_id$gated) # Should be close to z_id # Example 2: Out-of-Distribution Sample z_ood <- c(5.0, 5.0, 5.0) out_ood <- reslik(z_ood) print(out_ood$gated) # Should be strongly suppressed# Example 1: In-Distribution Sample z_id <- c(0.1, -0.2, 0.05) out_id <- reslik(z_id) print(out_id$gated) # Should be close to z_id # Example 2: Out-of-Distribution Sample z_ood <- c(5.0, 5.0, 5.0) out_ood <- reslik(z_ood) print(out_ood$gated) # Should be strongly suppressed
The Control Surface integrates inputs from multiple reliability sensors (ResLik, TCS, Agreement)
to issue a standardized control signal (PROCEED, DEFER, ABSTAIN). It uses a deterministic,
rule-based logic to ensure safety and predictability.
rlcs_control(reslik, tcs = NULL, agreement = NULL, thresholds = list())rlcs_control(reslik, tcs = NULL, agreement = NULL, thresholds = list())
reslik |
List. The output from the |
tcs |
List (Optional). The output from the |
agreement |
List (Optional). The output from the |
thresholds |
List. Custom thresholds to override defaults:
|
Deterministic Control Surface
The logic implements a "Conservative OR" strategy:
ABSTAIN: Triggered if ResLik discrepancy exceeds reslik_max_disc.
This indicates the input is fundamentally invalid (e.g., sensor failure).
DEFER: Triggered if TCS consistency is below tcs_consistency OR
Agreement is below agreement. This indicates valid but unstable or conflicting data.
PROCEED: Default state if no negative flags are raised.
A character vector of signals (same length as input batch).
# Mock Inputs res_pass <- list(diagnostics = list(discrepancy = c(0.1), max_discrepancy = 0.1)) res_fail <- list(diagnostics = list(discrepancy = c(5.0), max_discrepancy = 5.0)) tcs_pass <- list(consistency = c(0.9)) tcs_fail <- list(consistency = c(0.1)) # Scenario 1: All Good rlcs_control(res_pass, tcs_pass) # Scenario 2: ResLik Fail -> ABSTAIN rlcs_control(res_fail, tcs_pass) # Scenario 3: TCS Fail -> DEFER rlcs_control(res_pass, tcs_fail)# Mock Inputs res_pass <- list(diagnostics = list(discrepancy = c(0.1), max_discrepancy = 0.1)) res_fail <- list(diagnostics = list(discrepancy = c(5.0), max_discrepancy = 5.0)) tcs_pass <- list(consistency = c(0.9)) tcs_fail <- list(consistency = c(0.1)) # Scenario 1: All Good rlcs_control(res_pass, tcs_pass) # Scenario 2: ResLik Fail -> ABSTAIN rlcs_control(res_fail, tcs_pass) # Scenario 3: TCS Fail -> DEFER rlcs_control(res_pass, tcs_fail)
The Temporal Consistency Sensor (TCS) monitors the evolution of a latent representation over time. It quantifies "drift" as the relative rate of change and converts it into a stability score.
tcs(z_t, z_prev, eps = 1e-06)tcs(z_t, z_prev, eps = 1e-06)
z_t |
Numeric vector or matrix. The current latent representation. |
z_prev |
Numeric vector or matrix. The previous latent representation. Must have the same shape as |
eps |
Numeric. Small constant to avoid division by zero. Defaults to 1e-6. |
Temporal Consistency Sensor
The sensor computes the L2 distance between the current state z_t and the previous state z_prev.
This distance is normalized by the magnitude of the previous state to produce a relative drift score.
Consistency is defined as exp(-drift).
This metric is essential for detecting "shock" events where the representation changes too rapidly for the downstream system to adapt safely.
A list containing:
drift |
The relative drift score (non-negative). |
consistency |
The consistency score (0 to 1). |
# Example 1: Stable Evolution z_t0 <- c(1.0, 0.0) z_t1 <- c(1.01, 0.01) tcs(z_t1, z_t0) # Example 2: Sudden Shock z_shock <- c(5.0, 0.0) tcs(z_shock, z_t0)# Example 1: Stable Evolution z_t0 <- c(1.0, 0.0) z_t1 <- c(1.01, 0.01) tcs(z_t1, z_t0) # Example 2: Sudden Shock z_shock <- c(5.0, 0.0) tcs(z_shock, z_t0)