Skip to main content

CMAD: A Lightweight Framework for Extreme Spatio-Temporal Anomaly Detection

Project description

Convolution Matrix Anomaly Detection (CMAD)

CMAD is a lightweight, unsupervised framework for detecting clusters of negative spatio-temporal anomalies in sequential 2D data. It is designed for applications such as ice melt detection, environmental degradation, loss analysis, and decline-focused change detection.

CMAD operates on consecutive time steps, requires no labels, and adapts automatically to arbitrary spatial resolutions.


⚠️ Important Version Note

This version of CMAD detects clusters of negative anomalies only.

An anomalous event is identified when a spatially contiguous cluster of locations exhibits an extreme negative change between consecutive time steps that exceeds the normal (e.g., loss, decrease, melting, erosion).

Positive changes are intentionally ignored in this release.


Key Features

  • ✔ Unsupervised (no training labels required)
  • ✔ Works with images or generic 2D time-series arrays
  • ✔ Supports arbitrary spatial dimensions (no fixed size)
  • ✔ Adaptive IQR-based thresholding
  • ✔ Binary anomaly masks (1 = anomaly, 0 = normal)
  • ✔ CPU-only by default (GPU-ready via PyTorch)
  • ✔ Suitable for large spatio-temporal datasets

Method Overview

Given a time series of 2D data
[ X = {X_1, X_2, \dots, X_T}, \quad X_t \in \mathbb{R}^{H \times W} ]

CMAD performs:

  1. Temporal differencing [ D_t = X_{t+1} - X_t ]

  2. 2×2 convolution with stride-2 downsampling

    • Captures localized spatial changes while reducing resolution
  3. Second-stage 2×2 pooling

    • Aggregates local neighborhoods to emphasize spatially coherent patterns
  4. Adaptive IQR-based thresholding

    • Per-cell thresholds learned from training data
  5. Back-projection

    • Detected anomalous regions are mapped back to the original spatial resolution using back projection strategy
  6. Negative-only cluster filtering

    • A region is marked anomalous only if:
      • It exceeds the adaptive threshold and
      • The temporal difference is negative
      • The signal forms a spatially contiguous cluster

Demo Code

from cmad import CMAD
import numpy as np

X_train = np.random.randn(30, 64, 64)
X_test  = np.random.randn(10, 64, 64)


#Demo Code for CPU
cmad = CMAD(device="cpu")
cmad.fit_from_array(X_train)

anomaly_masks = cmad.predict_from_array(X_test)
print(anomaly_masks.shape)  # (T-1, H, W)


## Demo Code for GPU (cuda)
cmad = CMAD(device="cuda")
cmad.fit_from_array(X_train)
anomaly_masks = cmad.predict_from_array(X_test)

## Demo Code for Apple Silicon (MPS)
cmad = CMAD(device="mps")
cmad.fit_from_array(X_train)
anomaly_masks = cmad.predict_from_array(X_test)

Synthetic Demo Example

import numpy as np
import matplotlib.pyplot as plt
from cmad import CMAD

T, H, W = 20, 50, 50
X = np.random.randn(T, H, W)

# Inject negative anomaly
X[10:, 20:25, 20:25] -= 5

X_train = X[:15]
X_test = X[15:]

cmad = CMAD(device="cpu")
cmad.fit_from_array(X_train)

anomaly_masks = cmad.predict_from_array(X_test)

accumulated = anomaly_masks.sum(axis=0)
plt.imshow(accumulated, cmap="hot")
plt.colorbar()
plt.title("Accumulated Negative Anomalies")
plt.show()

Installation

pip install cmad

Citation

If you use CMAD in your research, please cite the following paper:

@inproceedings{devnath2024cmad,
  author    = {Maloy Kumar Devnath and Sudip Chakraborty and Vandana P. Janeja},
  title     = {CMAD: Advancing Understanding of Geospatial Clusters of Anomalous Melt Events in Sea Ice Extent},
  booktitle = {Proceedings of the 32nd ACM SIGSPATIAL Conference},
  year      = {2024},
  publisher = {ACM},
  doi       = {10.1145/3678717.3691280}
}

Full Reference

Maloy Kumar Devnath, Sudip Chakraborty, and Vandana P. Janeja. 2024.
CMAD: Advancing Understanding of Geospatial Clusters of Anomalous Melt Events in Sea Ice Extent.
Proceedings of the 32nd ACM International Conference on Advances in Geographic Information Systems (SIGSPATIAL ’24).
ACM. https://doi.org/10.1145/3678717.3691280

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmad-0.1.0.post6.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmad-0.1.0.post6-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file cmad-0.1.0.post6.tar.gz.

File metadata

  • Download URL: cmad-0.1.0.post6.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.17

File hashes

Hashes for cmad-0.1.0.post6.tar.gz
Algorithm Hash digest
SHA256 6c7163f923fdcb54fd8eaf6bb30b50102a933b95a2160a0e608d53fbc4c1f80d
MD5 fcefc42a5a2e16ae54e5cfc62c7ff6fd
BLAKE2b-256 1a1c50814efcfae75e0e20e5e47d1fdea6a6d2bee39e172f0f7aae2ba27ff895

See more details on using hashes here.

File details

Details for the file cmad-0.1.0.post6-py3-none-any.whl.

File metadata

  • Download URL: cmad-0.1.0.post6-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.17

File hashes

Hashes for cmad-0.1.0.post6-py3-none-any.whl
Algorithm Hash digest
SHA256 1f08f7073f2decd88fbe28ca6b96405d8e3c3971c09de583f5a96ce64d125c98
MD5 f12ae2680844e349e98808f64f42a0ea
BLAKE2b-256 f5649d76294d9ff7da61b3385b6e09c041f8288951b066c2ad68e8ac4f37a449

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page