www.pudn.com > LBG_GA.rar > all_dist.m, change:2011-06-15,size:1261b


function DIST=all_dist(x,y) 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% %此函数计算训练矢量与码本码本的总畸变(每个训练矢量与每个码字的欧氏距离的加和的加和) 
% %x为训练矢量12*318;y为码本12*32 
% x=randn(12,318);y=randn(12,32); 
% m=size(x,2); 
% n=size(x,1); 
% l=size(y,2); 
% dis_sum=0; 
% dis_sum_1=0; 
% Dis_sum_1=[]; 
% %m=318 n=12 l=32 
% for i=1:l 
%     for j=1:m 
%         for k=1:n 
%         dis(k,j)=(y(k,i)-x(k,j))^2;   %计算欧氏距离 
%         dis_sum=dis_sum+dis(k,j); 
%         end 
%         Dis_sum(j)=dis_sum/n; 
%         dis_sum_1=dis_sum_1+Dis_sum(j); 
%     end 
%         Dis(i)=dis_sum_1/m; 
% end 
% dist=sum(Dis)/l; 
% DIST=dist; 
% clear i j k; 
% end 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%该程序为适应度函数为训练矢量与每个码字的欧氏距离,取距离最小的,然后加和取平均 
m=size(x,2); 
l=size(y,2); 
n=size(x,1); 
dis=zeros(l,n); 
dis_1=zeros(1,l); 
dis_min=zeros(1,m); 
dist=0; 
for i=1:m 
    for j=1:l 
%         dis(:,j)=(x(:,i)-y(:,j)).^2; 
        for k=1:n 
            dis(k,j)=(x(k,i)-y(k,j))^2; 
        end 
        dis_1(j)=sum(dis(:,j),1)/n; 
    end 
    dis_min(i)=min(dis_1); 
end 
dist=sum(dis_min)/m; 
DIST=dist; 
 
clear i j k; 
 
end