LDA人脸识别地matlab程序_第1页
LDA人脸识别地matlab程序_第2页
LDA人脸识别地matlab程序_第3页
LDA人脸识别地matlab程序_第4页
LDA人脸识别地matlab程序_第5页
已阅读5页,还剩14页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实用文案LDA人脸识别的matlab 程序以下是LDA的m文件函数:你稍稍改改就能用了!fun cti on eigvector, eigvalue, elapse = LDA(g nd,opti on s,data)% LDA: Lin ear Discrim inant An alysis%eigvector, eigvalue = LDA(g nd, opti ons, data)标准文档% point.%each%In put:data - Data matrix. Each row vector of fea is a datagnd - Colu nm vector of the

2、label in formatio n fordata point.options - Struct value in Matlab. The fields in optionsthat can be set:Regu -1: regularized soluti on,a* = argmax(aXWXa)/(aXXa+ReguAlpha*l)%0: solve the sinu larity problemby SVD%Default: 0%ReguAlpha -The regularizati on parameter.Valid%whe n Regu=1. Default valueis

3、 0.1.%ReguType - Ridge: Tikh onovregularizati on%Custom: User provided%regularizati onmatrix%Default: Ridge%regularizerR -(nFea x nF ea)regularizati on%matrix which should beprovided%if ReguType is Custom.nFea is%the feature nu mber ofdata%matrix%Fisherface-1: Fisherface approach%PCARatio = n Smp -n

4、 Class%Default: 0%PCARatio- The perce ntage ofprin cipal%comp onent kept in thePCA%step. The perce ntage is%calculated based on the%eige nv alue. Default is 1%(100%, all the non-zero%eige nv alues will be kept.%If PCARatio 1, the PCAstep%will keep exactlyPCARatio prin ciple%comp onents (does notexce

5、ed the%exact nu mber ofnon-zero comp onen ts).%Output:%eigvector -Each colu mn is an embedd ing function, fora new%data point (row vector) x,y = x*eigvector%will be the embedd ing result of x.%eigvalue-The sorted eigvalue of LDA eige n-problem.%elapse-Time spe nt on differe nt steps%Examples:%fea =

6、ran d(50,70);%gnd = on es(10,1);o nes(15,1)*2;o nes(10,1)*3;o nes(15,1)*4;%opti ons =;%opti on s.Fisherface =1;%eigvector, eigvalue=LDA(gnd, options, fea);%Y = fea*eigvector;% See also LPP, con structW, LGE%Refere nee:% P. N. Belhumeur, J. P. Hespanha, and D. J. Kriegman, 揈 igenfaces%vs. fisherfaces

7、: recog niti on using class specific lin ear% projection, ? IEEE Transactions on Pattern Analysis and Machine%Intelligenee, vol. 19, no. 7, pp. 711-720, July 1997.% Deng Cai, Xiaofei He, Yuxiao Hu, Jiawei Han, and Thomas Hua ng,%Lear ning a Spatially Smooth Subspace for Face Recog niti on,CVPR2007%D

8、e ng Cai, Xiaofei He, Jiawei Han, SRDA: An Efficie nt Algorithm for%Large Scale Discrim inant An alysis, IEEE Tran sact ions on Kno wledgeand% Data Engin eeri ng, 2007.%实用文案%version2.1-Ju ne/2007%version2.0-May/2007%version1.1-Feb/2006%version1.0-April/2004%Writte n by Deng Cai (de ngcai2 AT cs.uiuc

9、.edu)%if exist(data,var) global data;endif (exist(optio ns,var) optio ns =;endif isfield(options,Regu) | options.Regu bPCA = 1;if isfield(optio ns,卩 CARatio)optio ns.PCARatio = 1;elseend标准文档实用文案bPCA = 0;if isfield(opti on s,ReguType)opti on s.ReguType = Ridge;endif isfield(opti on s,ReguAlpha)opti o

10、n s.ReguAlpha = 0.1;endendtmp_T = cputime;% = In itializati onn Smp ,nF ea = size(data);if len gth(g nd) = n Smperror(g nd and data mismatch!);endclassLabel = uniq ue(g nd);n Class = len gth(classLabel);Dim = n Class - 1;if bPCA & isfield(optio ns,Fisherface) & opti on s.Fisherfaceopti on s.PCARatio

11、 = n Smp - n Class;endif issparse(data)data = full(data);endsampleMea n = mean( data,1);data = (data - repmat(sampleMea n,n Smp,1);bChol = 0;if bPCA & (n Smp nFea+1) & (optio ns.PCARatio = 1)DPrime = data*data;DPrime = max(DPrimeQPrime);R,p = chol(DPrime);if p = 0bPCA = 0;bChol = 1;end%=% SVD%=if bP

12、CAif n Smp nFeaddata = data*data;ddata = max(ddata,ddata);eigvector_PCA, eigvalue_PCA = eig(ddata); eigvalue_PCA = diag(eigvalue_PCA);clear ddata;maxEigValue = max(abs(eigvalue_PCA);eigIdx = fin d(eigvalue_PCA/maxEigValue 1idx = optio ns.PCARatio;if idx le ngth(eigvalue_PCA)eigvalue_PCA = eigvalue_P

13、CA(1:idx); eigvector_PCA = eigvector_PCA(:,1:idx); endelseif options.PCARatio = sumEig break;endendeigvalue_PCA = eigvalue_PCA(1:idx); eigvector_PCA = eigvector_PCA(:,1:idx);%= eigvalue_PCA = eigvalue_PCA4-.5;elsedata = (data*eigvector_PCA).*repmat(eigvalue_PCA, nSmp,1); ddata = data*data;ddata = ma

14、x(ddata,ddata);eigvector, eigvalue_PCA = eig(ddata);eigvalue_PCA = diag(eigvalue_PCA);clear ddata;maxEigValue = max(eigvalue_PCA);eigIdx = fin d(eigvalue_PCA/maxEigValue 1idx = optio ns.PCARatio;if idx le ngth(eigvalue_PCA)eigvalue_PCA = eigvalue_PCA(1:idx); eigvector = eigvector(:,1:idx);endelseif

15、options.PCARatio = sumEig break;endendeigvalue_PCA = eigvalue_PCA(1:idx); eigvector = eigvector(:,1:idx);end%= eigvalue_PCA = eigvalue_PCA4-.5;eigvector_PCA =(data*eigvector).*repmat(eigvalue_PCA, nF ea,1);data = eigvector;clear eigvector;endelseif bCholDPrime = data*data;%opti on s.ReguAlpha = n Sm

16、p*opti on s.ReguAlpha;switch lower(optio ns.ReguType)case lower(Ridge)for i=1:size(DPrime,1)DPrime(i,i) = DPrime(i,i) + opti on s.ReguAlpha;endcase lower(Te nsor)DPrime = DPrime +opti on s.ReguAlpha*opti on s.regularizerR;case lower(Custom)DPrime = DPrime +opti on s.ReguAlpha*opti on s.regularizerR;

17、otherwiseerror(ReguType does not exist!); endDPrime = max(DPrime,DPrime);endendn Smp ,nF ea = size(data);Hb = zeros( nClass, nF ea);for i = 1:n Class,in dex = fin d(g nd=classLabel(i);classMea n = mea n(data(i ndex,:),1);Hb (i,:) = sqrt(le ngth(i ndex)*classMea n;endelapse.timeW = 0;elapse.timePCA =

18、 cputime - tmp_T;tmp_T = cputime;if bPCAdumpVec,eigvalue,eigvector = svd(Hb,ec on);eigvalue = diag(eigvalue);eigIdx = fin d(eigvalue dimMatrixDim = dimMatrix;endif isfield(opti on s,bEigs)if opti on s.bEigsbEigs = 1;elsebEigs = 0;endelseif (dimMatrix 1000 & Dim 500& Dim 250 & Dim dimMatrix/30)bEigs = 1;elsebEigs = 0;endendif bEigs%disp(use eigs to speed up!);opti on = struc

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论