Scale-Aware Temporal Facts: Carrying Over-Stationarization into Rule-Based Monitoring

Many real monitoring systems run in two stages. A numerical model forecasts sensor streams such as transformer temperature, road occupancy, or influenza rates. A set of temporal logic rules, written by operators, then turns those numbers into alarms like "the load has been abnormally high relative to its recent baseline for six hours while oil temperature approaches its limit." Each stage has been studied on its own. Forecasting research has found that normalizing every input window to zero mean and unit variance, the standard trick for training stability, erases the absolute levels, slopes and cross-series trends that matter. This side effect is called over-stationarization. Logic research has built fast engines that derive all consequences of temporal rules and are guaranteed to stop. This is finite materialization. Database research compiles those rules into goal-directed or SQL form so that only the relevant time range is evaluated, which is temporal query rewriting. Nobody has asked what happens at the interface between the two stages, where numbers become symbolic facts.

The thesis of this note is that the interface reproduces over-stationarization in symbolic form. If facts are extracted with fixed absolute thresholds, they go wrong as baselines drift. If facts are extracted from normalized signals, they cannot say whether a physical limit is near. The fix we propose mirrors the forecasting fix. Normalization statistics (rolling means and spreads) become first-class predicates inside the rule language, so that a rule can compare a value both against an absolute limit and against its own recent baseline. The new technical piece is letting those statistics be computed over derived states, such as "the baseline during the last day when the unit was in normal operation." This must be done without losing termination guarantees or goal-directed pruning. The application test asks whether forecasting gains from de-stationarization show up as better alarms, which is what operators actually consume.

Core Claim

We claim three things, in decreasing order of novelty.

The first is a language extension. DatalogMTL is Datalog extended with metric temporal operators such as "at some point in the past 5 hours." We add bounded-window statistic predicates, for example the mean of $X$ over the window $[t-w, t]$, restricted to time points where a derived predicate $S$ holds. These statistics are kept in a separate stage (stratified), so that a statistic never feeds back into the rules that define its own conditioning state.

The second is a pair of results for this extension. Finite materialisability is preserved: if the program without statistics is acyclic in the sense of Finitely Materialisable Datalog Programs with Metric Temporal Operators, treating each statistic as a dependency edge labelled $[0,w]$ keeps it acyclic. Temporal magic sets also extend to these predicates. A demand for a statistic on goal interval $[a,b]$ propagates as a demand on its inputs over $[a-w, b]$, which generalizes the past-operator guards of Goal-Driven Reasoning in DatalogMTL with Magic Sets. That paper explicitly lists temporal aggregation as unsupported.

The third is an empirical claim. Event-level accuracy of rules applied to forecasts is more sensitive to over-stationarization than the mean squared error (MSE) of the forecasts suggests, because alarms depend on threshold crossings and baseline-relative deviations. Those are exactly the signals that Kang et al. and Non-stationary Transformers show normalization destroys.

The closest existing work is the magic-sets paper. It rewrites DatalogMTL programs for goal-driven materialization but has no aggregates and never touches numeric data. On the forecasting side, de-stationarization methods such as Non-stationary Transformers and TimeBridge stop at MSE and have no symbolic layer. Temporal Query Network uses "query" only in the attention sense.

Research Program

The first component is the fact layer. Raw or forecast numeric streams are converted into interval facts of two kinds. Absolute-frame facts compare a value to a fixed physical constant. Relative-frame facts compare a value to a statistic predicate, for example "deviation greater than $k$ spreads above the conditioned baseline." Comparisons produce Boolean facts that coalesce into long intervals. This matters because MeTeoR's efficiency (Practical Reasoning in DatalogMTL) depends on merging adjacent intervals. Raw statistic values, which change at every timestamp, would defeat that merging. We therefore never materialize raw statistic values as facts. We materialize only the comparisons the rules ask for, and we determine those comparisons by a rewriting pass over the program.

The second component is the reasoning extension. We implement statistic predicates in MeTeoR's seminaïve loop (Seminaïve Materialisation in DatalogMTL) as a separate stage that runs after its conditioning predicates reach a fixpoint. We then prove the two results stated above. The acyclicity argument is straightforward but must handle a subtle case: a statistic whose conditioning state depends on an earlier statistic. This is allowed as long as the stages are layered and every stage has bounded windows.

The research file also flags a potential conflict. It suggests that non-stationary trends prevent the periodicity-based termination of Materialisation-Based Reasoning in DatalogMTL with Bounded Intervals. We think this is overstated for our setting. Those periodicity results concern program behaviour beyond the last data timestamp, and forecasts have a finite horizon, so the dataset is always finite. We will nonetheless check empirically whether time-to-saturation grows with drift. More distinct fact patterns could plausibly delay the point at which the engine detects periodicity.

The third component is the non-recursive SQL path. When a monitoring query has no recursion, statistic predicates map directly onto SQL window functions. This follows the window-function translations behind Computing Compact Answers to Temporal Path Queries Using SQL. It gives a relational reference implementation and a natural competitor.

The fourth component is predictive monitoring. Forecasters produce horizon-$H$ predictions, which are de-normalized and turned into future-stamped facts. The rule program is evaluated only over the forecast horizon, using magic sets. Alarms derived from forecasts are compared with alarms derived by the same rules from the realized future data. This gives non-circular ground truth: the rules are fixed specifications, and what is evaluated is the forecaster's ability to support them.

Baselines

The naive reference point is a standard forecaster with per-window normalization (RevIN-style) whose outputs are de-normalized and passed through absolute-threshold rules only. This is what a practitioner would build today. It is run with the same backbone, data splits and horizons as every other forecaster. Beating it means higher event-level F1 on relative-frame and mixed-frame alarms at equal or lower MSE.

The strongest forecasting competitors are Non-stationary Transformers and TimeBridge. Non-stationary Transformers re-injects the removed mean and variance into attention through learned factors, using the official code (thuml/nonstationary_transformers). It reports MSE reductions of 49.43% on vanilla Transformer, 47.34% on Informer and 46.89% on Reformer across its benchmark suite. TimeBridge normalizes locally but keeps raw trends for cross-series attention, and reports an MSE reduction of over 13% on the 862-channel Traffic dataset relative to the next-best model. These are the strongest competitors because they are the methods that address over-stationarization. Our empirical claim is that their advantage should grow when measured by alarms. They will be retrained under one tuning budget per dataset and horizon, and all of them feed the identical rule program. Here we are not trying to beat them. We are testing whether their MSE ranking predicts their alarm ranking.

The strongest reasoning competitor has two parts. The first is preprocessing: all statistics are computed in SQL or as a dataframe step and materialized as facts, after which unmodified MeTeoR runs with magic sets. The second is Ontop-style SQL translation of the non-recursive fragment, as surveyed in Reasoning Techniques in DatalogMTL. For engine efficiency, the published reference numbers are the magic-sets speedups in Goal-Driven Reasoning in DatalogMTL with Magic Sets: over 69,000 times on average on iTemporal, and at least 12 times on non-entailed LUBM$_t$ queries. These are speedups over naive materialization, not over a preprocessing pipeline. We found no reported result on Lacuna for aggregate-bearing DatalogMTL programs. Beating this baseline means matching its answers exactly on unconditioned statistics while being faster or more memory-efficient on conditioned statistics, which preprocessing cannot express without an extra reasoning round.

Three ablations isolate the key ingredients. The first varies the frame: absolute-only, relative-only, or both. The second removes conditioning, computing statistics over all time points instead of over derived states. The third removes magic-set propagation through statistics, keeping magic sets elsewhere.

Why not just…?

Why not just precompute rolling statistics in SQL and feed them to an existing reasoner? For statistics over raw inputs this works, and it gives exactly the same answers. We use it as the main reasoning baseline and do not claim to beat it on accuracy. The approach breaks when the statistic is conditioned on a derived state, such as a baseline computed only over time when recursive rules have established normal operation. That state is unknown until reasoning has run. Preprocessing then requires a reason–compute–reason loop over the whole timeline, which discards the goal-directed pruning that made magic sets fast. The experiment that settles this compares wall-clock time and fact counts on conditioned-statistic workloads as the history length grows. If the loop costs about the same, our engine contribution reduces to convenience, and we will say so.

Why not just de-normalize the forecasts and use fixed physical thresholds? De-normalized outputs are on the absolute scale, so physical-limit alarms are well posed. Many operator rules, however, are baseline-relative, and fixed thresholds misfire as baselines drift, as the drift results in Non-stationary Transformers imply for Exchange and ILI. This is the naive baseline above. If it matches the dual-frame rules on our relative-frame alarms, the fact-layer claim fails.

Why not just train a neural classifier to predict alarms end-to-end? Operators' rules are specifications, not labels. A classifier gives no guarantee that its alarms follow the stated temporal logic, and it must be retrained whenever a rule changes. This alternative is still a real threat on accuracy, so we train one on rule-generated labels from training data as an upper-bound comparator. If it dominates rules-over-forecasts, the right conclusion is that the symbolic layer should verify rather than predict.

Why not just reduce everything to automata or linear temporal logic? The file reports that discretizing to linear temporal logic blows up exponentially (Reasoning Techniques in DatalogMTL). It also reports that materialization alone answers 99.7% of practical queries (Practical Reasoning in DatalogMTL). We therefore do not pursue this route.

Proposed Experiments

We build monitoring rule suites with mixed absolute and relative-frame alarms on four datasets: ETT (oil temperature limits combined with load deviation from a conditioned baseline), Weather (where MeTeoR has already handled 397 million facts), Traffic occupancy, and ILI (epidemic onset relative to a seasonal baseline). Forecasters run at standard horizons. Metrics are MSE, event-level F1, and alarm onset delay.

The first decisive check is rank correlation between MSE improvement and F1 improvement across forecasters. The hypothesis predicts that de-stationarized forecasters gain proportionally more F1 on relative-frame alarms than on absolute ones. No event-level results exist for any forecaster in the file, so this is new measurement.

For the engine, we extend the iTemporal generator and LUBM$_t$ with conditioned-statistic rules. We report correctness against the preprocessing baseline, runtime, materialized fact counts, and time-to-saturation under synthetic drift of increasing strength. The second decisive check is whether magic-set propagation through statistics preserves the scaling behaviour that the magic-sets paper reports when moving from $10^3$ to $10^6$ facts. If conditioned statistics instead force full-history evaluation, the extension has failed at its main purpose.