📄 olpp.m
字号:
function [eigvector, eigvalue, bSuccess] = OLPP(X, W, options)
% OLPP: Orthogonal Locality Preserving Projections
%
% [eigvector, eigvalue, bSuccess] = OLPP(X, W, options)
%
% Input:
% X - Data matrix. Each row vector of fea is a data point.
% W - Affinity matrix. You can either call "constructW"
% to construct the W, or construct it by yourself.
% options - Struct value in Matlab. The fields in options
% that can be set:
%
% ReducedDim - The dimensionality of the reduced
% subspace. If 0, all the dimensions
% will be kept. Default is 30.
%
% Regu - 1: regularized solution,
% a* = argmax (a'X'WXa)/(a'X'DXa+alpha*I)
% 0: solve the sinularity problem by SVD (PCA)
% Default: 1
%
% alpha - The regularization parameter. Valid
% when Regu==1. Default 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
%
% 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 principle
% components (does not exceed the
% exact number of non-zero components).
%
% bDisp - 0 or 1. diagnostic information
% display
%
% 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 OLPP eigen-problem.
%
% bSuccess - 0 or 1. Indicates whether the OLPP calcuation
% is successful. (OLPP needs matrix inverse,
% which will lead to eigen-decompose a
% non-symmetrical matrix. The caculation precsion
% of malab sometimes will cause imaginary numbers
% in eigenvectors. It seems that the caculation
% precsion of matlab is a little bit random, you
% can try again if not successful. More robust
% and efficient algorithms are welcome!)
%
%
%
%
%
% Examples:
%
% fea = rand(50,70);
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'KNN';
% options.k = 5;
% options.WeightMode = 'HeatKernel';
% options.t = 1;
% W = constructW(fea,options);
% options.PCARatio = 0.99
% options.ReducedDim = 5;
% [eigvector, eigvalue, bSuccess] = OLPP(fea, W, options);
% if bSuccess
% Y = fea*eigvector;
% end
%
% fea = rand(50,70);
% gnd = [ones(10,1);ones(15,1)*2;ones(10,1)*3;ones(15,1)*4];
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'Supervised';
% options.gnd = gnd;
% options.bLDA = 1;
% W = constructW(fea,options);
% options.PCARatio = 1;
% options.ReducedDim = 5;
% [eigvector, eigvalue, bSuccess] = OLPP(fea, W, options);
% if bSuccess
% Y = fea*eigvector;
% end
%
%
%
% See also constructW, LPP, LGE, OLGE.
%
%Reference:
%
% Deng Cai and Xiaofei He, "Orthogonal Locality Preserving Indexing"
% The 28th Annual International ACM SIGIR Conference (SIGIR'2005),
% Salvador, Brazil, Aug. 2005.
%
% Deng Cai, Xiaofei He, Jiawei Han and Hong-Jiang Zhang, "Orthogonal
% Laplacianfaces for Face Recognition". IEEE Transactions on Image
% Processing, vol. 15, no. 11, pp. 3608-3614, November, 2006.
%
% Written by Deng Cai (dengcai2 AT cs.uiuc.edu), August/2004, Feb/2006,
% Mar/2007, May/2007
if (~exist('options','var'))
options = [];
end
[nSmp,nFea] = size(X);
if size(W,1) ~= nSmp
error('W and X mismatch!');
end
D = sparse(1:nSmp,1:nSmp,sum(W),nSmp,nSmp);
%==========================
% If X is too large, the following centering codes can be commented
%==========================
if issparse(X)
X = full(X);
end
sampleMean = mean(X);
X = (X - repmat(sampleMean,nSmp,1));
%==========================
[eigvector, eigvalue, bSuccess] = OLGE(X, W, D, options);
eigIdx = find(eigvalue < 1e-3);
eigvalue (eigIdx) = [];
eigvector(:,eigIdx) = [];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -