Abstract
The phenomenon of distribution shift (DS) occurs when a dataset at test time differs from the dataset at training time, which can significantly impair the performance of a machine learning model in practical settings due to a lack of knowledge about the data's distribution at test time. To address this problem, we postulate that real-world distributions are composed of latent Invariant Elementary Distributions (I.E.D) across different domains. This assumption implies an invariant structure in the solution space that enables knowledge transfer to unseen domains. To exploit this property for domain generalization, we introduce a modular neural network layer consisting of Gated Domain Units (GDUs) that learn a representation for each latent elementary distribution. During inference, a weighted ensemble of learning machines can be created by comparing new observations with the representations of each elementary distribution. Our flexible framework also accommodates scenarios where explicit domain information is not present. Extensive experiments on image, text, and graph data show consistent performance improvement on out-of-training target domains. These findings support the practicality of the I.E.D assumption and the effectiveness of GDUs for domain generalisation.
Introduction
Standard machine learning models typically rely on the Independent and Identically Distributed (I.I.D.) assumption, where training and test data are expected to originate from the same distribution. However, real-world applications frequently encounter distribution shift. For instance, a diagnostic model trained on medical imaging from one hospital may see its performance degrade when deployed at a different facility due to variations in equipment, lighting, or demographics.
Domain Generalization (DG) seeks to address this by training models on multiple source domains to ensure robustness on unseen target domains. Traditional DG methods often rely on explicit, and sometimes noisy, domain labels. We propose a shift in perspective: viewing domains not as monolithic entities, but as mixtures of universal, latent building blocks.
The Invariant Elementary Distribution (I.E.D.) Assumption
We introduce the Invariant Elementary Distribution (I.E.D.) assumption. We postulate that any observed domain is a mixture of latent, universal "elementary distributions" shared across environments. By identifying these invariant components, a model can generalize to a new domain by treating it as a novel combination of familiar building blocks.
Methodology: Gated Domain Units
To operationalize the I.E.D. assumption, we developed the Gated Domain Unit (GDU) layer. This modular component can be integrated into standard architectures like ResNet, DistilBERT, or Graph Isomorphism Networks (GIN).
1. Latent Representation and Gating
The GDU layer learns $M$ "elementary domain bases" using Kernel Mean Embeddings (KME). KME allows the model to represent complex probability distributions as single points in a Reproducing Kernel Hilbert Space (RKHS). When the model encounters a new data point $x_i$, the GDU calculates its similarity to each of the $M$ learned bases using metrics such as Cosine Similarity or Maximum Mean Discrepancy (MMD).
2. Weighted Ensemble Mechanism
As illustrated in the architecture below, each GDU is associated with a specific "learning machine" (a sub-network $f(x_i; \theta_j)$). The final output is a weighted sum of these sub-networks, where the weights $\beta_{ij}$ are dynamically determined by the similarity between the input and the elementary distributions.
To ensure the model learns diverse representations, we employ regularization techniques that encourage the elementary bases to remain distinct and orthogonal during the training process.
Experimental Results
We evaluated the GDU framework across a wide array of benchmarks, including digits classification and the rigorous WILDS benchmark, which covers medical imaging (Camelyon17), satellite data (FMoW), and molecular graphs (OGB-MolPCBA).
- Performance Gains: On the MNIST-M task, which features digits against shifting colorful backgrounds, GDUs improved accuracy from 63.0% (standard ERM) to 69.4%.
- State-of-the-Art Comparison: GDUs consistently outperformed standard Empirical Risk Minimization (ERM) and remained competitive with specialized algorithms like CORAL or IRM, even when those methods had access to more explicit domain information.
- Latent Domain Discovery: Our results indicate that the model can often discover more effective "latent domains" on its own than those provided by human-labeled metadata, suggesting that explicit domain labels are frequently redundant or suboptimal.
Conclusion
Gated Domain Units provide a flexible, modular approach to domain generalization by breaking down complex distributions into invariant building blocks. By shifting from explicit domain labels to latent geometric inference, GDUs allow models to adapt to unseen environments more effectively. Future work will explore adaptive GDUs that can automatically determine the optimal number of elementary distributions ($M$) based on data complexity.
Summary updated