-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTensorLPP.m
112 lines (104 loc) · 3.71 KB
/
TensorLPP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function [U, V, eigvalue_U, eigvalue_V, posIdx, Y] = TensorLPP(X, W, options)
% TensorLPP: Tensor Locality Preserving Projections
%
% [U, V, eigvalue_U, eigvalue_V, posIdx, Y] = TensorLPP(X, W, options)
%
% Input:
% X - 3-d data matrix. X(:,:,i) is the i-th data
% sample.
% 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:
% nRepeat - The repeat times of the
% iterative procedure. Default
% 10
%
% Output:
% U, V - Embedding functions, for a new data point
% (matrix) x, y = U'*x*V will be the embedding
% result of x. You might need to resort each
% element in y based on the posIdx.
% eigvalue_U
% eigvalue_V - corresponding eigenvalue.
%
% Y - The embedding results, Each row vector is a
% data point. The features in Y has been sorted
% that Y(:,i) will be important to Y(:,j) with
% respect to the objective function if i<j
%
% posIdx - Resort idx. For a new data sample (matrix) x,
% y = U'*x*V, y is still a matrix.
% You should convert it to a vector by :
% y = reshape(y,size(U,2)*size(V,2),1)';
% and resort the features by:
% y = y(posIdx);
%
%
% Examples:
%
% fea = rand(50,100);
% options = [];
% options.Metric = 'Euclidean';
% options.NeighborMode = 'KNN';
% options.k = 5;
% options.WeightMode = 'HeatKernel';
% options.t = 1;
% W = constructW(fea,options);
% fea = reshape(fea',10,10,50);
% [U, V, eigvalue_U, eigvalue_V, posIdx, Y] = TensorLPP(fea, W, options);
%
%
% fea = rand(50,100);
% 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);
% fea = reshape(fea',10,10,50);
% [U, V, eigvalue_U, eigvalue_V, posIdx, Y] = TensorLPP(fea, W, options);
%
%
% See also constructW, LPP, TensorLGE.
%
%Reference:
%
% Xiaofei He, Deng Cai and Partha Niyogi, "Tensor Subspace Analysis".
% Advances in Neural Information Processing Systems 18 (NIPS 2005),
% Vancouver, Canada, 2005.
%
% Xiaofei He, Deng Cai, Haifeng Liu and Jiawei Han, "Image Clustering
% with Tensor Representation". ACM Multimedia 2005 , Nov. 2005, Hilton,
% Singapore.
%
% version 2.0 --May/2007
% version 1.1 --Feb/2006
% version 1.0 --Feb/2005
%
% Written by Deng Cai (dengcai2 AT cs.uiuc.edu)
%
if (~exist('options','var'))
options = [];
else
if ~strcmpi(class(options),'struct')
error('parameter error!');
end
end
if ~isfield(options,'nRepeat')
nRepeat = 10;
else
nRepeat = options.nRepeat; %
end
[nRow,nCol,nSmp] = size(X);
DataMean = mean(X,3);
for i=1:nSmp
X(:,:,i) = X(:,:,i)-DataMean;
end
D = sparse(1:nSmp,1:nSmp,sum(W),nSmp,nSmp);
if nargout == 6
[U, V, eigvalue_U, eigvalue_V, posIdx, Y] = TensorLGE(X, W, D, options);
else
[U, V, eigvalue_U, eigvalue_V, posIdx] = TensorLGE(X, W, D, options)
end