k* Distribution: Evaluating the Latent Space of Deep Neural Networks using Local Neighborhood Analysis

Shashank Kotyan, Tatsuya Ueda, Danilo Vasconcellos Vargas · DOI

Introduction

Deep neural networks (DNNs) are often criticized as "black boxes" because their internal decision-making processes are difficult to interpret. Central to their function is the "latent space"—a high-dimensional representation where the network groups similar inputs. While tools like t-SNE and UMAP are commonly used to visualize these spaces, they often introduce distortions and are highly sensitive to hyperparameters. This paper introduces the $k^*$ distribution, a mathematically rigorous, dimension-independent metric that provides a clearer "texture" of the latent space by analyzing local neighborhoods.

Methodology: The k* Metric

The core innovation is the $k^*$ value. For any given sample in the latent space, $k^*$ is defined as the index of the nearest neighbor belonging to a different class. A high $k^*$ indicates a sample is deep within a "pure" cluster of its own class, while a low $k^*$ suggests it is near a decision boundary or surrounded by noise.

Overview of the k* distribution computation pipeline across different data modalities.

By aggregating these values for an entire class, researchers can visualize the distribution using violin plots. This process is applicable to any data modality—images, text, or audio—as long as it can be processed by a neural network to produce feature vectors.

Interpreting Latent Space Patterns

The authors identify three primary patterns in the $k^*$ distribution that correspond to specific geometric organizations in the latent space:

  1. Pattern A (Fractured): Characterized by a positively skewed distribution (skew > 0.5). This indicates the class is broken into many small, isolated islands, often seen in models struggling with generalization.
  2. Pattern B (Overlapped): A nearly uniform distribution (-0.5 < skew < 0.5). Here, the class is heavily entangled with others, representing a state of confusion for the model.
  3. Pattern C (Clustered): The "gold standard," featuring a negatively skewed distribution (skew < -0.5). This represents a dense, cohesive cluster where most samples are surrounded by their own kind.
The three characteristic patterns of k* distributions: Fractured (A), Overlapped (B), and Clustered (C).

Key Insights and Comparative Analysis

The $k^*$ distribution reveals several critical properties of modern DNNs that traditional metrics miss:

  • Architectural Differences: Vision Transformers (ViTs) demonstrate significantly better latent space organization than ResNets. On ImageNet-1k, ViTs produced nearly 30 times more "Clustered" classes than ResNet-50, despite having similar top-1 accuracy.
  • The Robustness Trade-off: Adversarially trained models, while more robust to attacks, exhibit more "Fractured" latent spaces. This suggests that robustness is achieved by creating complex, fragmented boundaries rather than clean, cohesive clusters.
  • Layer-by-Layer Evolution: Interestingly, latent spaces often become more fractured in deeper layers. The final classification layer is frequently more fragmented than preceding pooling layers, indicating the network "shatters" representations to make final categorical decisions.
  • Sensitivity to Noise: Data augmentations like cropping or Gaussian noise significantly fracture the latent space, revealing a "brittleness" in internal representations that output accuracy alone does not capture.

Conclusion

The $k^*$ distribution offers a robust, cross-domain tool for peering into the hidden layers of neural networks. Unlike visualization-only techniques, it provides quantitative skewness metrics that correlate with model performance and architectural quality. Future work suggests integrating $k^*$ directly into the training process as a loss function to encourage the formation of well-clustered, interpretable latent spaces.

Summary updated

BibTeX
@article{kotyan2025k,
  author = {Shashank Kotyan and Tatsuya Ueda and Danilo Vasconcellos Vargas},
  title = {{k* Distribution: Evaluating the Latent Space of Deep Neural Networks using Local Neighborhood Analysis}},
  journal = {IEEE TNNLS},
  year = {2025},
  doi = {10.1109/tnnls.2024.3446509},
}
Figure