Random Forests for Metric Learning with Implicit Pairwise Position Dependence

Caiming Xiong, David M. Johnson, Ran Xu, Jason J. Corso

Introduction

Metric learning is a fundamental task in machine learning, aimed at discovering a distance function that captures the underlying structure of data more effectively than standard Euclidean distance. Traditionally, researchers have faced a stark tradeoff: global metrics, which are computationally efficient but struggle with complex, non-linear geometries; and multi-metric methods, which are highly accurate but suffer from prohibitive computational and memory costs. This paper introduces Random Forest Distance (RFD), a novel approach that bridges this gap by using a random forest classifier to learn a single distance function that implicitly adapts to local regions of the feature space.

The Challenge of Metric Learning

Standard metric learning often relies on "must-link" and "cannot-link" constraints to learn a custom distance function.

  1. Global Mahalanobis Metrics: These learn a single linear transformation for the entire dataset. While fast, they fail on heterogeneous data because a single metric cannot capture varying local geometries.
  2. Multi-Metric Methods: These learn unique metrics for different regions or instances. While adaptable, they require learning and storing $O(n)$ matrices, leading to massive overhead.

The authors propose a "middle ground": a single, efficient metric with the flexibility to adapt its calculations based on the location of data points in the feature space.

Methodology: Random Forest Distance (RFD)

RFD reframes metric learning as a binary classification problem. Given a pair of points, the model classifies them as similar (0) or dissimilar (1). The final distance is defined as the percentage of trees in the forest that vote "dissimilar."

Implicit Pairwise Position Dependence

The core innovation lies in the feature mapping function. Traditional methods typically only consider the relative position (the difference $|x_i - x_j|$). RFD augments this with absolute position information (the mean $\frac{1}{2}(x_i + x_j)$).

RFD performance on a complex geometric dataset compared to standard metrics as the number of nearest neighbors increases.

By including absolute position, the decision trees can split nodes based on where points are located. This allows the single forest to implicitly apply different distance logic to different localized sub-spaces, effectively mimicking a multi-metric approach without the associated overhead. As shown in the figure above, this allows RFD to maintain high accuracy even as the number of nearest neighbors ($k$) increases, whereas global metrics often degrade rapidly due to non-linearity.

Experimental Evaluation

The authors evaluated RFD against state-of-the-art global and local methods using 10 UCI datasets and the Corel Image Database.

Key Results

  • Superior Accuracy: On the UCI datasets, RFD consistently outperformed global methods like LMNN and ITML. It also achieved comparable or superior accuracy to state-of-the-art multi-metric methods like ISD.
  • The Power of Position: The inclusion of absolute position (RFD+P) was critical for performance, particularly in datasets with complex local structures.
  • Computational Efficiency: RFD proved to be 16x to 85x faster than the leading multi-metric method (ISD) because it avoids the need to learn thousands of individual matrices.
Classification accuracy of RFD versus state-of-the-art global and local metric learning methods across various UCI datasets.

Conclusion

Random Forest Distance provides a highly efficient yet flexible framework for metric learning. By leveraging the natural space-partitioning properties of decision trees and incorporating absolute position information, RFD achieves the performance of localized multi-metric methods with the speed of global approaches. While it technically violates the triangle inequality—a necessary tradeoff for positional flexibility—its empirical success across diverse classification and retrieval tasks makes it a powerful tool for modern machine learning pipelines.

Summary updated

BibTeX
@inproceedings{xiong2012random,
  author = {Caiming Xiong and David M. Johnson and Ran Xu and Jason J. Corso},
  title = {{Random Forests for Metric Learning with Implicit Pairwise Position Dependence}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2012},
  url = {https://openreview.net/forum?id=ByZi0N-_WS},
}
Figure