Compute centroid means (vectorized)
This commit is contained in:
parent
39b09f144a
commit
6c51a29ca2
1 changed files with 3 additions and 11 deletions
|
@ -27,17 +27,9 @@ centroids = zeros(K, n);
|
|||
%
|
||||
|
||||
for k = 1:K
|
||||
count = 0;
|
||||
|
||||
% XXX vectorize
|
||||
for i = 1:m
|
||||
if idx(i) == k
|
||||
centroids(k, :) += X(i, :);
|
||||
count += 1;
|
||||
end
|
||||
end
|
||||
if count > 0
|
||||
centroids(k, :) /= count;
|
||||
X_in_k = X(idx == k, :);
|
||||
if size(X_in_k, 1) > 0
|
||||
centroids(k, :) = sum(X_in_k)/size(X_in_k, 1);
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Reference in a new issue