Finding hamming distance of code

偶尔善良 提交于 2019-12-31 23:00:09

问题


A question asks: find the hamming distance of the following code:

11111  
10101  
01010  
11100  
00011  
11001

The answer is 2. How does this work? I thought hamming distance is only between two strings?


回答1:


The Hamming distance of a code is defined as the minimum distance between any 2 codewords. So, in your case, finding the Hamming distance between any 2 of the listed codewords, no one is less than 2.




回答2:


Here is some Python-code to find it automatically:

code = [
(0,0,0,0,0,0),
(0,0,1,0,0,1),
(0,1,0,0,1,0),
(0,1,1,0,1,1),
(1,0,0,1,0,0),
(1,0,1,1,0,1),
(1,1,0,1,1,0),
(1,1,1,1,1,1)]

def hammingDistance(a, b):
    distance = 0
    for i in xrange(len(a)):
        distance += a[i]^b[i]
    return distance

def minHammingDistance(code):
    minHammingDistance = len(code[0])
    for a in code:
        for b in code:
            if a != b:
                tmp = hammingDistance(a, b)
                if tmp < minHammingDistance:
                    minHammingDistance = tmp
    return minHammingDistance

print("min Hamming distance: %i" % minHammingDistance(code))



回答3:


We have a theorem that d_min=weight(sum(all codes)); weight is the number of non zeros in the result string . In your example modulo add all string codes like first column of all and second....... then we get code as [ 0 0 1 1 0 ], weight of this is 2 ( no. of non zeros), i.e the minimum distance of hamming code



来源:https://stackoverflow.com/questions/12741613/finding-hamming-distance-of-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!