function [W2,Y2,idx2] = reorder_hf(W,Y)

% reorder W according to the labels in Y
% and form reordered Y2
% Y - np * k indicator matrix 
% np - number of points 
% k - number of classes

y = sum(Y,2);
idx = find(y==1);

Y2 = Y(idx,:);     % Y2 - nl * k matrix (nl is number of labels)

n = length(idx);
W2 = zeros(size(W));
W2(1:n,1:n) = W(idx,idx);           % reorder W

idx2 = [1:size(W,1)];
idx2(idx) = [];

W2(1:n,n+1:end) = W(idx,idx2);
W2(n+1:end,1:n) = W(idx2,idx);
W2(n+1:end,n+1:end) = W(idx2,idx2);


