Run Kumo Anomaly
Kumo Anomaly is part of the Kumo-TS library, not SDM. Install the Kumo-Anomaly package (Python 3.12 or later) before running the example.
Use perform_anomaly_analysis_with_diffusion to score every time step of a series and flag anomalous steps.
For what the model is and how it works, see Kumo Anomaly.
Example
Run this script with uv run from the Kumo-TS/Kumo-Anomaly directory.
The first run downloads the weights into the working directory.
The input holds numeric columns only, and the script injects an anomaly into pressure at steps 300 to 309.
The main guard runs the model when you execute the script directly.
All ten injected steps (300 to 309) are flagged, and nine of the ten highest scores fall on them.
Read the Output
Explain an Anomaly
Pass sdk_config=ADDiffusionConfig(report_path="report.pdf", timestamp_column="timestamp", ground_truth_column="GT") to write a PDF of signals, flags, and scores.
Timestamp and label columns named there are kept in the output but excluded from the model’s features.
Add explain=True to rank the features of each flagged step by reconstruction error.
TopContributors lists the features with the largest errors (up to explanation_top_k, default 3), and ContributionShares gives each one’s share of the step’s total error.
The ranking describes where the model’s reconstruction failed, not what caused the anomaly.
This code continues the Example above with the same df.
In this two-sensor example, pressure has the largest share of reconstruction error at every flagged step. With other inputs, the top contributor can differ from the sensor containing the fault, including a correlated sensor. For more information, see Explainability and reporting.
Tune Compute and Reproducibility
nsample(default 15) sets the diffusion samples per window. Lower runs faster with noisier scores.- Diffusion sampling uses the SDK’s default seed (42) on every call.
sdk.inference_ad.set_seed(...)seeds only the global Python, NumPy, and PyTorch random number generators in your own process.
Inputs and Limits
- Numeric columns only. Other columns raise
The following columns contain non-numeric values: [...]; drop them or declare them inADDiffusionConfig. - At least as many rows as the model’s PCA dimension.
- Weight files go to
model_pathandmodel_config_path, which default to the working directory.
Fine-Tuning
Fine-tune on normal windows from your own CSV with examples/finetune_example.py.