function [eigvector, eigvalue,new_samples] = LPP(X, W, options)
% LPP: Locality Preserving Projections
%
% [eigvector, eigvalue] = LPP(Y, W, options)
%
% Input:
% Y - Data matrix. Each row vector of Y 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 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.
% 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 eigvalue of LPP eigen-problem. sorted from
% smallest to largest.
%
%
% [eigvector, eigvalue] = LPP(Y, W, options)
%
% Y: The embedding results, Each row vector is a data point.
% Y = Y*eigvector
%
%
% Examples:
%
% Y = rand(50,70);
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'KNN';
% options.k = 5;
% options.WeightMode = 'HeatKernel';
% W = constructW(Y,options);
% options.PCARatio = 0.99
% [eigvector, eigvalue] = LPP(Y, W, options);
%
%
%
% Note: After applying some simple algebra, the smallest eigenvalue problem:
% Y^T*L*Y = \lemda Y^T*D*Y
% is equivalent to the largest eigenvalue problem:
% Y^T*W*Y = \beta Y^T*D*Y
% where L=D-W; \lemda= 1 - \beta.
% Thus, the smallest eigenvalue problem can be transformed to a largest
% eigenvalue problem. Such tricks are adopted in this code for the
% consideration of calculation precision of Matlab.
%
%
% See also constructW, pca.
%Reference:
% Xiaofei He, and Partha Niyogi, "Locality Preserving Projections"
% Advances in Neural Information Processing Systems 16 (NIPS 2003),
% Vancouver, Canada, 2003.
%
% Written by Qiuqiu Li([email protected]), April/2013,
if (~exist('options','var'))
options = [];
else
if ~isstruct(options)
error('parameter error!');
end
end
if ~isfield(options,'PCARatio')
[eigvector_PCA, ~, ~, new_X] = PCA(X);
else
PCAoptions = [];
PCAoptions.PCARatio = options.PCARatio;
[eigvector_PCA, ~, ~, new_X] = PCA(X,PCAoptions);
end
Y = new_X;
[nSmp,nFea] = size(Y);
if nFea > nSmp
error('Y is not of full rank in column!!');
end
if ~isfield(options,'ReducedDim')
ReducedDim = nFea;
else
ReducedDim = options.ReducedDim;
end
if ReducedDim > nFea
ReducedDim = nFea;
end
D = diag(sum(W));
%L = D - W;
L =D - W ;
DPrime = Y'*D*Y;
DPrime = max(DPrime,DPrime');
LPrime = Y'*L*Y;
LPrime = max(LPrime,LPrime');
dimMatrix = size(DPrime,2);
if dimMatrix > 1000 && ReducedDim < dimMatrix/10 % using eigs to speed up!
option = struct('disp',0);
[eigvector, eigvalue] = eigs(LPrime,DPrime,ReducedDim,'la',option);
eigvalue = diag(eigvalue);
else
[eigvector, eigvalue] = eig(LPrime,DPrime);
eigvalue = diag(eigvalue);
[~, index] = sort(eigvalue);
eigvalue = eigvalue(index);
eigvector = eigvector(:,index);
end
eigvalue = ones(length(eigvalue),1) - eigvalue;
if ReducedDim < size(eigvector,2)
eigvector = eigvector(:, 1:ReducedDim);
eigvalue = eigvalue(1:ReducedDim);
end
for i = 1:size(eigvector,2)
eigvector(:,i) = eigvector(:,i)./norm(eigvector(:,i));
end
eigvector = eigvector_PCA*eigvector;
new_samples=X*eigvector;
lpp.zip_lpp
版权申诉
160 浏览量
2022-09-24
21:08:17
上传
评论
收藏 2KB ZIP 举报
朱moyimi
- 粉丝: 64
- 资源: 1万+
最新资源
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0