Armatura (1D series shield)¶
Armatura cleans one series of numbers: it finds the readings that are obviously broken (a sudden huge value, a missing reading) and replaces them with sensible values. You get back the cleaned series and the list of places it changed.
A loss curve that suddenly jumps to 10⁶. A sensor channel that drops a reading and returns NaN. A token-likelihood stream that goes from 0.9 to 0 for one sample. These are the kinds of single-value glitches that break a downstream pipeline silently: the model does not complain, it just produces wrong numbers from that point on.
Armatura is the shield for a single 1D series. You give it an array; you get back
the same array, with the broken samples replaced by the local baseline, plus the list of
indices that were replaced.
1. Protect the series¶
One sensor channel at 100 Hz: noise around 0.5, one absurd value (9999) at sample 100, one NaN at sample 200.
import numpy as np
from dense_armor import Armatura
rng = np.random.default_rng(42)
x = 0.5 + 0.1 * rng.standard_normal(300)
x[100], x[200] = 9999.0, float("nan")
clean, K, anomalies = Armatura(livello_ia=0.0).analizza(x)
print(len(clean), anomalies, round(float(clean[100]), 3), K[100], K[50])
clean has the same shape as x: the two broken samples are replaced by the local baseline
(9999 becomes 0.463). Ordinary samples are kept, except those the engine's trigger classifies
as static, which are replaced by the local median without being listed in anomalies (35 of the
300 here, see Hybrid engine, step 3). anomalies lists the replaced indices,
[100, 200]. K is one flag per sample from the engine's trigger: 1 where the spike rule fired
(sample 100), 0 elsewhere; the NaN is cleaned before the trigger, so sample 200 is in anomalies
with K = 0.
livello_ia = 0 means "actively filter". livello_ia = 1 means "only mark, do not
change the values" — useful when you want to log what the shield would have done
without altering the stream.
2. What "local baseline" means¶
Armatura looks at a window of samples before the one being scored (never after): its
baseline is the mean of those previous samples (radius min(20, max(3, n // 3))), and a
binary trigger decides whether the sample is an impulse. If it is, it is replaced by the
baseline; otherwise it passes through unchanged. The first two samples are never tested (the
trigger needs two previous points), so a glitch there must be caught by another check.
The consequence, on the running example:
- The value 9999 at sample 100 is far above the baseline of the previous samples, so it is
replaced. Index 100 appears in
anomalies. - The NaN at sample 200 never enters the window (the shield drops non-finite samples
before the comparison), so the next finite sample is scored against the window ending
at sample 199. Index 200 appears in
anomalies, andclean[200]is the baseline.
3. What it is not for¶
Armatura is a point-level shield. It removes isolated spikes and non-finite values.
It does not remove a slow drift, and it does not classify a regime change: those need a
different tool (see CUSUM and Arbiter).
If your signal is a step change that is genuinely intended, Armatura leaves it alone
after the first few samples, because after those samples the step is the new local
baseline.
4. The engine inside¶
Armatura is built on core.hybrid_engine, the binary-trigger engine that generalises
the logic already verified in Dense-Evolution's own
ia_utils.vector_healing.enhanced_dense_healing_hybrid. See
Hybrid engine for the internals.
API reference¶
armatura ¶
armatura.py — L'Armatura: istanza indossabile dello scudo per una serie 1D. Usa solo i moduli in core/ e utility/ di questo pacchetto.
Uso rapido (CLI): python -m dense_armor 1.2 1.3 9999 1.25 nan 1.3 python -m dense_armor file_con_numeri.txt
Uso da codice
from dense_armor import Armatura a = Armatura(livello_ia=0.0) # 0=IA neonata (FILTRA) ... 1=matura (solo MARCA) pulito, K, anomalie = a.analizza(serie) pulito, K, anomalie = a.analizza(serie_oggi, riferimento=baseline_di_ieri) # anti-deriva
Armatura ¶
Armatura(
static_threshold: float = 0.15,
initial_damping: float = 0.85,
alpha: float = 0.05,
soglia_anomalia: float | None = None,
livello_ia: float = 1.0,
)
Scudo indossabile con CLIP DINAMICO universale.
livello_ia (0..1): quanto e' matura l'IA che lo indossa. 0.0 -> clip pieno: lo scudo FILTRA il dato (corazza per IA neonata) 1.0 -> clip zero: lo scudo NON tocca il dato, solo MARCA (lente per IA matura) PAVIMENTO: la marcatura delle anomalie non viene MAI clippata — a nessun livello lo scudo tace (l'anomalia puo' ESSERE la risposta: mai cancellarla in silenzio). Il livello puo' essere misurato, non dichiarato: Armatura.livello_da_entropia(entropia, vocab_size).
MEMORIA: lo scudo e' una funzione PURA, senza stato (leggero per design).
La memoria appartiene all'IA che lo indossa: per vedere la DERIVA LENTA
passa la tua baseline storica come riferimento.
static_threshold/initial_damping/alpha — mantenuti per compatibilità di firma con le versioni precedenti, non usati dal motore hybrid (che non ha stato/calibrazione: è una funzione pura, vedi CHANGELOG 1.1.0). soglia_anomalia — soglia fissa opzionale (None = calcolata dai dati); livello_ia — 0=neonata (filtra) .. 1=matura (solo marca).
Source code in dense_armor/armatura.py
set_livello ¶
livello_da_entropia
staticmethod
¶
Livello MISURATO: 1 - entropia/log(V) (stessa formula dello sfogo dinamico).
Source code in dense_armor/armatura.py
analizza ¶
analizza(
serie: ndarray, riferimento: ndarray | None = None
) -> tuple[np.ndarray, np.ndarray, list[int]]
serie: 1D (lista/array). Per tensori N-D: passare tensore.ravel() e rifare reshape dopo (lo scudo e' agnostico: la trasposizione basta). Ritorna (pulito, K, indici_anomalie).
Source code in dense_armor/armatura.py
deriva ¶
RILEVATORE DI DERIVA LENTA (usa METRO, come suggerito da Salvatore).
La rana bollita: incrementi infinitesimi (es. +0.004/passo) invisibili
allo scudo punto-per-punto. Qui si guarda la TENDENZA degli incrementi:
se la loro media e' sistematica rispetto al rumore, c'e' deriva — e
METRO (scaler logaritmico) ne risolve la scala anche quando e' sotto
la precisione visibile. Funziona SENZA baseline storica (ma la baseline
via riferimento in analizza() resta il metodo piu' forte).
Ritorna (tasso_per_passo, significativa: bool, esponente_metro).
Source code in dense_armor/armatura.py
referto_json ¶
Referto MACCHINA-LEGGIBILE (dict pronto per json.dumps). Pensato per IA e altri programmi: niente prosa, solo dati. I valori non finiti diventano stringhe ("NaN") per dare JSON valido.
Source code in dense_armor/armatura.py
referto ¶
Analisi + referto leggibile.
Source code in dense_armor/armatura.py
main ¶
Entry point CLI: python -m dense_armor [--json] <file_o_numeri...>.
Source code in dense_armor/armatura.py
Details¶
See also: Hybrid engine — the core/hybrid_engine.py module
Armatura is built on. Orca — the full input + output shield for an entire
model, if you have a model rather than a bare series.