What do you do when you have to compute pairwise distances many times, and those damn distances take a long time to compute? Answer: You cache the distances and permute the underlying sample labels!

cachePermute(dists, forward, reverse)

Arguments

dists

\({N \choose 2}\) by \(B\) matrix, with each column containing the distances (ex: Hamming, \(l_p^p\)) for the block

forward

\(N \times N\) matrix mapping the pairs of sample labels to index of the \({N \choose 2}\)-length vector

reverse

\({N \choose 2}\times 2\) matrix mapping the index to pairs of sample labels

Value

A matrix with same dimensions as dists containing the block-permuted pairwise distances

Details

This function permutes the distances (Hamming, \(l_p^p\), etc.) within blocks. Permutations respect the fact that we are actually permuting the underlying labels. Arguments forward and reverse should be precomputed using buildForward and buildReverse.

Dependencies: buildForward, buildReverse