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


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
function [adapt,best_pos]=adapting(x,pop,k,p) 
% function adapt=adapting(x,pop) 
%计算种群的适应度值 
%其中x为特征矢量12*318,pop为初始码本50*384 
global gen 
Dim=p; 
M=size(pop,1); 
N=size(x,1); 
after_transfer=zeros(N,k);%12*32 
Dist=zeros(1,M); 
adapt=zeros(1,M); 
C=5000; 
for i=1:M 
    after_transfer=transfer_mat(pop(i,:),k,Dim); 
    %计算总畸变作为适应度值 
    Dist(i)=all_dist(x,after_transfer); 
    adapt(i)=C-Dist(i); 
end 
[ff,index]=sort(adapt); 
best_pos=index(M); 
 
clear i; 
clear j; 
 
% adapt_ave(gen)=adapt_ave(gen)/40; 
% plot(adapt_ave) 
 
end