Skip to main content

Crate struktura

Crate struktura 

Source
Expand description

Time-series anomaly detection with no training data.

Struktura detects when the structure of a signal changes: detrended fluctuation analysis (DFA) for the correlation structure, plus a streaming monitor that calibrates itself on the first rows of your data.

§Quick start

use struktura::{compare, is_degraded};

// Compare current readings against a known-good baseline
let result = compare(&normal_readings, &current_readings);
println!("{}", result); // "HEALTHY shift=+0.003" or "CRITICAL shift=-0.45"

// Or just ask: is this signal degraded compared to baseline?
if is_degraded(&normal_readings, &current_readings) {
    trigger_alert();
}

§Domains

  • space: spacecraft telemetry monitoring (reaction wheels, magnetometers, batteries)
  • market: financial regime detection (trending / random walk / mean-reverting)
  • text: writing rhythm analysis (human literary prose vs mechanical/AI)
  • rhythm: event timing analysis (git commits, heartbeats, keystrokes)

Works in no_std environments (default-features = false). 85-112x faster than Python.

Modules§

autopilot
Autonomic layer over the hybrid monitor: detect → decide → adapt → continue, without a human in the loop.
case
A case directory: saves a recording, its incidents, detector config, and a manifest so struktura replay can reproduce and diff the analysis.
changepoint
Changepoint detection: locates WHERE the structure changed.
classify
Signal classification — what kind of signal is this?
codegen
conformal
Conformal prediction: calibrated confidence for any detector.
context
Operating context: column typing and a context timeline that pairs each sample row with its active operating mode, command, and annotations.
evolve_real
Evolve against real labeled data: the bridge between the synthetic RED/BLUE loop (crate::redblue) and actual benchmark anomalies.
ffi
fingerprint
Structural fingerprint — the “DNA” of a signal.
genome
Genome structural analysis via DFA on GC-content windows.
incident
Incident records: groups temporally proximate alarms into inspectable incidents with per-channel evidence, context, and reconstruction state. IncidentBuilder folds AlarmReports and Events into Incidents (alarms within gap ticks join; farther out starts a new one), pulling in explanations via explain_alarm and context from a ContextTimeline.
market
Financial time series regime detection via DFA.
mfdfa
Multifractal DFA (MFDFA) — reveals signals with multiple scaling regimes.
monitor
Flight-grade streaming hybrid health monitor.
prognosis
Prognosis: time-to-threshold estimation from a health-metric trajectory.
redblue
RED/BLUE adversarial self-improvement.
replay
Re-run a detector on a saved case, diff the output against the saved incidents, and report what changed.
report
Human-readable investigation report from incident records. Designed to be printed to a terminal or written to a Markdown file.
rhythm
Rhythm analysis — DFA on inter-event timing sequences.
rover
Rover health monitoring — structural analysis for planetary exploration.
rover_flight
Fixed-size rover health monitor for flight computers.
smap_eval
Telemanom-protocol evaluation with a closed-form predictor.
space
Spacecraft health monitoring via DFA structural analysis.
telemetry_bench
Coupled-spacecraft telemetry benchmark comparing DFA to the standard telemetry fault taxonomy (packet loss, spike, stuck, drift, regime shift, mixed).
text
Text structural analysis via DFA on sentence-length sequences.
trend
Trend detection: is the signal’s structure drifting over time?

Structs§

BaselineTracker
BootstrapCI
CompareResult
Result of comparing two signals.
DfaResult
Result of a DFA or ACR computation.
ShuffleProof
SlidingWindow
SplitHalfResult
StructuralLaw
Complete structural analysis of a time series.

Enums§

HealthVerdict
Health verdict comparing current DFA alpha against a known baseline.
LawQuality
How confident the analysis is in the derived scaling exponent.

Functions§

acr
Compute autocorrelation decay exponent.
analyze
Full structural analysis of a time series.
anomaly_scores
Per-window anomaly scores from sliding DFA.
bootstrap_alpha
Subsampling confidence interval for α (Politis–Romano style).
compare
Compare two signals and get a verdict: is the structure the same?
dfa
Compute the DFA scaling exponent of a time series.
dfa_box_sizes
Box sizes that dfa, dfa_into, dfa_fast_into and dfa_scratch use for a series of n samples: up to 12 distinct sizes, geometrically spaced from max(16, n / 50) to n / 4. Returns the sizes and how many of them are valid (0 when the range is empty).
dfa_fast_into
Prefix-sum DFA: identical boxes and mathematics to dfa_into, but the per-segment sums (Σy, Σj·y, Σy²) are O(1) prefix-difference lookups instead of an O(s) pass per segment. One O(n) pass builds the profile prefixes; each of the ≤12 box sizes then costs O(n/s) segments × O(1).
dfa_into
DFA with a caller-provided buffer, avoiding allocation on the hot path.
dfa_scratch
Allocation-free DFA: the same mathematics as dfa_into, with the cumulative profile written into a caller-owned slice. Runs on no_std targets with no heap at all; a stack array or a static mut buffer works.
dfa_short
DFA for short series (from about 24 samples), or None when the series cannot be measured (too short, constant, or fewer than 3 usable box sizes).
has_changed
Has the signal’s structure changed at all?
health_check
Compare current DFA alpha against a known healthy baseline.
is_degraded
Is the current signal structurally degraded compared to baseline?
prove_structure
sanitize
Filter out NaN and Inf values from a signal.
shuffle
Deterministic Fisher-Yates shuffle of a signal.
split_half_validate