Implements means computation

This commit is contained in:
julien Lengrand-Lambert
2015-12-24 13:47:29 +01:00
parent 953ab45279
commit 1b4291cded
3 changed files with 17 additions and 9 deletions

View File

@@ -26,12 +26,20 @@ centroids = zeros(K, n);
% Note: You can use a for-loop over the centroids to compute this.
%
% this could be vectorized but today is Christmas and I have family talking
% loud everywhere around.
for i = 1:K
temp = [];
for j = 1:m
if idx(j) == i
temp = [temp; X(j, :)];
end
end
s = size(temp, 1);
centroids(i, :) = sum(temp)./s;
end
% =============================================================

View File

@@ -44,7 +44,7 @@ fprintf(' %d', idx(1:3));
fprintf('\n(the closest centroids should be 1, 3, 2 respectively)\n');
fprintf('Program paused. Press enter to continue.\n');
pause;
% pause;
%% ===================== Part 2: Compute Means =========================
% After implementing the closest centroids function, you should now
@@ -63,7 +63,7 @@ fprintf(' [ 5.813503 2.633656 ]\n');
fprintf(' [ 7.119387 3.616684 ]\n\n');
fprintf('Program paused. Press enter to continue.\n');
pause;
% pause;
%% =================== Part 3: K-Means Clustering ======================
@@ -93,7 +93,7 @@ initial_centroids = [3 3; 6 2; 8 5];
fprintf('\nK-Means Done.\n\n');
fprintf('Program paused. Press enter to continue.\n');
pause;
% pause;
%% ============= Part 4: K-Means Clustering on Pixels ===============
% In this exercise, you will use K-Means to compress an image. To do this,

Binary file not shown.