Created
August 14, 2012 19:31
-
-
Save grapeot/3352014 to your computer and use it in GitHub Desktop.
Inuitive example for LSH with toy data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Inuitive example for LSH with toy data | |
| dimension = 30; | |
| sampleNum = 1000; | |
| hashBitCount = 16; | |
| x = rand(sampleNum, dimension); % data points to hash | |
| w = rand(dimension, hashBitCount); % w vector in hash function | |
| w = w ./ repmat(sqrt(diag(w' * w)'), dimension, 1); % normalization | |
| projection = x * w; % Do the projection | |
| t = median(projection); % empirically provides good result | |
| hashCode = sign(x * w - repmat(t, sampleNum, 1)); % replace x with test data in test phase | |
| % Now we have hash codes as binary vectors in the matrix | |
| compactCode = sum((hashCode + 1) / 2 .* repmat(2 .^ [0:hashBitCount-1], sampleNum, 1), 2); % (hashCode + 1) / 2 maps 1 to 1, -1 to 0. | |
| % Now we have compact hash codes as integers in the vector | |
| % You can also use bi2de if having communication toolbox installed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment