Cyber Anomaly Detection & Service Dependency Risk

Markov transition matrices, PageRank, a shallow autoencoder, and Extreme Value Theory thresholds: a simulation study

Author

Patrick Lefler

Published

August 13, 2026

Introduction

Enterprise systems produce large volumes of authentication, network and host telemetry. Most monitoring still relies on fixed signatures and static thresholds, which miss attacks that stay inside normal ranges. Credential stuffing spread across many sources and slow data exfiltration are examples. An unsupervised detector learns what normal looks like and flags departures from it, so it can in principle catch attacks nobody has written a rule for.

Detection alone is not enough. The usual response to an alert is containment: isolate a host, revoke a token. If the affected service sits under much of the estate, the containment can cause a larger outage than the attack. This project therefore tests a two-layer design, built in R, on simulated enterprise telemetry. Together the layers answer two questions: is this window abnormal? and how dangerous is it to act on that automatically?

The structural layer models 23 services as a Markov transition matrix of call flows. It ranks them by PageRank, articulation points and a node-removal simulation, and turns the ranking into criticality tiers that decide which alerts may trigger automated containment.

The detection layer is a shallow autoencoder, written in base R with analytic gradients and Adam. It is trained on 19 correlated, seasonal telemetry features. Alerts fire when reconstruction loss exceeds a threshold fitted to the loss tail with a Generalized Pareto Distribution on held-out hosts.

Results. Across 30 independent seeds (mean [95% range]):

  • The autoencoder separates attacks from normal windows with ROC AUC 0.794 [0.734–0.824]. Mahalanobis distance does better (0.817 [0.765–0.843]), so the network adds nothing over simpler statistics on this data.
  • At the 99.9% threshold it catches 77.0% [63.8%–82.0%] of high-intensity attacks, 24.6% [19.1%–34.3%] of medium and 0.8% [0.2%–2.1%] of low.
  • It misses data exfiltration at every intensity.
  • False alarms at 99.9% were 14.1 [1.5–52.2] per 8,064 normal windows, against about 8 expected. The threshold does not transfer cleanly to new hosts.
  • The loss tail is heavy (shape ξ = 0.24 [0.10–0.38]), driven by rare benign count spikes.

The two-layer design is sound. The detector, as built, is not ready for automated response.

WarningRead this first

Every number on this site comes from a simulation with assumed parameters (params.yaml) and injected attacks, not production telemetry. The results show how the methods behave under controlled conditions. They do not estimate how the system would perform on any real network.

Techniques

Markov transition matrix. Services are nodes, and an edge \(i \to j\) means service \(i\) calls service \(j\). Normalizing call volumes by row gives \(P_{ij} = \Pr(\text{next call goes to } j \mid \text{at } i)\), a row-stochastic matrix. It assumes the next hop depends only on the current service (first-order Markov). Details →

PageRank. PageRank is the long-run share of request hops landing on each service, with random restarts weighted by a damping factor. It measures dependency concentration. It is not a single-point-of-failure detector, so it is cross-checked against articulation points and a node-removal simulation.

Shallow autoencoder. A 19-4-19 network with a \(\tanh\) bottleneck and a linear decoder, trained only on normal windows. Each window is scored by its mean squared reconstruction error \(\ell(\mathbf{x}) = \tfrac{1}{d}\lVert \mathbf{x} - \hat{\mathbf{x}} \rVert^2\). With one hidden layer it is close to principal component analysis, and the results confirm this. Details →

Extreme Value Theory (peaks over threshold). Losses above a high level are modelled with a Generalized Pareto Distribution. This gives quantile thresholds \(\tau_q\) for exceedance probabilities too small to estimate directly from the data. The thresholds come with bootstrap intervals, diagnostics and a calibration test. Details →

Architecture

Display code
%%{init: {'themeVariables': { 'fontSize': '15px', 'fontFamily': 'sans-serif' }}}%%
flowchart LR
    T["<b>Telemetry window</b><br>x ∈ ℝᵈ"] --> AE["<b>Shallow autoencoder</b><br>d → k → d"]
    AE --> L["<b>Loss</b><br>ℓ(x) = (1/d)‖x − x̂‖²"]
    L --> EVT["<b>EVT threshold</b><br>τ_q from held-out GPD fit"]
    EVT --> A{"<b>Alert?</b><br>ℓ(x) > τ_q"}
    G["<b>Service call graph</b>"] --> P["<b>Transition matrix P</b><br>PageRank, articulation,<br>removal impact"]
    P --> C["<b>Criticality tier</b>"]
    A --> R["<b>Containment routing</b>"]
    C --> R
    R --> H["Tier 1: human approval"]
    R --> S["Tier 2–3: low-blast-radius<br>automated actions"]

    classDef default fill:#f8f9fa,stroke:#0275d8,stroke-width:1.5px;
    classDef human fill:#fce4e4,stroke:#d9534f,stroke-width:1.5px;
    class H human;

%%{init: {'themeVariables': { 'fontSize': '15px', 'fontFamily': 'sans-serif' }}}%%
flowchart LR
    T["<b>Telemetry window</b><br>x ∈ ℝᵈ"] --> AE["<b>Shallow autoencoder</b><br>d → k → d"]
    AE --> L["<b>Loss</b><br>ℓ(x) = (1/d)‖x − x̂‖²"]
    L --> EVT["<b>EVT threshold</b><br>τ_q from held-out GPD fit"]
    EVT --> A{"<b>Alert?</b><br>ℓ(x) > τ_q"}
    G["<b>Service call graph</b>"] --> P["<b>Transition matrix P</b><br>PageRank, articulation,<br>removal impact"]
    P --> C["<b>Criticality tier</b>"]
    A --> R["<b>Containment routing</b>"]
    C --> R
    R --> H["Tier 1: human approval"]
    R --> S["Tier 2–3: low-blast-radius<br>automated actions"]

    classDef default fill:#f8f9fa,stroke:#0275d8,stroke-width:1.5px;
    classDef human fill:#fce4e4,stroke:#d9534f,stroke-width:1.5px;
    class H human;

Headline results

It collects the numbers a decision-maker needs on one screen, each averaged over 30 complete re-runs instead of one lucky draw.

Display code
pick <- tribble(
  ~group,                             ~metric,                        ~label,                                        ~fmt,
  "ROC AUC by method",                ae_label,                       "ROC AUC, autoencoder",                         "num",
  "ROC AUC by method",                "Mahalanobis distance",         "ROC AUC, Mahalanobis distance (baseline)",     "num",
  "ROC AUC by method",                "Sum of squared z-scores",      "ROC AUC, sum of squared z-scores (baseline)",  "num",
  "Detection at 99.9% by intensity",  "high",                         "Detection at 99.9%, high-intensity attacks",   "pct",
  "Detection at 99.9% by intensity",  "medium",                       "Detection at 99.9%, medium-intensity attacks", "pct",
  "Detection at 99.9% by intensity",  "low",                          "Detection at 99.9%, low-intensity attacks",    "pct",
  "Detection at 99.9% by attack",     "Data Exfiltration",            "Detection at 99.9%, data exfiltration",        "pct",
  "Model",                            "False alarms at 99.9%",        "False alarms at 99.9% (count)",                "int",
  "Model",                            "GPD shape xi",                 "Tail shape ξ",                                 "num",
  "Model",                            "tau 0.999",                    "Threshold τ₀.₉₉₉",                             "num"
)
pick |>
  left_join(rob, by = join_by(group, metric)) |>
  mutate(across(c(mean, lo, hi), \(x) case_when(fmt == "pct" ~ f_pct(x), fmt == "int" ~ f_num(x, 1), .default = f_num(x, 3)))) |>
  select(label, mean, lo, hi) |>
  gt() |>
  tab_header(title = sprintf("Headline Results across %d Seeds", n_seeds),
             subtitle = sprintf("False alarms out of %s normal test windows; about %.0f expected at 99.9%%",
                                f_int(n_normal_test), n_normal_test * 0.001)) |>
  cols_label(label = "Quantity", mean = "Mean", lo = "2.5%", hi = "97.5%") |>
  tab_options(table.font.size = 12)
Table 1
Headline Results across 30 Seeds
False alarms out of 8,064 normal test windows; about 8 expected at 99.9%
Quantity Mean 2.5% 97.5%
ROC AUC, autoencoder 0.794 0.734 0.824
ROC AUC, Mahalanobis distance (baseline) 0.817 0.765 0.843
ROC AUC, sum of squared z-scores (baseline) 0.798 0.749 0.824
Detection at 99.9%, high-intensity attacks 77.0% 63.8% 82.0%
Detection at 99.9%, medium-intensity attacks 24.6% 19.1% 34.3%
Detection at 99.9%, low-intensity attacks 0.8% 0.2% 2.1%
Detection at 99.9%, data exfiltration 0.9% 0.0% 3.9%
False alarms at 99.9% (count) 14.1 1.5 52.2
Tail shape ξ 0.237 0.097 0.379
Threshold τ₀.₉₉₉ 3.134 2.038 4.376

How to read the table. Each row is one result, averaged over 30 complete re-runs of the study, each with fresh simulated data, a newly trained model and a newly fitted threshold. ROC AUC runs from 0.5, no better than a coin toss, to 1, complete separation of attacks from normal activity. Detection rates are the share of attack windows that raised an alert. The 2.5% and 97.5% columns bracket the middle 95% of re-runs.

What the table tells you. The detector reliably catches loud attacks and misses quiet ones: 77.0% of high-intensity windows but 0.8% of low-intensity ones, and almost no data exfiltration. It does no better than Mahalanobis distance, a classical statistic that needs no training. False alarms average 14.1 against about 8 expected and vary several-fold between runs. The original AUC of 1.0 came from the simulation design, not the model.

Recommendations

We recommend three governance practices:

  1. Human-in-the-loop containment, routed by criticality. Alerts on Tier 1 services (Key Management, File Store, DNS Resolver, API Gateway, Notification Svc, Customer Service) require human approval before isolation or credential revocation, because isolating them is itself an outage. Automate only low-blast-radius actions, such as step-up authentication or ending a single session, and only after the detector has been validated on production telemetry. At realistic attack rates most alerts at the 99.9% threshold would be false alarms (see the base-rate table), so automated isolation today would mostly hit healthy hosts.

  2. Explain every alert, and test the explanations. Report the top three contributing features with each alert. Measure how often they point at the true cause, and compare them against plain z-scores, which did as well here. This aligns with the explainability and model-risk expectations in the NIST AI Risk Management Framework (voluntary) and OSFI Guideline E-23 (effective May 1, 2027 for federally regulated Canadian financial institutions). Neither one prescribes a specific detector.

  3. Monitor drift by effect size, not significance. Replace weekly per-feature KS tests with Wasserstein distance per feature (in standard-deviation units, with an effect-size trigger). Track the live alert rate against its expected \(1-q\), and refit and re-validate the threshold on a schedule. In the drift test, KS flagged harmless shifts every time, and PSI at standard cut-offs missed a material one.

Limitations

All telemetry, attacks and the service graph are simulated, so the results show how the method behaves on data like the simulation, not how it would perform in a real environment. The threshold is fitted once to a heavy, discrete tail, and the test set has about 28% attacks, far more than real environments, which is why the base-rate table matters more than the ROC curve. The Model limitations section lists each limitation, the real data that would replace each assumption, and how the results should and should not be used.

Reproducibility

Every result can be regenerated from params.yaml with one script, run_all.R, and package versions are pinned with renv. The Reproducibility page has step-by-step instructions, result fingerprints for checking a rerun, unit-test results, and the full software environment. The code is on GitHub.