%ksomforspeech.m
clear all
close all
load TRAINLPC
s=[];
for i=1:1:3
s=[s size(TRAINLPC{i},1)];
end
mx=min(s);
DATA=[];
for i=1:1:3
DATA=[DATA TRAINLPC{i}(1:1:mx,:)];
end
[E,D]=eigs(cov(DATA'),14);
DATA=E'*DATA;
ma=max(max(abs(DATA)));
DATA=DATA/ma;
N=10;
W=rand(size(DATA,1),N);
k=2;
c=0.1;
eta=0.1;
for iteration1=1:1:20
eta=eta*0.1;
for iteration2=1:1:200
for i=1:1:size(DATA,2);
D=sum((repmat(DATA(:,i),1,N)-W).^2);
[P,Q]=min(D);
l=Q-k:1:Q+k;
[P1,Q1]=find(l>0);
index=l(Q1);
G=exp(-c*(k-index).^2);
for j=1:1:length(index)
W(:,j)=W(:,j)+eta*G(j)*(DATA(:,i)-W(:,j) );
end
end
end
end
%Verification using training data
COLTRAIN=[];
for i=1:1:size(DATA,2);
D=sum((repmat(DATA(:,i),1,N)-W).^2);
[P,Q]=min(D);
COLTRAIN=[COLTRAIN Q];
end
load TESTLPC
s=[];
for i=1:1:3
s=[s size(TESTLPC{i},1)];
end
DATA=[];
for i=1:1:3
DATA=[DATA TESTLPC{i}(1:1:mx,:)];
end
DATA=E'*DATA;
DATA=DATA/ma;
COLTEST=[];
for i=1:1:size(DATA,2);
D=sum((repmat(DATA(:,i),1,N)-W).^2);
[P,Q]=min(D);
COLTEST=[COLTEST Q];
end