海明距离hamming distance

仔细阅读ORB的代码,发现有很多细节不是很明白,其中就有用暴力方式测试Keypoints的距离,用的是HammingLUT,上网查了才知道,hamming距离是相差位数。这样就好理解了。

我理解的HammingLUT lut;

result=lut((a),(b),size_t size):result=a与b的hamming distance+size;

[cpp] view plain copy

print?

  1. unsigned int hamdist(unsigned int x, unsigned int y)
  2. {
  3. unsigned int dist = 0, val = x ^ y;
  4. // Count the number of set bits
  5. while(val)
  6. {
  7. ++dist;
  8. val &= val - 1;
  9. }
  10. return dist;
  11. }
  12. unsigned int hamdist2(unsigned char* a, unsigned char* b, size_t size)
  13. {
  14. HammingLUT lut;
  15. unsigned int result;
  16. result = lut((a), (b), size);
  17. return result;
  18. }

In information theory, the Hamming distance, named after Richard Hamming, is the number of positions in two strings of equal length for which the corresponding elements are different. Put another way, it measures the number of substitutions required to change one into the other.
    汉明距离是以理查德·卫斯里·汉明的名字命名的。在信息论中,两个等长字符串之间的汉明距离是两个字符串对应位置的不同字符的个数。换句话说,它就是将一个字符串变换成另外一个字符串所需要替换的字符个数。
    For example:
    例如:
    The Hamming distance between 1011101 and 1001001 is 2. 
    The Hamming distance between 2143896 and 2233796 is 3. 
    The Hamming distance between "toned" and "roses" is 3. 
    1011101 与 1001001 之间的汉明距离是 2。
    2143896 与 2233796 之间的汉明距离是 3。
    "toned" 与 "roses" 之间的汉明距离是 3。
    The Hamming weight of a string is its Hamming distance from the zero string (string consisting of all zeros) of the same length. That is, it is the number of elements in the string which are not zero: for a binary string this is just the number of 1‘s, so for instance the Hamming weight of 11101 is 4.
    汉明重量是字符串相对于同样长度的零字符串的汉明距离,也就是说,它是字符串中非零的元素个数:对于二进制字符串来说,就是 1 的个数,所以 11101 的汉明重量是 4。
    The Hamming distance between two words a and b, viewed as elements of a vector space, can then be seen as the Hamming weight of a-b. If a and b are binary strings this is equivalent to a+b and to a XOR b. The Hamming distance is also equivalent to the Manhattan distance between two vertices in an n-dimensional hypercube, where n is the length of the words.
    如果把a和b两个单词看作是向量空间中的元素,则它们之间的汉明距离等于它们汉明重量的差a-b。如果是二进制字符串a和b,汉明距离等于它们汉明重量的 和a+b或者a和b汉明重量的异或a XOR b。汉明距离也等于一个n维的超立方体上两个顶点间的曼哈顿距离,n指的是单词的长度。
    The Hamming distance is used in telecommunication to count the number of flipped bits in a fixed-length binary word, an estimate of error, and so is sometimes called the signal distance. Hamming weight analysis of bits is used in several disciplines including information theory, coding theory, and cryptography. For comparing strings of different lengths, or strings where insertions or deletions are expected, not just substitutions, a more sophisticated metric like the Levenshtein distance is more appropriate.
    汉明距离可以在通信中累计定长二进制字中发生翻转的错误数据位,所以它也被称为信号距离。汉明重量分析在包括信息论、编码理论、密码学等领域都有应用。但 是,如果要比较两个不同长度的字符串,不仅要进行替换,而且要进行插入与删除的运算,在这种场合下,通常使用更加复杂的编辑距离等算法。

from: http://blog.csdn.net/yangtrees/article/details/7543553

时间: 2024-08-29 05:10:16

海明距离hamming distance的相关文章

64. 海明距离(Hamming Distance)

[本文链接] http://www.cnblogs.com/hellogiser/p/hamming-distance.html [介绍] 在信息领域,两个长度相等的字符串的海明距离是在相同位置上不同的字符的个数,也就是将一个字符串替换成另一个字符串需要的替换的次数. 例如: xxxxyy和xxxxzz的海明距离是2: 111100 和 111111 的海明距离是2: 对于二进制数字来说,海明距离的结果相当于a^b结果中1的个数. [字符串] C++ Code 12345678910111213

海量数据相似度计算之simhash和海明距离

通过 采集系统 我们采集了大量文本数据,但是文本中有很多重复数据影响我们对于结果的分析.分析前我们需要对这些数据去除重复,如何选择和设计文本的去重算法?常见的有余弦夹角算法.欧式距离.Jaccard相似度.最长公共子串.编辑距离等.这些算法对于待比较的文本数据不多时还比较好用,如果我们的爬虫每天采集的数据以千万计算,我们如何对于这些海量千万级的数据进行高效的合并去重.最简单的做法是拿着待比较的文本和数据库中所有的文本比较一遍如果是重复的数据就标示为重复.看起来很简单,我们来做个测试,就拿最简单的

Leetcode 461. Hamming Distance JAVA语言

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. PS:求海明距离. 思路:就是求x和y二进制的异或中的1的个数 public class Solution {     public int ham

Matlab计算两集合间的海明距离

一.问题描述 B1[1 2 3 4 5 6 7 8 9] B2[12 13 14 21 31 41 51  1 1 81 1 1] 两个十进制矩阵,行数不一样,分别是n1和n2,列数必须一致,为nwords,输出的矩阵Dh是[n1,n2],这和求两句真的欧氏距离一样的. 输出[1 1] = 1和12海明+2和13海明 + 3和14海明,[1 2] = 1和21 + 2和31 + 3和41,也就是说[i j]是B1第i行和B2第j行的海明距离. 二.问题分析 1和12 21 51 81分别求海明距

【转】海量数据相似度计算之simhash和海明距离

通过 采集系统 我们采集了大量文本数据,但是文本中有很多重复数据影响我们对于结果的分析.分析前我们需要对这些数据去除重复,如何选择和设计文本的去重算法?常见的有余弦夹角算法.欧式距离.Jaccard相似度.最长公共子串.编辑距离等.这些算法对于待比较的文本数据不多时还比较好用,如果我们的爬虫每天采集的数据以千万计算,我们如何对于这些海量千万级的数据进行高效的合并去重.最简单的做法是拿着待比较的文本和数据库中所有的文本比较一遍如果是重复的数据就标示为重复.看起来很简单,我们来做个测试,就拿最简单的

使用simhash以及海明距离判断内容相似程度

算法简介 SimHash也即相似hash,是一类特殊的信息指纹,常用来比较文章的相似度,与传统hash相比,传统hash只负责将原始内容尽量随机的映射为一个特征值,并保证相同的内容一定具有相同的特征值.而且如果两个hash值是相等的,则说明原始数据在一定概率下也是相等的.但通过传统hash来判断文章的内容是否相似是非常困难的,原因在于传统hash只唯一标明了其特殊性,并不能作为相似度比较的依据. SimHash最初是由Google使用,其值不但提供了原始值是否相等这一信息,还能通过该值计算出内容

461. Hamming Distance

The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, calculate the Hamming distance. Note:0 ≤ x, y < 2^31. Example: Input: x = 1, y = 4 Output: 2 Explanation:

HDU 4712 Hamming Distance (随机函数)

Hamming Distance Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1806    Accepted Submission(s): 714 Problem Description (From wikipedia) For binary strings a and b the Hamming distance is equal

UVa 729 - The Hamming Distance Problem

题目:构造n位01串,其中有m个1的所有组合. 分析:搜索.枚举.可以利用库函数,求解,也可以利用dfs求解:我这里采用位运算计算组合数. 说明:注意库啊! #include <iostream> #include <cstdlib> #include <cstdio> using namespace std; int S[20]; int main() { int T,N,M; while ( cin >> T ) for ( int t = 1 ; t