function [model, B, elapse] = LSH_learn(X, maxbits)
% LSH_learn: Training process in Locality Sensitive Hashing
%
% [model, B, elapse] = LSH_learn(X, maxbits)
%
% Input:
% X - Data matrix. Each row vector of data is a sample vector. The data should be normalized and centralized to have zero mean before.
% maxbits - Code length of hash codes
%
% Output:
% model - Struct value in Matlab. The field in model is:
% U - The matrix record the random projection vectors
% B - The binary codes for data points
% elapse - The training time
%
% Examples:
%
% load('Flickr1M');
% [model, TrainCode, TrainTime] = LSH_learn(fTrain, 32);
%
% Reference:
% M. Charikar. "Similarity estimation techniques from rounding algorithms". In STOC, pages 380-388, 2002.
%
% version 1.0 -- Feb/2012
%
% Written by Yue Lin (linyue29@gmail.com)
tmp_T = tic;
[Nsamples, Nfeatures] = size(X);
U = normrnd(0, 1, Nfeatures, maxbits);
Z = X * U;
B = (Z > 0);
model.U = U;
elapse = toc(tmp_T);
end