Better Size Estimation for Sparse Matrix Products

Rasmus Resen Amossen, Andrea Campagna, Rasmus Pagh · DOI

TL;DR

This paper presents a novel algorithm for efficiently and accurately estimating the number of non-zero entries in the product of two sparse boolean matrices. The new method achieves linear time complexity and significantly improves upon previous state-of-the-art techniques, making it highly relevant for applications in databases and computer algebra.

What Problem Does This Paper Address?

Estimating the size of a sparse matrix product is a crucial problem in various computational fields, particularly in database query optimization and computer algebra. When dealing with large sparse matrices, explicitly computing the product to count its non-zero entries can be prohibitively expensive, often requiring superlinear time complexity. Existing algorithms for size estimation, while better than direct computation, still fall short of optimal efficiency. For instance, Cohen's algorithm from 1997 offers a 1 ± ε approximation in O(n/ε²) time, which can be slow for small ε. The challenge is to find an algorithm that can provide accurate size estimates in near-linear time, even for matrices where the resulting product has a relatively small number of non-zero entries.

Methods

The core of the paper's contribution lies in a new estimation algorithm that leverages a specific type of pairwise independent hash function. This hash function allows for the efficient computation of a "sketch" of a set of the form A × C in expected linear time and I/Os. The algorithm builds upon the idea of data stream sketching, specifically adapting techniques for estimating distinct elements.

Key methodological aspects include:

  • Pairwise Independent Hash Functions: The paper utilizes hash functions that are "sufficiently structured" to allow efficient manipulation of sketches and "sufficiently random" to ensure analytical guarantees.
  • Sketching Technique: Instead of explicitly generating all pairs in a matrix product, the algorithm maintains a sketch of relevant information. This sketch is updated incrementally.
  • Buffering Trick: A novel buffering technique is introduced to update the sketch in amortized O(1) time per pair, avoiding the logarithmic factor associated with heap data structures.
  • Sampling: The paper also explores using sampling to maintain sketches, offering a simpler alternative to existing methods and matching theoretical space lower bounds.

Datasets

The paper evaluates its algorithm on several real-world datasets. These datasets are primarily sourced from the Frequent Itemset Mining Implementations (FIMI) Repository and the Internet Movie Database (IMDB). The experiments involve performing size estimation on self-joins of these relations, effectively treating them as sparse matrices. The paper provides a table (Table 1) detailing the characteristics of these datasets, including their size and the number of distinct attribute values.

Key Insights and Ideas

  • Linear Time Estimation is Achievable: The most significant insight is that accurate size estimation for sparse matrix products can be achieved in expected linear time (O(n)), a substantial improvement over previous algorithms.
  • The Power of Structured Hashing: The choice of specific pairwise independent hash functions is critical. They enable efficient sketch updates without needing to materialize the entire intermediate products.
  • Bridging Streaming and Matrix Computations: The work effectively bridges techniques from data stream algorithms (like distinct element estimation) to the domain of matrix computations, demonstrating a powerful cross-pollination of ideas.
  • Practical Performance Exceeds Theory: Experimental results show that the algorithm's practical accuracy is often much better than the worst-case theoretical bounds predict, suggesting its robustness in real-world scenarios.

Key Results

The paper presents two main theoretical results:

  • Theorem 1: An algorithm that runs in expected O(n) time on a RAM and expected O(sort(n)) I/Os in the cache-oblivious model. It outputs an estimate $\tilde{z}$ such that for a given error tolerance $\varepsilon$, it provides a $(1 \pm \varepsilon)$ approximation of the true size $z$ with probability at least 2/3, provided $z$ is sufficiently large ($z > k^2$, where $k = 9/\varepsilon^2$).
  • Theorem 2: For a constant $\varepsilon$, this algorithm achieves a $(1 \pm \varepsilon)$ approximation with probability $1 - O(1/n)$ in expected O(n) RAM time and expected O(sort(n)) I/Os.

Experimentally, the paper demonstrates that:

  • The algorithm's observed error is significantly smaller than the theoretical bounds. For example, with $k=1024$, 2/3 of the estimates are within 4% and 10% of the exact size, respectively.
  • Sampling probabilities of 10% and 1% were tested, showing that while very small probabilities can lead to no estimate being returned, the observed errors are still much smaller than theoretical bounds.

Limitations and Future Work

  • Transitive Closure Extension: The authors pose an "interesting open problem" of whether their techniques can be extended to achieve similar efficiency for transitive closure in general graphs, and/or for products of more than two matrices.
  • Parameter Sensitivity: While the theoretical analysis provides bounds, the practical performance might still be sensitive to the choice of parameters like $k$ and $\varepsilon$. The paper notes that in practice, the initial threshold $p$ quickly decreases, which is beneficial but might require careful handling in the implementation.
  • Hash Function Realization: The paper discusses the practical realization of hash functions by approximating real numbers with rational numbers. While this approximation is shown to be negligible, it's a point of practical implementation detail.

Summary updated

BibTeX
@article{amossen2014better,
  author = {Rasmus Resen Amossen and Andrea Campagna and Rasmus Pagh},
  title = {{Better Size Estimation for Sparse Matrix Products}},
  journal = {Algorithmica},
  year = {2014},
  doi = {10.1007/s00453-012-9692-9},
}
Figure