收藏 分享(赏)

LDA人脸识别的matlab程序.doc

上传人:HR专家 文档编号:6691299 上传时间:2019-04-20 格式:DOC 页数:9 大小:58KB
下载 相关 举报
LDA人脸识别的matlab程序.doc_第1页
第1页 / 共9页
LDA人脸识别的matlab程序.doc_第2页
第2页 / 共9页
LDA人脸识别的matlab程序.doc_第3页
第3页 / 共9页
LDA人脸识别的matlab程序.doc_第4页
第4页 / 共9页
LDA人脸识别的matlab程序.doc_第5页
第5页 / 共9页
点击查看更多>>
资源描述

1、LDA 人脸识别的 matlab 程序以下是 LDA 的 m 文件函数:你稍稍改改就能用了!function eigvector, eigvalue, elapse = LDA(gnd,options,data)% LDA: Linear Discriminant Analysis % eigvector, eigvalue = LDA(gnd, options, data)% % Input:% data - Data matrix. Each row vector of fea is a data point.% gnd - Colunm vector of the label infor

2、mation for each% data point. % options - Struct value in Matlab. The fields in options% that can be set:% Regu - 1: regularized solution, % a* = argmax (aXWXa)/(aXXa+ReguAlpha*I) % 0: solve the sinularity problem by SVD % Default: 0 % ReguAlpha - The regularization parameter. Valid% when Regu=1. Def

3、ault value is 0.1. % ReguType - Ridge: Tikhonov regularization% Custom: User provided% regularization matrix% Default: Ridge % regularizerR - (nFea x nFea) regularization% matrix which should be provided% if ReguType is Custom. nFea is% the feature number of data% matrix% Fisherface - 1: Fisherface

4、approach% PCARatio = nSmp - nClass% Default: 0% PCARatio - The percentage of principal% component kept in the PCA% step. The percentage is% calculated based on the% eigenvalue. Default is 1% (100%, all the non-zero% eigenvalues will be kept.% If PCARatio 1, the PCA step% will keep exactly PCARatio p

5、rinciple% components (does not exceed the% exact number of non-zero components). % % Output:% eigvector - Each column is an embedding function, for a new% data point (row vector) x, y = x*eigvector% will be the embedding result of x.% eigvalue - The sorted eigvalue of LDA eigen-problem. % elapse - T

6、ime spent on different steps % Examples:% % fea = rand(50,70);% gnd = ones(10,1);ones(15,1)*2;ones(10,1)*3;ones(15,1)*4;% options = ;% options.Fisherface = 1;% eigvector, eigvalue = LDA(gnd, options, fea);% Y = fea*eigvector;% % See also LPP, constructW, LGE%Reference:% P. N. Belhumeur, J. P. Hespan

7、ha, and D. J. Kriegman, 揈 igenfaces% vs. fisherfaces: recognition using class specific linear% projection, IEEE Transactions on Pattern Analysis and Machine% Intelligence, vol. 19, no. 7, pp. 711-720, July 1997. % Deng Cai, Xiaofei He, Yuxiao Hu, Jiawei Han, and Thomas Huang, % “Learning a Spatially

8、 Smooth Subspace for Face Recognition“, CVPR2007% Deng Cai, Xiaofei He, Jiawei Han, “SRDA: An Efficient Algorithm for% Large Scale Discriminant Analysis“, IEEE Transactions on Knowledge and% Data Engineering, 2007.% version 2.1 -June/2007 % version 2.0 -May/2007 % version 1.1 -Feb/2006 % version 1.0

9、 -April/2004 % Written by Deng Cai (dengcai2 AT cs.uiuc.edu)% if exist(data,var)global data;endif (exist(options,var)options = ;endif isfield(options,Regu) | options.RegubPCA = 1;if isfield(options,PCARatio)options.PCARatio = 1;endelsebPCA = 0;if isfield(options,ReguType)options.ReguType = Ridge;end

10、if isfield(options,ReguAlpha)options.ReguAlpha = 0.1;endendtmp_T = cputime;% = InitializationnSmp,nFea = size(data);if length(gnd) = nSmperror(gnd and data mismatch!);endclassLabel = unique(gnd);nClass = length(classLabel);Dim = nClass - 1;if bPCA endif issparse(data)data = full(data);endsampleMean

11、= mean(data,1);data = (data - repmat(sampleMean,nSmp,1);bChol = 0;if bPCA DPrime = max(DPrime,DPrime);R,p = chol(DPrime);if p = 0bPCA = 0;bChol = 1;endend%=% SVD%=if bPCA if nSmp nFeaddata = data*data;ddata = max(ddata,ddata);eigvector_PCA, eigvalue_PCA = eig(ddata);eigvalue_PCA = diag(eigvalue_PCA)

12、;clear ddata;maxEigValue = max(abs(eigvalue_PCA);eigIdx = find(eigvalue_PCA/maxEigValue 1idx = options.PCARatio;if idx = sumEigbreak;endendeigvalue_PCA = eigvalue_PCA(1:idx);eigvector_PCA = eigvector_PCA(:,1:idx);end%=eigvalue_PCA = eigvalue_PCA.-.5;data = (data*eigvector_PCA).*repmat(eigvalue_PCA,n

13、Smp,1);elseddata = data*data;ddata = max(ddata,ddata);eigvector, eigvalue_PCA = eig(ddata);eigvalue_PCA = diag(eigvalue_PCA);clear ddata;maxEigValue = max(eigvalue_PCA);eigIdx = find(eigvalue_PCA/maxEigValue 1idx = options.PCARatio;if idx = sumEigbreak;endendeigvalue_PCA = eigvalue_PCA(1:idx);eigvec

14、tor = eigvector(:,1:idx);end%=eigvalue_PCA = eigvalue_PCA.-.5;eigvector_PCA = (data*eigvector).*repmat(eigvalue_PCA,nFea,1);data = eigvector;clear eigvector;endelseif bCholDPrime = data*data;% options.ReguAlpha = nSmp*options.ReguAlpha;switch lower(options.ReguType)case lower(Ridge)for i=1:size(DPri

15、me,1)DPrime(i,i) = DPrime(i,i) + options.ReguAlpha;endcase lower(Tensor)DPrime = DPrime + options.ReguAlpha*options.regularizerR;case lower(Custom)DPrime = DPrime + options.ReguAlpha*options.regularizerR;otherwiseerror(ReguType does not exist!);endDPrime = max(DPrime,DPrime);endendnSmp,nFea = size(d

16、ata);Hb = zeros(nClass,nFea);for i = 1:nClass,index = find(gnd=classLabel(i);classMean = mean(data(index,:),1);Hb (i,:) = sqrt(length(index)*classMean;endelapse.timeW = 0;elapse.timePCA = cputime - tmp_T;tmp_T = cputime;if bPCAdumpVec,eigvalue,eigvector = svd(Hb,econ);eigvalue = diag(eigvalue);eigId

17、x = find(eigvalue dimMatrixDim = dimMatrix;endif isfield(options,bEigs)if options.bEigsbEigs = 1;elsebEigs = 0;endelseif (dimMatrix 1000 elsebEigs = 0;endendif bEigs%disp(use eigs to speed up!);option = struct(disp,0);if bCholoption.cholB = 1;eigvector, eigvalue = eigs(WPrime,R,Dim,la,option);elseei

18、gvector, eigvalue = eigs(WPrime,DPrime,Dim,la,option);endeigvalue = diag(eigvalue);elseeigvector, eigvalue = eig(WPrime,DPrime);eigvalue = diag(eigvalue);junk, index = sort(-eigvalue);eigvalue = eigvalue(index);eigvector = eigvector(:,index);if Dim size(eigvector,2)eigvector = eigvector(:, 1:Dim);eigvalue = eigvalue(1:Dim);endendendfor i = 1:size(eigvector,2)eigvector(:,i) = eigvector(:,i)./norm(eigvector(:,i);endelapse.timeMethod = cputime - tmp_T; elapse.timeAll = elapse.timePCA + elapse.timeMethod;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报