- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个过程,类似于生成感知哈希的 tineye,这些是 32 位整数。
我打算将来将这些存储在 sql 数据库(可能是 nosql db)中
但是,我对如何根据哈希的相似性检索记录感到困惑。
有任何想法吗?
最佳答案
一种常见的方法(至少对我来说是常见的)是将您的哈希位字符串分成几个块并在这些块上查询以进行精确匹配。这是一个“预过滤”步骤。然后,您可以对返回的结果执行按位汉明距离计算,这应该只是整个数据集的一个较小子集。这可以使用数据文件或 SQL 表来完成。
简单来说:假设您在数据库中有一堆 32 位散列,并且您想找到在“查询”散列的 4 位汉明距离内的每个散列:
qslice1=islice1 or qslice2=islice2 or qslice3=islice3 or qslice4=islice4
中的任何一个.这为您提供了查询哈希的 3 位 ( 4 - 1
) 内的每个数据库哈希。
- APPROXIMATE NEAREST NEIGHBOR SEARCH IN HAMMING SPACE
[...]
Given bit vectors consisting of d bits each, we choose N = O(n 1/(1+ ) ) random permutations of the bits. For each random permutation σ, we maintain a sorted order O σ of the bit vectors, in lexicographic order of the bits permuted by σ. Given a query bit vector q, we find the approximate nearest neighbor by doing the following:
For each permutation σ, we perform a binary search on O σ to locate the two bit vectors closest to q (in the lexicographic order obtained by bits permuted by σ). We now search in each of the sorted orders O σ examining elements above and below the position returned by the binary search in order of the length of the longest prefix that matches q.
3.3 The Results for Algorithm C
We partitioned the bit string of each page into 12 non- overlapping 4-byte pieces, creating 20B pieces, and computed the C-similarity of all pages that had at least one piece in common. This approach is guaranteed to find all pairs of pages with difference up to 11, i.e., C-similarity 373, but might miss some for larger differences.
- THE HAMMING DISTANCE PROBLEM
Definition: Given a collection of f -bit fingerprints and a query fingerprint F, identify whether an existing fingerprint differs from F in at most k bits. (In the batch-mode version of the above problem, we have a set of query fingerprints instead of a single query fingerprint)
[...]
Intuition: Consider a sorted table of 2 d f -bit truly random fingerprints. Focus on just the most significant d bits in the table. A listing of these d-bit numbers amounts to “almost a counter” in the sense that (a) quite a few 2 d bit- combinations exist, and (b) very few d-bit combinations are duplicated. On the other hand, the least significant f − d bits are “almost random”.
Now choose d such that |d − d| is a small integer. Since the table is sorted, a single probe suffices to identify all fingerprints which match F in d most significant bit-positions. Since |d − d| is small, the number of such matches is also expected to be small. For each matching fingerprint, we can easily figure out if it differs from F in at most k bit-positions or not (these differences would naturally be restricted to the f − d least-significant bit-positions).
The procedure described above helps us locate an existing fingerprint that differs from F in k bit-positions, all of which are restricted to be among the least significant f − d bits of F. This takes care of a fair number of cases. To cover all the cases, it suffices to build a small number of additional sorted tables, as formally outlined in the next Section.
关于sql - 数据库中的汉明距离/相似性搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9606492/
我是一名优秀的程序员,十分优秀!