hamming-distance

Bit string nearest neighbour searching

…衆ロ難τιáo~ 提交于 2019-12-19 08:53:11
问题 I have hundreds of thousands of sparse bit strings of length 32 bits. I'd like to do a nearest neighbour search on them and look-up performance is critical. I've been reading up on various algorithms but they seem to target text strings rather than binary strings. I think either locally sensitive hashing or spectral hashing seem good candidates or I could look into compression. Will any of these work well for my bit string problem ? Any direction or guidance would be greatly appreciated. 回答1:

Generate all sequences of bits within Hamming distance t

家住魔仙堡 提交于 2019-12-17 14:55:46
问题 Given a vector of bits v , compute the collection of bits that have Hamming distance 1 with v , then with distance 2, up to an input parameter t . So for 011 I should get ~~~ 111 001 010 ~~~ -> 3 choose 1 in number 101 000 110 ~~~ -> 3 choose 2 100 ~~~ -> 3 choose 3 How to efficiently compute this? The vector won't be always of dimension 3, e.g. it could be 6. This will run numerous time in my real code, so some efficiency would be welcome as well (even by paying more memory). My attempt:

How should I store and compute Hamming distance between binary codes?

蓝咒 提交于 2019-12-14 01:46:33
问题 How can I efficiently store binary codes? For certain fixed sizes, such as 32 bits, there are primitive types that can be used. But what if I my binary codes are much longer? What is the fastest way to compute the Hamming distance between two binary codes? 回答1: Use std::bitset<N>, defined in the <bitset> header, where N is the number of bits ( not bytes). Compute the Hamming distance between two binary codes a and b using (a ^ b).count() . 来源: https://stackoverflow.com/questions/26168753/how

input 2 integers and get binary, brgc, and hamming distance

独自空忆成欢 提交于 2019-12-12 19:00:49
问题 I've got everything except hamming distance. I keep getting the error "int() can't convert non-string with explicit base" here is my code: def int2bin(n): if n: bits = [] while n: n,remainder = divmod(n, 2) bits.insert(0, remainder) return bits else: return [0] def bin2gray(bits): return bits[:1] + [i ^ ishift for i, ishift in zip(bits[:-1], bits[1:])] def hamming(a,b): assert len(a) == len(b) count,z = 0,int(a,2)^int(b,2) while z: count += 1 z &= z-1 return count def main(): a = int(input(

Can I derive the hamming distance by subtracting the hamming weight of two integers?

你。 提交于 2019-12-11 09:46:28
问题 Can I get the hamming distance between two numbers by subtracting the hamming weight of them? I have to write a program in assembly to derive the hamming distance between two decimal integers. I was just curious as to if it was possible to simply subtract the hamming weights of said integers. Or would it be better to just go the XOR instruction route and create a loop to count the ones? 回答1: I agree with Jester, I tried the subtracting method and it gives the wrong answer. So I tried bit by

Fastest way to calculate Hamming Distance in C#

风格不统一 提交于 2019-12-11 04:13:05
问题 I have a large collection (n = 20,000,000) of BigInteger, representing bit arrays of length 225. Given a single BigInteger, I want to find the x BigInteger within my collection below a certain Hamming distance. Currently, I convert all BigInteger to byte arrays: bHashes = new byte[hashes.Length][]; for (int i = 0; i < hashes.Length; i++) { bHashes[i] = hashes[i].ToByteArray(); } I then create a Hamming distance lookup array: int[][] lookup = new int[256][]; for (int i = 0; i < 256; i++) {

Similarity of two Hexadecimal numbers

梦想的初衷 提交于 2019-12-11 00:01:40
问题 I am trying to find similar hashes (hexadecimal hash) using hamming and Levenshtein distance. Lets say two hashes are similar if their hamming distance is less than 10 (number of differing bits). Hash 1= ffffff (base 16) Hash 2= fffff0 (base 16) The hamming distance between two hashes is 4. They are similar. Because, Hash 1= 11111111 11111111 11111111 (base 2) Hash 2= 11111111 11111111 11110000 (base 2) I have 8 million such hashes. I am wondering what will be a suitable data structure for

Calculate Hamming distance between two strings of binary digits in Matlab

最后都变了- 提交于 2019-12-10 22:54:43
问题 I have two equal length strings containing 1's and 0's. Each string is 128-bits long, and I want to calculate the Hamming distance between them. What's the best way I can go about doing this? e.g. a='1000001' and b='1110001' --> dist=Hamming(a,b); 回答1: Use pdist with the hamming parameter. 回答2: dist = sum(a ~= b); 来源: https://stackoverflow.com/questions/4178469/calculate-hamming-distance-between-two-strings-of-binary-digits-in-matlab

Fast hamming distance computation between binary numpy arrays

≯℡__Kan透↙ 提交于 2019-12-10 13:05:32
问题 I have two numpy arrays of the same length that contain binary values import numpy as np a=np.array([1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0]) b=np.array([1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1]) I want to compute the hamming distance between them as fast as possible since I have millions of such distance computations to make. A simple but slow option is this (taken from wikipedia): %timeit sum(ch1 != ch2 for ch1, ch2 in zip(a, b)) 10000 loops,

Finding a number of maximally different binary vectors from a set

耗尽温柔 提交于 2019-12-09 05:22:28
问题 Consider the set, S , of all binary vectors of length n where each contains exactly m ones; so there are n-m zeros in each vector. My goal is to construct a number, k , of vectors from S such that these vectors are as different as possible from each other. As a simple example, take n =4, m =2 and k =2, then a possible solution is: [1,1,0,0] and [0,0,1,1]. It seems that this is an open problem in the coding theory literature (?). Is there any way (i.e. algorithm) to find a suboptimal yet good