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
1
vote
2 answers

Sum of all Hamming distances of a given string A from substrings of length |A| of another string B

Given two binary strings a and b, find the sum of the Hamming distances between a and all contiguous substrings of b of length |a|. inputCopy: 01 00111 outputCopy: 3 Explanation: For the first sample case, there are four contiguous substrings of…
RAHUL
  • 54
  • 5
1
vote
1 answer

What data structure to represent clustered dots within a Hamming space?

I have a population of N chromosomes that can all be represented by binary strings of size L. N is typically of the size of 1e4 (plus or minus two orders of magnitude). L can vary a lot but can go up to 1e7. For the moment, I am recording all this…
Remi.b
  • 17,389
  • 28
  • 87
  • 168
1
vote
1 answer

Collapsing set of strings based on a given hamming distance

Given a set of strings (first column) along with counts (second column), e.g.: aaaa 10 aaab 5 abbb 3 cbbb 2 dbbb 1 cccc 8 Are there any algorithms or even implementations (ideally as a Unix executive, R or python) which collapse this set into a new…
1
vote
2 answers

XOR operation and BitCount in Java on Long variables returns java.lang.NumberFormatException

I am trying to do a XOR operation on two 64 bits Long variables in Java. The problem is that it fails when I add more than 16 bits in a variable. For instance this works and returns 7: Long h1 = Long.parseLong("1100001101001101"); Long h2 =…
c1377554
  • 173
  • 1
  • 10
1
vote
2 answers

Python: scipy/numpy all pairs computation between two 1-D vectors

I have two lists l1 and l2 containing integers that may be of different lengths, and I want to perform a computation between every possible pairing between these two vectors. Specifically, I'm checking the Hamming distance between each pair and if…
Filip Allberg
  • 3,941
  • 3
  • 20
  • 37
1
vote
1 answer

How to find the hamming distance for strings that are not necessarily equal length?

I have an assignment asking me to find the hamming distance of two user-input strings that are not necessarily equal in length. So, I made the following algorithm: Read both strings check the length of each string compare the length of the…
1
vote
0 answers

Fast circuit for popcount comparison

I'm designing a circuit that needs to check if the popcount (number of bit sets to 1) of two 16-bit vectors are equal. So what I need is to perform the operation logic[15:0] A,B; if (popcount(A) == popcount(B)) begin ... end (here popcount is…
1
vote
1 answer

Calculate Levenshtein/Hamming distance by grouping variable

I am trying to calculate the accuracy of participants' response (column MEM_Response) based on the correct response (columns MEM_Correct). The grouping variable would be the participant's ID (in this case column SERIAL--> 15 cases per…
1
vote
1 answer

Elasticsearch Aggregation with hamming distance of a phash

Trying to group together similar documents with matching keyword field values and phashes of their related images. At the moment I have the following which works well for exact matching phashes 'duplicate_docs': A('terms', …
1
vote
0 answers

Count numbers with Hamming distance less than or equal than given k from a given set of integers

I admit that this problem is part (although small) of school programming assignment, but I wasn't able to find much of a hint online and my solutions are very slow so far. Here is my problem defined more precisely: Given a vector of integers v and…
Karel Křesťan
  • 399
  • 2
  • 17
1
vote
1 answer

About Hamming and Manhattan priorities computation for 8 puzzle

http://coursera.cs.princeton.edu/algs4/assignments/8puzzle.html Is this Hamming and Manhattan priorities computation from the above link correct? For example, the Hamming and Manhattan priorities of the initial search node below are 5 and 10,…
tchappy ha
  • 185
  • 6
1
vote
0 answers

Subtract one image from another using JavaCV

I have been looking into the possibility of subtracting two images in Bytedeco/JavaCV. The objective is to perform what is suggested by Dat Chu for OpenCV but in JavaCV. Unfortunately, direct subtraction of Mat variables appears to be not…
Psi-Ed
  • 683
  • 1
  • 9
  • 22
1
vote
1 answer

Encoding for strings (preferrably a value) such that closer values means more similar Strings?

I am looking for an encoding which can encode every string into a unique number such that -> Every two strings which are similar must have values close to each other. Every two values which are close to each other must represent similar…
Prakhar Ganesh
  • 117
  • 2
  • 8
1
vote
2 answers

Calculate Hamming distance between strings of variable length in Matlab

I would like to calculate the Hamming distance between two strings of variable length in Matlab. For fixed length strings the following syntax solves my problem: str1 = 'abcde'; str2 = 'abedc'; sum(str1 ~= str2) ans = 2 How can I do this…
smonsays
  • 400
  • 2
  • 17
1
vote
1 answer

Can the hamming distance be used with non-binary strcuture

It is known that the hamming distance is applied to calculate the difference between two binary strings. Is it possible to apply it to calculate the difference between non-binary structures?
Nasser
  • 2,118
  • 6
  • 33
  • 56