An Anomaly Node Detection Method for Wireless Sensor Networks Based on Deep Metric Learning with Fusion of Spatial–Temporal Features

Ziheng Wang, Miao Ye, Cheng Jin, Cheng Zhu, Yong WangSensors 2025 · DOI

TL;DR

This paper introduces a novel anomaly detection method for Wireless Sensor Networks (WSNs) that fuses deep learning with metric learning to better capture complex spatial and temporal correlations in multi-node, multi-modal data. By employing a Graph Attention Network (GAT) and Transformer for feature extraction and a specialized distance metric module with triplet loss, the method achieves a significant 7% improvement in F1 score on public datasets, particularly excelling in small-sample scenarios.

What Problem Does This Paper Address?

Wireless Sensor Networks (WSNs) are crucial for tasks like environmental monitoring and surveillance, but their distributed nature and inherent limitations (low power, limited memory) lead to data anomalies. Existing anomaly detection methods often struggle to fully grasp the intricate correlations present in multi-node, multi-modal time-series data. This is exacerbated by the challenge of effectively mapping features to classes, especially when dealing with limited training samples. The paper aims to bridge this gap by developing a more robust anomaly detection framework that can accurately identify abnormal nodes in WSNs, even with scarce data.

Methods

The proposed approach, named ST-DMLAD (Spatio-Temporal Deep Metric Learning Anomaly Detection), is built around three core modules:

  1. Feature Extraction Module: This module combines a Graph Attention Network (GAT) for capturing spatial relationships between sensor nodes and a Transformer encoder for extracting temporal features from the time-series data. The GAT leverages attention mechanisms to weigh the importance of neighboring nodes, while the Transformer uses its self-attention mechanism to model long-range temporal dependencies. These spatial and temporal features are then fused.
  2. Distance Metric Module: This module is the heart of the metric learning aspect. It uses a triplet loss function to learn discriminative similarity. Unlike methods that only compare positive and negative pairs, this module explicitly considers both intra-class similarity (ensuring samples of the same class are close) and inter-class similarity (ensuring samples of different classes are far apart). This is achieved by training on anchor, positive, and negative sample triplets.
  3. Classification Module: A multi-layer fully connected layer maps the learned feature representations to a classification probability, determining whether a node is normal or abnormal.

The paper also details specific implementations for spatial feature extraction using GAT and temporal feature extraction using Transformer encoder layers, along with the mathematical formulations for attention coefficients and feature transformations.

Datasets

The experiments were conducted on a publicly available dataset from the Intel Berkeley Research Lab. This dataset comprises humidity, temperature, light, and voltage values collected by 54 sensors over a period, with readings taken every 31 seconds. The paper also describes a manual injection of various anomaly types (point, context, collective, spatial correlation, and temporal correlation anomalies) into this dataset to create diverse scenarios for testing.

Key Insights and Ideas

  • Fusion is Key: Combining spatial (GAT) and temporal (Transformer) feature extraction is crucial for capturing the complex dynamics of WSN data, which traditional methods often miss.
  • Metric Learning for Small Samples: Metric learning, particularly with triplet loss, is highly effective for anomaly detection in scenarios with limited training data, as it focuses on learning discriminative distance metrics rather than direct class mapping.
  • Beyond Binary Similarity: Explicitly modeling both intra-class and inter-class similarity relationships provides a more nuanced understanding of data patterns, leading to better anomaly detection.
  • Attention for Relevance: The use of attention mechanisms in both GAT and Transformer allows the model to dynamically focus on the most relevant spatial neighbors and temporal dependencies, improving feature representation.

Key Results

The proposed ST-DMLAD method achieved a F1 score of 0.89, outperforming existing approaches by 7%. Ablation studies demonstrated the effectiveness of the proposed distance measurement module, showing significant improvements in F1 score compared to a similarity score calculation module. Comparative experiments also highlighted the superiority of ST-DMLAD over methods like CNN-LSTM, GCN-LSTM, GAT-GRU, and GAT-Transformer, with ST-DMLAD showing a notable increase in recall and F1 scores.

Limitations and Future Work

The authors acknowledge that while their approach improves upon existing methods, there are still areas for future exploration:

  • Dynamic Graphs: Real-world scenarios often involve dynamic graphs, which present challenges due to their large data volume, complexity, noise, and sparsity. Future work could explore anomaly detection in these dynamic graph settings.
  • Frequency Domain Analysis: Analyzing time-series data from the frequency domain perspective could offer complementary insights. Developing data augmentation techniques and generative models, potentially leveraging large AI models, is also suggested.
  • Sparse Data: Handling sparse data, which is common in many applications, remains a challenge. Research into clustering and dimensionality reduction for sparse data is identified as a promising direction.
  • Computational Complexity: While the proposed method aims to optimize training cost, further research into more efficient computational approaches for large-scale WSN data is warranted.

Summary updated

Abstract

Wireless sensor networks (WSNs) use distributed nodes for tasks such as environmental monitoring and surveillance. The existing anomaly detection methods fail to fully capture correlations in multi-node, multi-modal time series data, limiting their effectiveness. Additionally, they struggle with small sample scenarios because they do not effectively map features to classes. To address these challenges, this paper presents an anomaly detection approach that integrates deep learning with metric learning. A framework incorporating a graph attention network (GAT) and a Transformer is developed to capture spatial and temporal features. A novel distance measurement module improves similarity learning by considering both intra-class and inter-class relationships. Joint metric-classification training improves model accuracy and generalization. Experiments conducted on public datasets demonstrate that the proposed approach achieves an F1 score of 0.89, outperforming the existing approaches by 7%.
BibTeX
@inproceedings{wang2025anomaly,
  author = {Ziheng Wang and Miao Ye and Cheng Jin and Cheng Zhu and Yong Wang},
  title = {{An Anomaly Node Detection Method for Wireless Sensor Networks Based on Deep Metric Learning with Fusion of Spatial–Temporal Features}},
  booktitle = {Sensors},
  year = {2025},
  doi = {10.3390/s25103033},
}
Figure