A Topology Layer for Machine Learning

Rickard Brüel Gabrielsson, Bradley J. Nelson, Anjan Dwaraknath, Primoz Skraba

Abstract

Topology applied to real world data using persistent homology has started to find applications within machine learning, including deep learning. We present a differentiable topology layer that computes persistent homology and its gradient, allowing for the optimization of global structural properties like connectivity and holes.

Introduction

Standard deep learning architectures are exceptionally proficient at identifying local patterns, such as edges and textures in images. However, they often struggle to capture and respect global structural properties. A common failure mode in generative models, such as Generative Adversarial Networks (GANs), is the production of outputs that are locally correct but topologically flawed—for example, a handwritten digit that is split into disconnected components or a 3D object with missing structural supports.

This paper addresses this gap by introducing a differentiable topology layer. By leveraging Persistent Homology (PH), a tool from algebraic topology, the authors enable neural networks to "see" and optimize global features like connected components, loops, and voids. This turns topology from a static preprocessing step into a dynamic component of the training loop.

Methodology: Differentiable Persistent Homology

The core innovation of this work is a framework for computing the gradient of a loss function defined on a persistence diagram. The process involves several key steps:

  1. The Layer: The input (e.g., pixel intensities or point cloud distances) is used to compute a filtration, which is a sequence of nested shapes that grow as a threshold changes.
  2. Differentiation: The critical insight is that every topological feature in a persistence diagram—represented by its "birth" and "death" times—is uniquely associated with specific "cells" in the input data, such as a particular pixel or an edge between two points. By identifying these critical cells, the gradient of the topological loss can be backpropagated directly to the input values.
  3. Filtration Types: The layer supports level-set (lower-star) filtrations for grid-based data like images and voxel volumes, as well as edge-based (Rips/Alpha) filtrations for point clouds.
Figure 6: A point cloud structured to emphasize its underlying topological branching, demonstrating the layer's ability to guide global organization.

This implementation is integrated into PyTorch, allowing it to function as a standard layer that can be combined with convolutional or linear components.

Experimental Evaluation

The authors evaluated the topology layer across several challenging domains, focusing on its ability to enforce structural priors.

3D Voxel Connectivity

In the generation of 3D voxel shapes, such as chairs, standard models often produce "floating" voxels or disconnected parts. By applying a topological loss that penalizes having more than one connected component, the model was forced to ensure all generated voxels formed a single, coherent structure.

Figure 1: Comparison of 3D point cloud generation: (a) original data, (b) skeletonized representation via the topological layer, and (c) a noisy baseline without topological constraints.

Generative Improvements on MNIST

On the MNIST dataset, the "Topology-Generator" outperformed baseline GANs. It achieved a higher Inception Score (5.1 vs 4.6) and a lower Wasserstein distance on persistence diagrams (1.52 vs 1.56), indicating that the generated digits were more structurally similar to real ones. Furthermore, the topological prior improved latent space interpolation, leading to smoother deformations rather than abrupt structural breaks.

Discussion and Insights

Beyond generative modeling, the topology layer offers new avenues for regularization and robustness:

  • Topological Regularization: Similar to how L1 regularization promotes sparsity, a topological penalty can promote "simplicity" in model weights or outputs, such as reducing the number of local maxima in a regression curve.
  • Adversarial Robustness: The authors demonstrated that "TopModels"—models trained with topological features—are significantly more robust to certain adversarial attacks. While standard models had a 100% failure rate against specific retargeting attacks, TopModels maintained a much higher degree of accuracy, with only a 25.2% success rate for the attacker.

Conclusion

While the computation of persistent homology introduces additional complexity compared to standard layers, the ability to optimize global structure provides a significant advantage for tasks where connectivity and topology are paramount. Future work may explore higher-dimensional homology or the application of these layers to intermediate neural activations to better understand how high-level concepts are formed within deep networks.

Summary updated

BibTeX
@inproceedings{gabrielsson2020topology,
  author = {Rickard Brüel Gabrielsson and Bradley J. Nelson and Anjan Dwaraknath and Primoz Skraba},
  title = {{A Topology Layer for Machine Learning}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2020},
  url = {https://openreview.net/forum?id=6ZG_d06EC5},
}
Figure