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

下载本文档

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

文档简介

1、以下是LDA的m文件函数: 你稍稍改改就能用了!fun cti on eigvector, eigvalue, elapse = LDA(g nd,opti on s,data) % LDA: Lin ear Discrim inant An alysis%(aXWXa)/(aXXa+ReguAlpha*l)%SVD%Valid%0.1.%regularizati on%matrix%provided%nFea is%eigvector, eigvalue = LDA(gnd, options, data)In put: data gnd-Data matrix. Each row vecto

2、r of fea is a data point. -Colunm vector of the label in formatio n for each data point.options - Struct value in Matlab. The fields in optionsthat can be set:ReguReguAlpha -ReguTyperegularizerRFisherface1: regularized soluti on, a* = argmax0: solve the sinu larity problem byDefault: 0The regulariza

3、ti on parameter.whe n Regu=1. Default value isRidge: Tikh onovCustom: User provided regularizati onDefault: Ridge(nFea x nF ea) regularizati on matrix which should beif ReguType is Custom.the feature nu mber of data matrix1: Fisherface approachPCARatioPCARatio = n Smp -Default: 0The perce ntage ofco

4、mp onent kept in thestep. 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 PCAwill keep exactlycomp onents (does notexact nu mber of non-zeroOutput:eigvector - Each colu mn is an embedd ing function, for adat

5、a point (row vector) x, y = x*eigvector will be the embedd ing result of x.-The sorted eigvalue of LDA eige n-problem.-Time spe nt on differe nt stepseigvalue elapsefea = 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

6、 = LDA(gnd, options, fea);Y = fea*eigvector;%n Class%prin cipal%PCA%step%PCARatio prin ciple%exceed the%comp onen ts).%new%Examples:% See also LPP, con structW, LGE%Refere nee:% P. N. Belhumeur, J. P. Hespanha, and D. J. Kriegman,揈 igenfaces% vs. fisherfaces: recog niti on using class specific lin e

7、ar%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%De ng Cai, Xiaofei He, Jiawei Han, SRDA: An

8、Efficie nt Algorithm for%Large Scale Discrim inant An alysis, IEEE Tran sact ions on Kno wledgeand%Data Engin eeri ng, 2007.%version 2.1 -Ju ne/2007%version 2.0 -May/2007%version 1.1 -Feb/2006%version 1.0 -April/2004% Writte n by Deng Cai (de ngcai2 AT )%if exist(data,var)global data;endi

9、f (exist(optio ns,var)optio ns =;endif isfield(options,Regu) | options.RegubPCA = 1;if isfield(optio ns,卩 CARatio)optio ns.PCARatio = 1;endelsebPCA = 0;if isfield(opti on s,ReguType)opti on s.ReguType = Ridge;endif isfield(opti on s,ReguAlpha)opti on s.ReguAlpha = 0.1; endendtmp_T = cputime;% = In i

10、tializati 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.Fisherface opti on s.PCARatio = n Smp - n Class;endif issparse(data)data = ful

11、l(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;endend%=% SVD%=if bPCAif n Smp nFeaddata = data*data;ddata = max(

12、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_PCA(1:idx);eigvector_PCA = eigvector_PCA(:,1:

13、idx);endelseif optio ns.PCARatio = sumEigbreak;endendeigvalue_PCA = eigvalue_PCA(1:idx);eigvector_PCA = eigvector_PCA(:,1:idx);end %=eigvalue_PCA = eigvalue_PCA.A-.5;data = (data*eigvector_PCA).*repmat(eigvalue_PCA, nSmp,1); elseddata = data*data;ddata = max(ddata,ddata);eigvector, eigvalue_PCA = ei

14、g(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 options.PCARatio = sumEigbreak;endendeigva

15、lue_PCA = eigvalue_PCA(1:idx); eigvector = eigvector(:,1:idx);end%=eigvalue_PCA = eigvalue_PCA.A-.5;eigvector_PCA = (data*eigvector).*repmat(eigvalue_PCA, nF ea,1);data = eigvector;clear eigvector;end elseif bCholDPrime = data*data;%opti on s.ReguAlpha = n Smp*opti on s.ReguAlpha;switch lower(optio

16、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;otherwise error(ReguType does not exist!

17、); 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 = cputime - tmp_T;tmp_T = cputime;if bPC

18、AdumpVec,eigvalue,eigvector = svd(Hb,ec on);eigvalue = diag(eigvalue); eigldx = 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 = struct(disp,0);

温馨提示

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

评论

0/150

提交评论