Generation of n binary vectors, where each vector has a Hamming distance d from any other vector

I am trying to generate binary vectors of nsome arbitrary length l, where each vector ihas a Hamming distance d(where is deven) from any other vector j. I am not sure if there are any theoretical relationships between n, land d, but I wonder if there are any implementations for this task. My current implementation is shown below. Sometimes I am successful, sometimes the code hangs, which indicates either: a) it is impossible to find nsuch vectors, data, land d, or b) the search takes a lot of time, especially for large values l.

My questions:

  • Are there any effective implementations of this task?
  • What theoretical relationships exist between n, land d?

    import numpy as np
    
    def get_bin(n):
        return ''.join([str(np.random.randint(0, 2)) for _ in range(n)])
    
    def hamming(s1, s2):
        return sum(c1 != c2 for c1, c2 in zip(s1, s2))
    
    def generate_codebook(n, num_codes, d):    
        codebooks = []
        seen = []
    
        while len(codebooks) < num_codes:
            code = get_bin(n)
            if code in seen:
                continue
            else:
                if len(codebooks) == 0:
                    codebooks.append(code)
                    print len(codebooks), code
                else:
                    if all(map(lambda x: int(hamming(code, x)) == d, codebooks)):
                        codebooks.append(code)
                        print len(codebooks), code
                seen.append(code)
    
        codebook_vectorized = map(lambda x: map(lambda b: int(b), x), codebooks)
        return np.array(codebook_vectorized)
    

Example:

codebook = generate_codebook(4,3,2)
codebook

1 1111
2 1001
3 0101
+6
source share
2 answers

Let's build a graph Gwhere each- Lbit binary vector vis a vertex. And there is an edge (vi, vj)only when the Hamming distance is between viand vjequal to d. Now we need to find the clique size n.

Clique is a subset of vertices of an undirected graph for which each two different vertices in a clique are adjacent.

NP-. .

. , . , , .

+2

, l, d n . , ( , ) . , , , .

, l = 6. , ( , , ). , v1 = 000000. , d = 1, , , n 1 2 ( 111111). d = 1, , n 1 2; , 000001, 2 , , , .

, d = 4. 4 2, 4- 6- , 15 , 001111, 010111 .. - , C(n, d) 1 n. v2 = 001111 , T = [1, 2], - S = [3, 4, 5, 6]. , , v2; , , :

  • 4 v2.
  • S, T ( ). v1 .

, d , ( ), , , , . , , 2, 2 S, C(4, 2) = 6 2 T, C(2, 2) = 1, 6 * 1 = 6 - C(d, d/2) * C(l - d, d/2) + 2 - n, d . v3 = 111100. v3 : , v1, v2, P1 = [1, 2], , v1, v2, P2 = [] ( ), , v1, v2, P3 = [3, 4] , v2, v1, P4 = [5, 6]. 4 , , P1, P2, , P3, P4 . - v4 = 110011, : n 4.

, , " " (2 , 4 , 8, 16...), , , "" "". ( , , ) " " . , , , / l d n, .

+2

All Articles