#encoding: utf8
#根据输入矩阵计算矩阵用来比较相似度的一个特征值
#计算公式是：Sum(i,n)(i*根号(pos(i)(x)^2-pos(i)(y)^@))/n, n是所有点的个数

def count_similarity(data, size):
    # count the similarity
    sum = 0.0
    for y in range(0, size[0]):
        for x in range(0, size[1]):
            idx = y * size[1] + x
            digit = data[idx]
            sum += (digit * 1.0 * ((abs(x ** 2 - y ** 2)) ** 0.5))
    return sum / ((size[0] * size[1]) ** 1.5)
