1. 程式人生 > >代碼驗證ncut和譜聚類的系數

代碼驗證ncut和譜聚類的系數

mark div dia source nes pos cnblogs 驗證 rand

W = rand(30); W = W+W';
 
 I = cell(3,1);
 I{1} = 1:10; I{2} = 11:20; I{3} = 21:30;
 vol = -ones(3,1);
 for i = 1 : 3
     vol(i) = sum(sum(W(I{i},I{i})));
 end
 
 Ncut_value = 0;
 for i = 1 : 3
     for j = 1 : 3
         if j ~= i
             Ncut_value = Ncut_value + sum(sum(W(I{i},I{j})))/vol(i);
         end
     end
 end
 Ncut_value = Ncut_value/2
; H = zeros(3, 30); for i = 1 : 3 H(i,I{i}) = 1/sqrt(vol(i)); end L = diag(sum(W,2))-W; trace_value = sum(diag(H*L*H')); disp([Ncut_value, trace_value])

代碼驗證ncut和譜聚類的系數