KNN-MMD: Cross Domain Wireless Sensing via Local Distribution Alignment

Zijian Zhao, Zhijie Cai, Tingwei Chen, Xiaoyang Li, Hang Li, Qimei Chen, Guangxu Zhu

TL;DR

KNN-MMD is a novel few-shot learning framework that tackles the challenge of cross-domain Wi-Fi sensing by aligning data distributions locally within individual categories rather than globally. By combining K-Nearest Neighbors (KNN) pseudo-labeling with Maximum Mean Discrepancy (MMD) and introducing an adaptive early stopping strategy, it delivers highly accurate and stable performance across different environments and users.

What Problem Does This Paper Address?

Wi-Fi sensing utilizes Channel State Information (CSI) from commercial network interface cards to recognize human actions, identify individuals, and detect falls without requiring cameras or wearable devices. However, CSI is notoriously sensitive to environmental changes. A model trained to recognize gestures in one room or for one specific person often fails completely when deployed in a new room or with a new user—a challenge known as domain shift.

To fix this, researchers typically use Domain Alignment Learning (DAL) to map the source (training) and target (testing) domains into a shared feature space. The flaw in traditional DAL is that it focuses on global alignment. As illustrated in the paper, globally aligning two domains can inadvertently cause different categories to overlap, destroying the classification boundaries. Furthermore, few-shot learning methods in this space suffer from extreme training instability, with accuracy fluctuating wildly between epochs. Because target domain data is unlabeled, standard early stopping techniques cannot be used to find the optimal training endpoint.

Global vs. Local Alignment Concept

Methods

The authors propose KNN-MMD, a few-shot cross-domain framework consisting of three main phases:

  1. Preliminary Classification & Help Set Construction: The target domain data is flattened and reduced to a lower dimension using Uniform Manifold Approximation and Projection (UMAP). A simple KNN algorithm then classifies the target data based on a tiny, labeled target "support set" (e.g., 1 sample per class in a 1-shot scenario). The samples with the highest classification confidence are selected to form a high-fidelity "help set" with pseudo-labels.
  2. Network Training with Local Alignment: A ResNet18 feature extractor and a multilayer perceptron (MLP) predictor are trained using a joint loss function. This loss combines standard cross-entropy on the source domain, a local MMD loss (which aligns the source and target domains within each specific category using the help set), and a global MMD loss to mitigate any random bias from class imbalances in the help set.
  3. Adaptive Early Stopping: Crucially, the target domain's support set is entirely excluded from the training loss calculation. Instead, it is repurposed as a validation set. The framework monitors validation loss and accuracy to trigger an early stop at the optimal training epoch, preventing the performance drops common in unstable few-shot models.

Datasets

The framework was validated across three distinct datasets:

  • WiGesture: A public dataset containing CSI data from 8 individuals performing 6 distinct gestures. It was used to evaluate cross-person gesture recognition and cross-action person identification.
  • WiFall: A new dataset introduced by the authors, featuring 10 volunteers performing 5 activities (walking, jumping, sitting, standing up, and falling—including various fall types like forward, backward, and seated falls).
  • WiDar3.0: A large-scale public dataset used for expanded cross-people and cross-room gesture recognition experiments.

Key Insights and Ideas

  • Local Alignment is Essential: Global domain alignment often mixes up class distributions across domains. Aligning sub-domains (categories) independently preserves the decision boundaries learned from the source domain.
  • KNN is a Robust Pseudo-Labeler: While deep neural networks trained on a source domain generalize poorly to a raw target domain, a simple distance-based KNN operating on UMAP-reduced features provides remarkably reliable pseudo-labels for top-confidence target samples.
  • Unlocking Early Stopping for Few-Shot Learning: By resisting the temptation to use the target support set for training, the authors turned it into a vital validation tool. This solves the notorious "when to stop training" dilemma inherent to cross-domain few-shot learning.
Fig. 2. UMAP Dimensionality Reduction of the WiGesture Dataset [4]: In the figure, different shapes represent different person IDs, while different colors represent different action IDs. The x and y axes correspond to the two main UMAP components.

Key Results

In a challenging one-shot scenario (only 1 labeled sample per category in the target domain), KNN-MMD achieved outstanding accuracy across four core tasks, significantly outperforming state-of-the-art methods like CrossFi and AutoFi:

  • Gesture Recognition: 93.26%
  • Person Identification: 81.84%
  • Fall Detection: 77.62%
  • Action Recognition: 75.30%

The framework also demonstrated exceptional stability. While competing models showed sharp, erratic performance spikes during training, KNN-MMD's testing accuracy increased smoothly and converged reliably thanks to the adaptive early stopping mechanism.

Limitations and Future Work

Currently, the KNN-MMD framework is designed strictly for classification tasks. The authors note that extending this local distribution alignment approach to regression tasks (such as tracking or continuous parameter estimation) remains an open area for exploration. Additionally, future work could investigate pairing zero-shot learning methods with this DAL framework to eliminate the need for a target support set altogether.

Summary updated

Abstract

Wireless sensing has recently found widespread applications in diverse environments, including homes, offices, and public spaces. By analyzing patterns in channel state information (CSI), it is possible to infer human actions for tasks such as person identification, gesture recognition, and fall detection. However, CSI is highly sensitive to environmental changes, where even minor alterations can significantly distort the CSI patterns. This sensitivity often leads to performance degradation or outright failure when applying wireless sensing models trained in one environment to another. To address this challenge, Domain Alignment (DAL) has been widely adopted for cross-domain classification tasks, as it focuses on aligning the global distributions of the source and target domains in feature space. Despite its popularity, DAL often neglects inter-category relationships, which can lead to misalignment between categories across domains, even when global alignment is achieved. To overcome these limitations, we propose K-Nearest Neighbors Maximum Mean Discrepancy (KNN-MMD), a novel few-shot method for cross-domain wireless sensing. Our approach begins by constructing a help set using KNN from the target domain, enabling local alignment between the source and target domains within each category using MMD. Additionally, we address a key instability issue commonly observed in cross-domain methods, where model performance fluctuates sharply between epochs. Further, most existing methods struggle to determine an optimal stopping point during training due to the absence of labeled data from the target domain. Our method resolves this by excluding the support set from the target domain during training and employing it as a validation set to determine the stopping criterion. The dataset and code are publicly available at https://github.com/RS2002/KNN-MMD .
BibTeX
@article{zhao2025knn,
  author = {Zijian Zhao and Zhijie Cai and Tingwei Chen and Xiaoyang Li and Hang Li and Qimei Chen and Guangxu Zhu},
  title = {{KNN-MMD: Cross Domain Wireless Sensing via Local Distribution Alignment}},
  journal = {IEEE Transactions on Mobile Computing},
  year = {2025},
  url = {https://openreview.net/forum?id=qxLbiSemR3},
}
Figure