Skip to content

Commit

Permalink
adding comments and fix the bugs according to the commend especially …
Browse files Browse the repository at this point in the history
…the dimensionality requirements for the input of these two files.
  • Loading branch information
lbl1985 committed Feb 5, 2012
1 parent e279f81 commit e8263e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
24 changes: 18 additions & 6 deletions svm/util/find_labels_dnc.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
%this function labels data with kmeans result in batches/blocks, useful for removing memory requirements

function labels = find_labels_dnc(center,X)
% center dimension should be fixed as n x d;
% X dimsnsion should be n x d
% However since X might be larget X might be n x d or d x n.

blksize = 1e5;
nr_desc = size(X, 1);

% X might be huge matrix. However, center is always relative small matrix
% if center dimension should be equal to X dimenstion.
isIdentical = isequal(size(center, 1), size(X, 1));
% since size(center, 2) is feature dimension
isIdentical = isequal(size(center, 2), size(X, 2));

if isIdentical
labels = zeros(size(X, 2), 1);
% X: n x d
nr_desc = size(X, 1);
labels = zeros(size(X, 1), 1);
else
labels = zeros(size(X, 1),1);
% X: d x n
nr_desc = size(X, 2);
labels = zeros(size(X, 2),1);
end

nr_calculated = 0;
Expand All @@ -21,11 +28,16 @@
head = nr_calculated+1;
tail = nr_calculated+nr_tocalc;
if isIdentical
% X: n x d
X_blk = X(head:tail, :);
else
% X: d x n
X_blk = X(:, head:tail);
X_blk = X_blk';
else
X_blk = X(head:tail,:);
end
% findvword input should be
% center: n x d
% X_blk: n x d
labels(head:tail) = findvword(center, X_blk);
nr_calculated = nr_calculated + nr_tocalc;
end
Expand Down
3 changes: 3 additions & 0 deletions svm/util/findvword.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
%quick wrapper for min Euclidean distance for kmeans labeling

function vword = findvword(vocab, X)
% Input:
% vocad: n x d
% X: n x d
% tic
center = vocab';
X = X';
Expand Down

0 comments on commit e8263e3

Please sign in to comment.