0

I'm trying to compare three different decoders for Hamming codes in python: brute force, local search, and syndrome. I am having issues with my brute force implementation:

def bruteForce(v):
    n = len(v)
    r = int(math.log(n+1,2))
    k = n-r
    m = []
    d = []
    c = []
    for i in range(2**k):
        m.append(decimalToVector(i,k))
    for j in range(2**k):
        d.append(hammingDistance(matrixMult(m[j], HammingG(r)),v))
    for l in range(2**k):
        if d[l] <= 1:
             c = matrixMult(m[l], HammingG(r))
    return c

This runs without error, but the output is simply [], instead of any sequence of binary numbers, when the input is a vector such as bruteForce([1,0,0,0,0,0,1]).

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
user3236854
  • 11
  • 1
  • 2
  • 2
    What exactly is your problem? Errors (provide traceback)? Unexpected outputs (provide inputs, expected outputs, actual outputs)? – jonrsharpe Feb 14 '14 at 11:23
  • The brute force compiles fine, but the output is simply "[]" instead of any sequence of binary numbers when the input is a vector such as bruteForce([1,0,0,0,0,0,1]) – user3236854 Feb 14 '14 at 12:18
  • Is `[]` unexpected as output? If so, why do you initialize c to `[]`? In your code, the value returned is either this empty list (if `d[l] > 1` for all `l`), or the result of the last computation in the last loop. – Armin Rigo Feb 14 '14 at 12:25

1 Answers1

0

This is only guessing, but you might as well check if d[l] <= 1 is really correct. One of the hallmarks of Hamming code is error correction and it is possible because the minimal distance is 3. Your code looks as if you implemented a mere parity check code (minimal distance == 1.)

nodakai
  • 7,773
  • 3
  • 30
  • 60