Let A and B be sparse matrices in $ \mathbb{R}^{m\times m}$ with (roughly) the same density $p$. I want to efficiently compute a matrix $C$ that in some sense is "closest" to $AB$ while still having density $p$. "Closest" should probably mean "minimizes $||C - AB||_F$" but I'm open to other interpretations.
If $\textrm{nnz}$ is the number of non-zero entries in A (= the number of non-zero entries in B), the main computational requirement is that the operation should only need $O(\textrm{nnz})$ memory.
Question 1: this seems like a problem that would have a lot of research already, but I failed to find much. Are there any references/keywords I could use when googling?
My naive idea:
- do a sparse matmul without actually writing the resulting entries in memory. Instead, feed them into an on-line order selection algorithm to choose the $\textrm{nnz}$'th biggest-norm element in the output stream.
- Re-do the sparse matmul, but only record entries with norm greater or equal than the threshold found in step 1.
This seems to straightforwardly minimize the Frobenius norm but is also kind of inefficient: asymptotically the runtime can still be $O(m^2)$ for bad sparsity patterns, and practically, we're essentially doing the multiplication twice.
Also, it's unclear what to do with a matrix whose non-zero entries are all identical. Maybe just take the first $nnz$ entries? But that makes analysis much harder.
Question 2: are there any obvious improvements to this?
Question 3: what's the dynamic behavior of this algorithm, under the assumption that all non-zero entries are distinct? E.g. let $\odot$ be this density-preserving multiplication and $M_i$ be sparse matrices. Can we say anything about $||(M_1 M_2 \ldots M_n) - (M_1 \odot M_2 \odot \ldots \odot M_n)||_F$ ? Probably not for pathological cases, but what about if $M_i$ are iid random sparse matrices?