Questions tagged [hamming-distance]

The Hamming distance is a mathematical distance function for a pair of strings (sequences) that can be computed with a binary calculation. It counts the number of symbols in the string that are different. Posts that are not about implementation may belong on https://math.stackexchange.com.

For the special case of two binary strings, it may be implemented as the bitcount of their XOR:

int H(int a, int b){
    return popcount(a^b);
}
291 questions
3
votes
1 answer

Hamming distance in ancient Microsoft DBMS

The Problem I want to find image duplicates and similar images in MS SQL Server 7. Edit I got it running using sql cursors - it's slow but it works, thanks again for the comment. See my answer for the solution I came up with. Specifically ... I…
mfeineis
  • 2,607
  • 19
  • 22
3
votes
1 answer

T-SQL Hamming distance function capable of decimal / string / UInt64

I need to convert this c# function to a T-SQL UDF I need to get all the rows from a database that have a humming distance smaller than x This function is just part of the solution. The csharp function return 40 for these 2 hashes while the t-sql…
Johan
  • 177
  • 2
  • 6
3
votes
1 answer

Create hamming distance function in mysql without super privilege

I would like to use the hamming distance in my MySQL database (used over phpMyAdmin) but did not succeed in creating the function with the code given here. I'm refering to this code: CREATE FUNCTION HAMMINGDISTANCE( A0 BIGINT, A1 BIGINT, A2 BIGINT,…
3
votes
1 answer

8-puzzle: hamming and manahttan heuristic consider "blank space"?

I've a very simple question. I'm working on 8-puzzle (8 numbers(from 1 to 8) + blank(=0) ) When calculating hamming distance (numbers in wrong position) and manhattan distance (distance horizontal+vertical between start and final position) should I…
dragonmnl
  • 14,578
  • 33
  • 84
  • 129
2
votes
2 answers

Converting N strings to a common target string in maximum of K edits

I've a set of string [S1 S2 S3 ... Sn] and I'm to count all such target strings T such that each one of S1 S2... Sn can be converted into T within a total of K edits. All the strings are of fixed length L and an edit here is hamming distance. All…
srbhkmr
  • 2,074
  • 1
  • 14
  • 19
2
votes
1 answer

Computation of 64 bit CRC polynomial performance

I found the following page in the web: https://users.ece.cmu.edu/~koopman/crc/crc64.html It lists the performance of a handful of 64 bit CRC polynomials. The optimal payload for a hamming distance of 3 is listed as 18446744073709551551 bit. A…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
2
votes
1 answer

Finding the difference between two strings of unequal length

Given two strings s1 = 'abcdef' s2 = 'bbcdefg' The goal is to find the Hamming distance between s1 and s2, not only counting the difference of varying characters, but also any additional characters to be added to the final count. In s2 the first…
zelfde
  • 300
  • 2
  • 13
2
votes
1 answer

Count number of matching bytes between two _m128i SIMD vectors

I'm developing a bioinformatics tool and I'm trying to use SIMD to boost its speed. Given two char arrays of length 16, I need to rapidly count the number of indices at which the strings match. For example, the two following strings,…
JWO
  • 75
  • 4
2
votes
1 answer

Is there something wrong with my Python Hamming distance code?

I am trying to implement the Hamming distance in Python. Hamming distance is typically used to measure the distance between two codewords. The operation is simply performing exclusive OR. For example, if we have the codewords 10011101 and 10111110,…
The Pointer
  • 2,226
  • 7
  • 22
  • 50
2
votes
1 answer

compare 2 subgraph with Hamming distances in R

I created a graph (igraph) from interview data. I would like to compare the sub-graphs of each interview to have a relative distance from each one. I found that I could use Hamming's distance. There are a lot of packages that offer functions to…
delaye
  • 1,357
  • 27
  • 45
2
votes
1 answer

numpy bitwise_and unable to broadcast argument 1 to output array

I'm trying to implement vectorization for answer from this question Fastest way to get hamming distance for integer array r = (1 << np.arange(64, dtype=np.uint64))[:, None] def hamming_distance_v2(a, b): t = np.bitwise_xor(a, b) p =…
Alexander Karp
  • 328
  • 1
  • 5
  • 20
2
votes
2 answers

pairwise hamming distance between numpy arrays considering non-zero values only

I want to calculate the pairwise hamming distance of a 2D numpy array. My arrays is A array([[-1, 0, -1, 0, -1, 0], [ 1, 0, 0, 0, 0, 0], [ 0, 0, 1, 1, 1, 0], [ 0, 0, -1, 1, 0, 0], [ 0, 0, 0, 0, -1, …
Shew
  • 1,557
  • 1
  • 21
  • 36
2
votes
1 answer

Where the Hamming Distance Constants Came From

The function: function popcount (x, n) { if (n !== undefined) { x &= (1 << n) - 1 } x -= x >> 1 & 0x55555555 x = (x & 0x33333333) + (x >> 2 & 0x33333333) x = x + (x >> 4) & 0x0f0f0f0f x += x >> 8 x += x >> 16 return x &…
Lance
  • 75,200
  • 93
  • 289
  • 503
2
votes
1 answer

Why cv2.NORM_HAMMING gives different value than actual hamming distance?

I am using the Hamming Distance to compute the difference among two keypoints descriptors obtained by the BRISK descriptor from opencv. I follow the suggestion of opencv documentation and use cv2.NORM_HAMMING while computing the distance as…
Hasnat
  • 664
  • 1
  • 7
  • 21
2
votes
2 answers

Find the minimum hamming distance between a string and a long vector of strings (fast)

I need to calculate the hamming distance between an input string and a large string dataset. (All strings in the dataset have the same length of the input string.) For example, if input <- "YNYYEY" dataset <- c("YNYYEE", "YNYYYY", "YNENEN",…
Codezy
  • 662
  • 5
  • 17