版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 云南省文山壮族苗族自治州(2024年-2025年小学五年级语文)人教版期末考试(下学期)试卷及答案
- 工程制图教案创新:2024年的机遇与挑战
- 教育技术驱动:2024年《登上企鹅岛》课件的革新
- 《曾子杀猪》课件
- 新版2024年安全教育培训记录表设计与应用
- 2024年企业ERP采购流程重构培训
- 第47届世界技能大赛江苏省选拔赛网络系统管理项目技术文件V1.1
- 2024年XX企业社会责任与企业文化
- 2020盲盒经济洞察报告
- 《高科技智能住宅》课件
- 乐理知识考试题库130题(含答案)
- 人教版(2024)七年级地理上册2.2《地形图的判读》精美课件
- 2024年共青团入团积极分子团校结业考试试题库及答案
- 2024年辽宁高考历史试题(含答案和解析)
- 黄河商品交易市场介绍稿
- Unit 3 My friends Part C Story time(教学设计)-2024-2025学年人教PEP版英语四年级上册
- 2024中国海油校园招聘2024人(高频重点提升专题训练)共500题附带答案详解
- 孙中山诞辰纪念日主题班会主题班会
- 2024年安徽省合肥市中考语文题卷(含答案)
- G -B- 43630-2023 塔式和机架式服务器能效限定值及能效等级(正式版)
- 24春国开电大《工具书与文献检索》平时作业1-4答案
评论
0/150
提交评论