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;
- % TODO compute clustering solution cost
- [n m] = size(points);
- [a b] = size(centroids);
- poz = zeros(n,1);
- for i = 1:n
- k = 1;
- dist_min = norm(points(i,:) - centroids(1,:));
- for j = 2:a
- dist = norm(points(i,:) - centroids(j,:));
- if (dist < dist_min)
- dist_min = dist;
- k = j;
- endif
- endfor
- poz(i) = k;
- endfor
- val = 1;
- while (val <= a)
- sum = 0;
- for m = 1:n
- if (val == poz(m))
- sum = sum + norm(points(m,:) - centroids(val,:));
- endif
- endfor
- cost = cost + sum;
- val = val + 1;
- endwhile
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement