I am looking for a faster way of finding large subsets of lists that obey pairwise conditions. In particular, I'm looking for a large (over 10k) set of quaternary words (i.e. ordered lists) of length 13 with Hamming distance greater than 5.
Here's an example in code: there are 67,108,864 words with 4 letters:
all = Tuples[Range[4], 13];
A naive solution to find a set that are all at least Hamming distance 5, we can sample one-at-a-time and compare to the current set:
set = Internal`Bag[];
Internal`StuffBag[set, RandomChoice[all]];
Dynamic[Internal`BagLength[set], UpdateInterval -> 1]
While[Internal`BagLength @ set < 10000,
new = RandomChoice[all];
If[AllTrue[Internal`BagPart[set, All],
HammingDistance[new, #] > 5 &], Internal`StuffBag[set, new]]]
result = Internal`BagPart[set, All];
I'm looking to find a set of length 10,000 but at the moment this code is just too slow, after an hour it only found about 1,400.
Can this type of random search problem be accelerated using compilation, parallelization, graph theory, heuristics, or anything else?
Related:
- This is equivalent to the graph problem of finding a clique of size $n$, however it's too costly to build the underlying graph. Still maybe
FindKClique
could be useful somehow? - For the n=4 case, R implements multicore evolutionary algorithms for the same problem with DNA strings
- Compiled hamming distance: Fastest way to measure Hamming distance of integers
"DynamicArray"
data structure? Slightly off topic since in this question appending elements to the list is not the rate limiting step. $\endgroup$NearestFunction
at each iteration of theWhile
loop and using that to find the nearest already-selected element. But the scaling of this problem means it still slows to a crawl eventually. $\endgroup$