12345678910111213141516 |
- function [affinity] = CalculateAffinity(data)
-
- % set the parameters
- sigma = 1;
- data = full(data);
- affinity = zeros(size(data,1), size(data,2));
- for i=1:size(data,1)
- for j=i:size(data,2)
- dist = sqrt(norm(data(i,:) - data(j,:)));
- %dist = sqrt((data(i,1) - data(j,1))^2 + (data(i,2) - data(j,2))^2);
- affinity(i,j) = dist;
- affinity(j,i) = affinity(i,j);
- end
- end
- affinity = exp(-affinity./(2*sigma^2));
- affinity = sparse(affinity);
|