Two-sample Testing Using Deep Learning

Matthias Kirchler, Shahryar Khorasani, Marius Kloft, Christoph Lippert

Introduction

Determining whether two sets of data originate from the same distribution is a fundamental task in statistics, known as the two-sample test. This problem is central to various fields, including clinical trials (comparing treatment vs. placebo) and detecting covariate shift in machine learning models. Traditional non-parametric approaches, such as the Maximum Mean Discrepancy (MMD), utilize fixed kernels to compare distributions. While theoretically sound, these methods often struggle with high-dimensional, complex data like images or audio. Conversely, Classifier Two-Sample Tests (C2ST) leverage neural networks but typically require splitting the dataset—using one half for training and the other for testing—which significantly diminishes statistical power when data is limited.

This paper introduces a novel framework for "Deep Two-Sample Testing" that utilizes the feature-learning capabilities of Deep Neural Networks (DNNs). By mapping data into the hidden layers of a trained network and applying new linear-time test statistics, the proposed methods achieve substantially higher statistical power, reducing Type-2 error rates by up to 35 percentage points compared to traditional benchmarks.

Methodology

The proposed approach shifts the testing domain from the raw input space to a learned representation space. Instead of using a fixed kernel or training a classifier from scratch on a split dataset, the authors use a DNN to learn a descriptive representation of the data.

Feature Mapping and Representation

Data is passed through a DNN, which can be either pre-trained on a related task (transfer learning) or trained on a subset of the available data. The statistical test is then performed on the activations of the network's last hidden layer. This allows the test to benefit from descriptive features that are more informative than those provided by standard fixed kernels.

New Test Statistics

Two new linear-time test statistics are introduced to evaluate these representations:

  1. Deep Maximum Mean Discrepancy (DMMD): This measures the squared distance between the means of the two populations within the feature space.
  2. Deep Fisher Discriminant Analysis (DFDA): A normalized variant of DMMD that accounts for the covariance (the "shape") of the data clusters. This normalization makes the test more robust by effectively "whitening" the features before comparison.

Unlike standard MMD, which typically scales quadratically ($O(n^2)$) with the number of samples, these statistics are computed in linear time ($O(n)$), facilitating application to large-scale datasets without sacrificing sensitivity.

Type-1 error rates for the proposed methods remain stable around the significance level (0.05) across various sample sizes, ensuring statistical validity.

Experimental Evaluation

The researchers evaluated the performance of Deep Two-Sample Testing across several challenging domains:

  • Audio Data: Distinguishing modulated song snippets.
  • Visual Classification: Differentiating between visually similar aircraft models (e.g., Boeing 737 vs. 747) and dog breeds using a ResNet-152 backbone.
  • Neuroimaging: Analyzing 3D MRI scans from the ADNI dataset to detect differences between healthy controls and patients with Alzheimer’s Disease or Mild Cognitive Impairment (MCI).

Results

The experimental results highlight several key advantages of the deep testing framework.

Statistical Power and Sample Efficiency

The proposed methods, particularly DFDA, demonstrated massive power gains. In image and audio tasks, the Type-2 error rate (the failure to detect a real difference) was reduced by up to 35 percentage points compared to state-of-the-art kernel methods. Notably, the deep tests maintained high sensitivity even with small sample sizes (e.g., $m=20$), where traditional methods were essentially guessing.

Type-2 error rates across different datasets show that the proposed deep testing methods (DFDA and DMMD) significantly outperform traditional kernel-based and classifier-based baselines as sample size increases.

The Role of Transfer Learning and Normalization

A significant finding is that transfer learning acts as a powerful tool for statistics; features from a model trained on ImageNet were sufficient to distinguish specific breeds or aircraft more effectively than hand-crafted kernels. Furthermore, DFDA generally outperformed DMMD by considering internal feature variance, proving the value of normalization in high-dimensional feature spaces. On the ADNI neuroimaging dataset, the DFDA test successfully identified statistically significant differences between Alzheimer's patients and healthy controls ($p < 10^{-4}$) and even detected subtle structural brain changes associated with genetic risk factors.

Discussion and Conclusion

While Deep Two-Sample Testing offers significant improvements, its performance is inherently tied to the quality of the learned features. If a pre-trained model is entirely unrelated to the target data, the test's power may diminish. Additionally, while the test identifies that distributions differ, it does not inherently explain why. Future research could integrate explainable AI (XAI) to improve interpretability.

In conclusion, by combining deep learning representations with efficient linear-time statistics, this work provides a robust and powerful framework for modern two-sample testing, particularly for complex, high-dimensional data.

Summary updated

BibTeX
@inproceedings{kirchler2020two,
  author = {Matthias Kirchler and Shahryar Khorasani and Marius Kloft and Christoph Lippert},
  title = {{Two-sample Testing Using Deep Learning}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2020},
}
Figure