[Home]


2DCLDA

A Matlab code for Robust two-dimensional capped l2,1-norm linear discriminant analysis with regularization and its applications on face recognition(You could Right-Click [Code] , and Save, then you can download the whole matlab code.)


Reference

Chun-Na Li, Yi-Fan Qi, Yuan-Hai Shao, Yan-Ru Guo, Ya-Fen Ye "Robust two-dimensional capped l2,1-norm linear discriminant analysis with regularization and its applications on face recognition" Submitted 2020

Main Function

function [W] = D2CLDA(Data,FunPara,dim) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % Input: % Data.X: Data matrix. Each column vector of Data.X is a sample. % Data.Y: Data label vector. % FunPara.MaxIter: Maximum iteration number. % FunPara.epsilon: Parameter epsilon in capped l_{2,1}-norm. % FunPara.delta: 10^-5 % FunPara.Eta: 0 % FunPara.Cta: Parameter need choose % dim: reduced dimension. % % % % % Eample: % Data.X = rand(32,32,10); % Data.Y = ones(10,1); % FunPara.MaxIter = 50; % FunPara.epsilon = Autoregulation; % dim = 32; % [W] = D2CLDA(Data,FunPara,dim) % Reference: % "Robust two-dimensional capped l2,1-norm linear discriminant analysis with regularization and its applications on face recognition". % Chun-Na Li, Yi-Fan Qi, Yuan-Hai Shao, Yan-Ru Guo, Ya-Fen Ye % Version 1.0 -- Nov/2020 % Written by Yi-Fan Qi (yifanqicoco@163.com) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Eta = FunPara.Eta; Cta = FunPara.Cta; MaxIter = FunPara.MaxIter; epsilon1 = FunPara.epsilon; epsilon2 = FunPara.epsilon; delta = 10^-6; X = Data.trainX; Y = Data.trainY; [d1,d2,~] = size(X); label = unique(Y); c = length(label); N_i = zeros(c,1); X_mean = mean(X,3); W = eye(d1,dim); I = eye(d1,dim); %% A = []; D = []; for t = 1:MaxIter S1 = zeros(d1,d1); S2 = zeros(d1,d1); H_w = []; H_b = []; F = []; G = []; B = []; C = []; for h = 1:d2 H_h_b = []; H_h_w = []; G_h = []; F_h = []; for i = 1:c X_i_Index = find(Y==i); N_i = length(X_i_Index); X_i = X(:,:,X_i_Index); X_i_mean(:,:,i) = mean(X_i,3); H_h_i = N_i*(X_i_mean(:,h,i)-X_mean(:,h)); H_h_b = [H_h_b,H_h_i]; if norm(N_i*W'*(X_i_mean(:,h,i)-X_mean(:,h)),2) <= epsilon1 Ind_1(i) = 1; else Ind_1(i) = 0; end B = [B,norm(N_i*W'*(X_i_mean(:,h,i)-X_mean(:,h)),2)]; G_h_i = Ind_1(i)/(norm(N_i*W'*(X_i_mean(:,h,i)-X_mean(:,h)),2) + delta); G_h = [G_h,G_h_i]; for s = 1:N_i if norm(W'*(X_i(:,h,s)-X_i_mean(:,h,i)),2) <= epsilon2 Ind_2(s) = 1; else Ind_2(s) = 0; end C = [C,norm(W'*(X_i(:,h,s)-X_i_mean(:,h,i)),2)]; F_h_is = Ind_2(s)/(norm(W'*(X_i(:,h,s)-X_i_mean(:,h,i)),2) + delta); F_h = [F_h,F_h_is]; H_h_is = X_i(:,h,s)-X_i_mean(:,h,i); H_h_w = [H_h_w,H_h_is]; end end F_h = F_h'; G_h = G_h'; F = [F,F_h']; G = [G,G_h']; H_w = [H_w,H_h_w]; H_b = [H_b,H_h_b]; end F = diag(F); G = diag(G); S1 = H_w*F*H_w'+Eta*I; S2 = H_b*G*H_b'+Cta*I; % if t > 1 % D = [D,abs(norm(S) - norm(S1))]; % end % S = S1; %% [W_best,D] = eig(S1,S2); % W_best = orth(W_best); D = diag(D); eigIdx1 = find(D < 1e-5); eigIdx = [eigIdx1]; D(eigIdx) = []; W_best(:,eigIdx) = []; [~, index] = sort(D); W_best = W_best(:,index); D = D(index); W_best = W_best(:,1:min(dim,length(index))); if t > 5 if abs(norm(W) - norm(W_best)) == 0 W = W_best; break; end end W = W_best; B = sort(B); C = sort(C); epsilon1 = B(:,round(length(B)*0.9)); epsilon2 = C(:,round(length(C)*0.9)); % A = [A,W(:,1)]; t = t + 1; end
Contacts


Any question or advice please email to na1013na@163.com or yifanqicoco@163.com