资源描述:
《ICA人脸识别算法实例matlab源码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ICA人脸识别算法实例matlab源码.txt32因为爱心,流浪的人们才能重返家园;因为爱心,疲惫的灵魂才能活力如初。渴望爱心,如同星光渴望彼此辉映;渴望爱心,如同世纪之歌渴望永远被唱下去。%%%%%%%%%%%%%%%%%%%%%%%%%%初始化%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clc;clearall;closeall;%%%%%%%%%%%%%%读入原始图像,混合,并输出混合图像%%%%%%%%%%%%%%%%%%%读入混合前的原始图片并显示t=0:1/100:9;I1=sin(t);I2=
2、randn(1,901);I3=square(4*t);subplot(4,3,1),plot(I1),title('输入信号1'),subplot(4,3,2),plot(I2),title('输入信号2'),subplot(4,3,3),plot(I3),title('输入信号3'),%将其组成矩阵S=[I1;I2;I3];%图片个数即为变量数,图片的像素数即为采样数%因此S_all是一个变量个数*采样个数的矩阵Sweight=randn(size(S,1));%取一随机矩阵,作为信号混合的权矩阵MixedS=Sweight*
3、S;%得到三个混合信号矩阵%将混合矩阵重新排列并输出subplot(4,3,4),plot(MixedS(1,:)),title('混合信号1'),subplot(4,3,5),plot(MixedS(2,:)),title('混合信号2'),subplot(4,3,6),plot(MixedS(3,:)),title('混合信号3'),MixedS_bak=MixedS;%将混合后的数据备份,以便在恢复时直接调用%%%%%%%%%%%%%%%%%%%%%%%%%%标准化%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4、%%%%MixedS_mean=zeros(3,1);fori=1:3MixedS_mean(i)=mean(MixedS(i,:));end%计算MixedS的均值fori=1:3forj=1:size(MixedS,2)MixedS(i,j)=MixedS(i,j)-MixedS_mean(i);endend%%%%%%%%%%%%%%%%%%%%%%%%%%%白化%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MixedS_cov=cov(MixedS');%cov为求协方差的函数[E,D]=eig(
5、MixedS_cov);%对图片矩阵的协方差函数进行特征值分解Q=inv(sqrt(D))*(E)';%Q为白化矩阵MixedS_white=Q*MixedS;%MixedS_white为白化后的图片矩阵IsI=cov(MixedS_white');%IsI应为单位阵%%%%%%%%%%%%%%%%%%%%%%%% FASTICA算法%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%X=MixedS_white;%以下算法将对X进行操作[VariableNum,SampleNum]=size(X);numof
6、IC=VariableNum;%在此应用中,独立元个数等于变量个数B=zeros(numofIC,VariableNum);%初始化列向量w的寄存矩阵,B=[b1b2...bd]forr=1:numofIC%迭代求取每一个独立元i=1;maxIterationsNum=100;%设置最大迭代次数(即对于每个独立分量而言迭代均不超过此次数)IterationsNum=0;b=rand(numofIC,1)-.5;%随机设置b初值b=b/norm(b);%对b标准化whilei<=maxIterationsNum+1ifi==maxI
7、terationsNum%循环结束处理fprintf('第%d分量在%d次迭代内并不收敛。',r,maxIterationsNum);break;endbOld=b;a2=1;u=1;t=X'*b;g=(exp(2.*t)-1)./(exp(2.*t)+1);dg=4*exp(2.*t)./(exp(2.*t)+1).^2;b=((1-u)*t'*g*b+u*X*g)/SampleNum-mean(dg)*b;%核心公式,参见理论部分公式2.52b=b-B*B'*b;%对b正交化b=b/norm(b);ifabs(abs(b'
8、*bOld)-1)<1e-9%如果收敛,则保存bB(:,r)=b;break;endi=i+1;endend%%%%%%%%%%%%%%%%%%%%%%%%%数据复原并构图%%%%%%%%%%%%%%%%%%%%%%%%ICAedS=B'*Q*Mi