[Home]

##### 2DBLDA

A Matlab code for "Two-dimensional Bhattacharyya bound linear discriminant analysis with its applications." (You could Right-Click [Code] , and Save, then you can download the whole matlab code.)

##### Reference

Guo Y R, Bai Y Q, Li C N. Two-dimensional Bhattacharyya bound linear discriminant analysis with its applications.

##### Main Function

function W = D2BLDA(X,Y) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Ref: "Two-dimensional Bhattacharyya bound linear discriminant analysis with its applications." % Input: % X - the samples; % Y - the labels corresponding to samples; % Ouput: % W:the project vectors; % Reference: % Guo Y R, Bai Y Q, Li C N. Two-dimensional Bhattacharyya bound linear discriminant analysis with its applications % % Version 2.0 -- 2021 % Written by Yan-Ru Guo %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% function begin .... %%%%%%%%%%初始化： c = length(unique(Y));[d1,~,N] = size(X);SW=zeros(d1,d1);SB=zeros(d1,d1);DeltaB = 0; %%%%%%%%%%%%计算类内Sw： for i=1:c SubclassIndex = find(Y==i); type(i) = length(SubclassIndex); SubData=X(:,:,SubclassIndex); meani(:,:,i)=mean(SubData,3); Swi=zeros(d1,d1); for j=1:type(i) Swi=Swi+(SubData(:,:,j)-meani(:,:,i))'*(SubData(:,:,j)-meani(:,:,i)); end SW=SW+Swi; end %%%%%%计算类间Sb及Delta： for i = 1:c for j = 1:c if i~=j DeltaB = DeltaB + sqrt(type(i)*type(j))/N*(meani(:,:,i)-meani(:,:,j))*(meani(:,:,i)-meani(:,:,j))'; SB=SB+sqrt(type(i)*type(j))/N*(meani(:,:,i)-meani(:,:,j))*(meani(:,:,i)-meani(:,:,j))'; end end end SB= -SB; Delta = DeltaB/4; S = SB+ Delta*SW; S = -S; S = (S+S')/2; [W,~] = eig(S); end