-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLaplacianScore.m
69 lines (53 loc) · 1.42 KB
/
LaplacianScore.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
function [Y] = LaplacianScore(X, W)
% Usage:
% [Y] = LaplacianScore(X, W)
%
% X: Rows of vectors of data points
% W: The affinity matrix.
% Y: Vector of (1-LaplacianScore) for each feature.
% The features with larger y are more important.
%
% Examples:
%
% fea = rand(50,70);
% options = [];
% options.Metric = 'Cosine';
% options.NeighborMode = 'KNN';
% options.k = 5;
% options.WeightMode = 'Cosine';
% W = constructW(fea,options);
%
% LaplacianScore = LaplacianScore(fea,W);
% [junk, index] = sort(-LaplacianScore);
%
% newfea = fea(:,index);
% %the features in newfea will be sorted based on their importance.
%
% Type "LaplacianScore" for a self-demo.
%
% See also constructW
%
%Reference:
%
% Xiaofei He, Deng Cai and Partha Niyogi, "Laplacian Score for Feature Selection".
% Advances in Neural Information Processing Systems 18 (NIPS 2005),
% Vancouver, Canada, 2005.
%
% Deng Cai, 2004/08
if nargin == 0, selfdemo; return; end
[nSmp,nFea] = size(X);
if size(W,1) ~= nSmp
error('W is error');
end
D = full(sum(W,2));
L = W;
allone = ones(nSmp,1);
tmp1 = D'*X;
D = sparse(1:nSmp,1:nSmp,D,nSmp,nSmp);
DPrime = sum((X'*D)'.*X)-tmp1.*tmp1/sum(diag(D));
LPrime = sum((X'*L)'.*X)-tmp1.*tmp1/sum(diag(D));
DPrime(find(DPrime < 1e-12)) = 10000;
Y = LPrime./DPrime;
Y = Y';
Y = full(Y);
%---------------------------------------------------