Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % computes a clustering solution total cost
- function cost = compute_cost_pc(points, centroids)
- cost = 0;
- [m n] = size(points);
- [NC c] = size(centroids);
- assigned_centroid = zeros(m,1);
- cost_clustere = zeros(NC,1);
- for i = 1:m
- dist_minima = 10000;
- for j = 1:NC
- dist = norm(points(i,:) - centroids(j,:));
- if dist < dist_minima
- dist_minima = dist;
- centroid_asociat = j;
- endif
- endfor
- assigned_centroid(i) = centroid_asociat;
- endfor
- for j = 1:NC
- cost_clustere(j) = 0;
- for i = 1:m
- if assigned_centroid(i) == j
- dist = norm(points(i,:) - centroids(j,:));
- cost_clustere(j) = cost_clustere(j) + dist;
- endif
- endfor
- cost = cost + cost_clustere(j);
- endfor
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement