1  function G = ulda(Data, Class)


2 


3  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


4  % Input: %


5  % Data: data matrix (Each row is a data point) %


6  % Class: class label (class 1, ..., k) %


7  % Output: %


8  % G: transformation matrix %


9  %%% Anirban Dutta


10  %%% adutta@northwestern.edu


11  %%% Creation date: 7/03/2010


12  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


13 


14  k = max(Class); % number of classes


15 


16  %


17  [m,n] = size(Data);


18  cc = sum(Data)/m;


19 


20  for i = 1:k


21  loc = find(Class==i);


22  [num,o] = size(loc);


23 


24  if num==1


25  B(loc,1:n) = 0;


26  B(m+i,1:n) = 0;


27  else


28  TMP = sum(Data(loc,1:n))/num;


29 


30  B(i,1:n) = sqrt(num)*(TMP  cc);


31  B(loc+k,1:n) = Data(loc,1:n)  ones(num,1)*TMP;


32  end;


33  end;


34 


35  Hw = B(k+1:k+m, :)';


36 


37  Hb = B(1:k, :)';


38 


39  Size_low = rank(Hb);


40 


41  Ht = (Data  ones(m,1)*cc)';


42 


43  [U1,D1,V1] = svd(Ht,0); % Ht = U1 D1 V1'


44  s = rank(Ht);


45 


46  D1 = D1(1:s, 1:s);


47  U1 = U1(:,1:s);


48 


49  d1 = diag(D1);


50  d1 = 1./d1;


51  D1 = diag(d1);


52 


53  B = D1*U1'*Hb;


54 


55  [P,D2, Q] = svd(B);


56 


57  X = U1*D1*P;


58 


59  G = X(:, 1:Size_low);


60 

