Skip to content

# dcsommer/CS229-Final-Project

Produced k vs gmeans metric avg over all clusters

• Loading branch information...
1 parent d2c70f9 commit 7f32489f9d297faa2319ab1d8192fb28c4b3ba72 committed Dec 13, 2011
Showing with 11 additions and 8 deletions.
1. +10 −6 gmeans_cluster.m
2. poster/images/gmeans_k_vs_metric.png
3. +1 −2 runall.m
16 gmeans_cluster.m
 @@ -1,13 +1,15 @@ -function [CenterIds, Centers] = gmeans_cluster(features, crit, maxClusters) +function [CenterIds, Centers, ks, means] = gmeans_cluster(features, crit, maxClusters) oldk = 1; k = 16; fprintf('Initial cluster with %d centers\n', k); [CenterIds, Centers] = kmeans(features, k); +a=1; while oldk ~= k && k < maxClusters oldk = k; + A2SZ = zeros(size(Centers,1), 1); for i=1:size(Centers,1) - fprintf('checking center %d of %d\n', i, size(Centers,1)) + %fprintf('checking center %d of %d\n', i, size(Centers,1)) is = features(CenterIds == i,:); if (size(is, 1) < 2) continue; @@ -26,12 +28,14 @@ sum = sum + (2*j - 1)*(log(Z(j)) + log(1 - Z(n+1-j))); end A2Z = -n - sum/n; - A2SZ = A2Z*(1 + 4/n - 25/n^2) - n - if A2SZ > crit + A2SZ(i) = A2Z*(1 + 4/n - 25/n^2); + if A2SZ(i) > crit k = k+1; % reject null hypothesis, there should be 2 clusters end end - fprintf('reclustering with %d centers\n', k) + ks(a) = k; + means(a) = mean(A2SZ); + fprintf( 'reclustering with %d centers\n', k) [CenterIds, Centers] = kmeans(features, k); + a = a+1; end
BIN poster/images/gmeans_k_vs_metric.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 runall.m
 @@ -25,5 +25,4 @@ %reduced_features = polyfit(features, REDUCED_DIMENSION,30); disp '-----Clustering-----' -[CenterIds, Centers] = gmeans_cluster(reduced_features, GMEANS_CRIT, MAX_CLUSTERS); - +[CenterIds, Centers] = gmeans_cluster(reduced_features, GMEANS_CRIT, MAX_CLUSTERS);

#### 0 comments on commit `7f32489`

Please sign in to comment.
Something went wrong with that request. Please try again.