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
7
votes
4 answers

Hamming distance between two binary strings not working

I found an interesting algorithm to calculate hamming distance on this site: def hamming2(x,y): """Calculate the Hamming distance between two bit strings""" assert len(x) == len(y) count,z = 0,x^y while z: count += 1 …
Hyperion
  • 2,515
  • 11
  • 37
  • 59
7
votes
2 answers

Performance discrepancy in compiled vs. hand-written assembly

I've been playing around with using assembly language in Go and I've written a Hamming Weight function as an excercise. I've based a native Go version on this SO answer and the assembly version is based on this doc from AMD (page 180). Upon…
Intermernet
  • 18,604
  • 4
  • 49
  • 61
7
votes
4 answers

Finding Minimum hamming distance of a set of strings in python

I have a set of n (~1000000) strings (DNA sequences) stored in a list trans. I have to find the minimum hamming distance of all sequences in the list. I implemented a naive brute force algorithm, which has been running for more than a day and has…
Devil
  • 903
  • 2
  • 13
  • 21
6
votes
2 answers

Python - How to generate the Pairwise Hamming Distance Matrix

beginner with Python here. So I'm having trouble trying to calculate the resulting binary pairwise hammington distance matrix between the rows of an input matrix using only the numpy library. I'm supposed to avoid loops and use vectorization. If…
user2444400
  • 139
  • 5
  • 14
6
votes
1 answer

Getting all string combinations by given maximal Hamming distance (number of mismatches) in Java

Is there an algorithm go generate all possible string combinations of a string (DNA Sequence) by a given number of maximal allowed positions that can variate (maximal Mismatches, maximal Hamming distance)? The alphabet is {A,C,T,G}. Example for a…
6
votes
3 answers

Hamming Distance optimization for MySQL or PostgreSQL?

I trying to improve search similar images pHashed in MySQL database. Right now I comparing pHash counting hamming distance like this: SELECT * FROM images WHERE BIT_COUNT(hash ^ 2028359052535108275) <= 4 Results for selecting (engine MyISAM) 20000…
mateuszdw
  • 61
  • 1
  • 8
6
votes
3 answers

Finding hamming distance of code

A question asks: find the hamming distance of the following code: 11111 10101 01010 11100 00011 11001 The answer is 2. How does this work? I thought hamming distance is only between two strings?
Celeritas
  • 14,489
  • 36
  • 113
  • 194
5
votes
4 answers

Finding twelve 32-bit numbers with at least 17 bit differences between pairs

Find twelve 32-bit numbers such that each pair of them differs by bits in at least 17 positions. I'm struggling to find and optimal algorithm for this problem. More general question is: Find 'n' 32-bit numbers such that each pair of them differs by…
5
votes
3 answers

How can I calculate the difference between two hashes in a MySQL query?

I'm attempting to calculate the Hamming distance between an input hash and database-stored hashes. These are perceptual hashes, so the Hamming distance between them are important to me and tell me how similar two different images are (see…
jeremy
  • 9,965
  • 4
  • 39
  • 59
5
votes
3 answers

bit_count function in PostgreSQL

We are in the process of migrating a MySQL 5.7 database to PostgreSQL 9.6. A real issue is the lack of bit_count function in PostgreSQL. This function is also not available in the upcoming version 10. Current MySQL code snippet (simplified): --…
rmuller
  • 12,062
  • 4
  • 64
  • 92
5
votes
1 answer

Gradient calculation in Hamming loss for multi-label classification

I am doing a multilabel classification using some recurrent neural network structure. My question is about the loss function: my output will be vectors of true/false (1/0) values to indicate each label's class. Many resources said the Hamming loss…
5
votes
3 answers

Checking the error detection capabilities of CRC polynomials

I tried to find out how to calculate the error detection capabilities of arbitrary CRC polynomials. I know that there are various error detection capabilities that may (or may not) apply to an arbitrary polynomial: Detection of a single bit…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
5
votes
1 answer

Algorithm to test minimum hamming distance against a set?

I have a relative straightforward thing I want to do: Given a query number Q, a query distance d, and a set of numbers S, determine whether or not S contains any numbers with Hamming distance less than or equal to d. The simplest solution is to…
Timothy Miller
  • 1,527
  • 4
  • 28
  • 48
5
votes
2 answers

generating numbers, with high hamming distance

I am looking for a fast way to generate k non-negative integers smaller than 2^64, of which, in base 2, the minimal Hamming distance between any two of the numbers is as high as possible. For example, if I were looking for k=4 numbers and they…
Leon
  • 2,926
  • 1
  • 25
  • 34
5
votes
2 answers

Counting Hamming Distance for 8-bit binary Values in C Language

I write a new program that compares 2 two digit unsigned integer. Compares by hamming distances. But my algorithm doesn't work perfectly. Can yo tell me what is wrong with this code :( THANKS A LOT!! this is my counting method; int…
Gökhan Nas
  • 213
  • 2
  • 5
  • 12
1 2
3
19 20