Binary Code Ranking with Weighted Hamming Distance

Lei Zhang, Yongdong Zhang, Jinhui Tang, Ke Lu, Qi Tian

Abstract

Standard binary hashing is efficient for large-scale retrieval but suffers from "distance ties" due to the discrete nature of Hamming distance. We present WhRank, a method that introduces data-adaptive and query-sensitive weights to binary bits. By breaking the integer barrier of standard Hamming distance, WhRank enables finer-grained ranking, significantly improving retrieval precision across various hashing algorithms without sacrificing the efficiency of binary codes.

Introduction

In large-scale image retrieval, binary hashing maps high-dimensional data into short binary strings, allowing for extremely fast similarity searches using Hamming distance. However, because Hamming distance is discrete and bounded (e.g., only 33 possible values for a 32-bit code), it frequently results in "distance ties." In a large database, thousands of images may share the same integer distance from a query, making it impossible to rank the most relevant results effectively. WhRank addresses this bottleneck by moving from integer distances to floating-point weighted distances.

Methods: Data-Adaptive and Query-Sensitive Weighting

WhRank assigns a weight $\omega_k$ to each bit $k$ based on two primary factors:

  1. Data-Adaptive Weighting: This component analyzes the distribution of "unbinarized" hash values across the dataset. Bits that are more stable across neighbors or have higher discriminative power are assigned different weights to reflect their global reliability.
  2. Query-Sensitive Weighting: This is the core innovation. For a specific query, bits are weighted based on their "stability." If a query's raw value is far from the hashing threshold, the resulting bit is stable; if it is near the threshold, a tiny amount of noise could flip it. WhRank assigns higher weights to flips on stable bits because such a flip is a much stronger signal of actual difference between points.
Geometric intuition of hashing (left) and the probabilistic model for bit flipping based on the distance between the query value $f_k(q)$ and the threshold $T_k$ (right).

The algorithm estimates the probability of a bit-flip occurring for a neighbor and uses Information Entropy principles to derive optimal weights. Crucially, WhRank acts as a post-processing ranking step: standard Hamming distance can quickly retrieve a candidate set, which WhRank then sorts with high precision.

Key Insights: The Stability Principle

The fundamental insight of WhRank is that a bit flip's meaning is query-dependent. Empirical analysis validates this "Stability Principle," showing clear correlations between bit-flipping probability and the physical characteristics of the hash values.

Empirical correlation between bit-flipping probability and distance to threshold (left) and standard variance (right).

As illustrated in the figure above, the probability of a bit flipping decreases as the distance to the threshold increases and increases as the standard variance of the bit increases. By modeling these relationships, WhRank effectively distinguishes between meaningful signal and noise in the binary code.

Results and Performance

The authors evaluated WhRank on the MNIST70K and ANN-SIFT1M benchmarks across several baselines, including ITQ, SPH, and LSH. Key findings include:

  • Precision Boost: WhRank improved precision by an average of 5% to 10% across all tested hashing methods.
  • Error Reduction: On the SIFT1M dataset, the distance error ratio was reduced by approximately 40%.
  • Efficiency: Using a 32-bit code with WhRank often outperformed 64-bit or 96-bit codes using standard Hamming distance, allowing for better accuracy with lower memory overhead.

Conclusion

WhRank provides a robust, algorithm-agnostic framework for breaking Hamming distance ties. By incorporating both global data characteristics and query-specific stability, it offers a significant boost to retrieval accuracy while remaining computationally efficient for large-scale applications.

Summary updated

BibTeX
@inproceedings{zhang2013binary,
  author = {Lei Zhang and Yongdong Zhang and Jinhui Tang and Ke Lu and Qi Tian},
  title = {{Binary Code Ranking with Weighted Hamming Distance}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2013},
  doi = {10.1109/cvpr.2013.208},
}
Figure