forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
function [label, mu] = litekmeans(X, k) | ||
n = size(X,2); | ||
last = zeros(1,n); | ||
label = ceil(k*rand(1,n)); | ||
function [label, mu] = litekmeans(X, label) | ||
idx = 1:size(X,2); | ||
last = idx; | ||
while any(label ~= last) | ||
[~,~,last(:)] = unique(label); % remove empty clusters | ||
mu = X*normalize(sparse(1:n,last,1),1); % compute cluster centers | ||
mu = X*normalize(sparse(idx,last,1),1); % compute cluster centers | ||
[~,label] = min(dot(mu,mu,1)'/2-mu'*X,[],1); % assign sample labels | ||
end | ||
% Perform kmeans clustering. | ||
% Input: | ||
% X: d x n data matrix | ||
% k: number of clusters | ||
% label: initial sample labels | ||
% Output: | ||
% label: 1 x n cluster label | ||
% label: 1 x n sample label | ||
% mu: d x k center of clusters | ||
% Written by Mo Chen ([email protected]). |