Вы находитесь на странице: 1из 2

function [gauss,mtrx,ctrx1,ctrx] = Fold_n(training_data,test_data,cov_type )

% function [gauss,mtrx,ctrx1,ctrx] = Fold_n(training_data,test_data,cov_type )


% Function Fold_n (as Bayesian Classifier) take input as--
% training_data as cell array which contain training data as ce
ll array
% test_data as cell array which contain test data as cell array
% cov_type as 1,2,3 when cov_type==1
% Covariance type will be different for
each classes
% when cov_type==2
% Covariance type will be same for
% each classes(take cov for
% different classes and do average)
% when cov_type==3
% Covariance type will be same for
% each classes (take cov for whole
% training data)
n1=length(training_data);
n2=length(test_data);
Class=training_data{1};
for i=2:n1
Class(1:length(Class)+length(training_data{i}),:)=[Class;training_data{i}];
end
if(n1~=n2)
error('input data is not good enough');
end
ctrx=[0,0;0,0];
for i=1:n1
X=training_data{i};
mtrx(:,i)=(mean(X))';
ctrx1(:,:,i)=cov(X);
ctrx=ctrx+ctrx1(:,:,i);
end
if(cov_type==1)
for i=1:n1
gauss{i}=gauss_dis(mtrx(:,i),ctrx1(:,:,i));
end
elseif(cov_type==2)
ctrx=ctrx*(1/n1);
for i=1:n1
gauss{i}=gauss_dis(mtrx(:,i),ctrx);
end
elseif(cov_type==3)
ctrx=cov(Class);
for i=1:n1
gauss{i}=gauss_dis(mtrx(:,i),ctrx);
end
end
for j=1:n2
b=test_data{j};
b=b';
n=length(b);
for i=1:n2
x=gauss{i};
for k=1:n
d(i,k)=x(b(:,k));
end
end
[x1,y1]=max(d);
y{j}=y1;
end
for i=1:n2
for j=1:n2
x=y{i};
mvalue(i,j)=length(find(x==j))/length(x);
end
end
listx=DE_boundary1(training_data,test_data,gauss);
plot_boundary(listx,training_data,test_data);
DET3(test_data,gauss);
confusion_matrix(mvalue,n1);
end

Вам также может понравиться