-
Notifications
You must be signed in to change notification settings - Fork 18
/
fs_unsup_spfs_nes.m
57 lines (48 loc) · 1.31 KB
/
fs_unsup_spfs_nes.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
function [ W, lam ]= fs_unsup_spfs_nes( X, Y, k, err, starting )
%unsupervised feature selection by 2-1 norm regression
% X - the training data, each row is an instance
% Y - the class label
if nargin < 5
starting = 0.5;
end
% L2-1 norm
opts.q=2;
% lambda = lambda * lambda_{max}
opts.rFlag=1;
% norm( x_i - x_{i-1}, 2) <= .tol
% opts.tFlag = 3;
% Tolerance parameter.
% opts.tol=1e-4;
% opts.init=2;
% .x0= zeros(n,1), .c0=0
% opts.init=2;
opts.verbose = 0;
opts.maxIter = 500;
upL = 1; downL = 0;
lam = starting; % the initial search point
nZ = k + 2*err;
count = 1;
need = -1;
while abs(nZ - k) > err && count <= 10
oldNZ = nZ;
oldNeed = need;
% fprintf('need %i, iteration: %2i, lam: %f\n', k, count, lam);
W = mcLeastR(X, Y, lam, opts);
opts.x0=W;
nZ = sum(sum(W.^2,2)>0);
if nZ - k > err
need = -1;
downL = lam; lam = (downL + upL) / 2;
elseif nZ - k < -err
need = 1;
upL = lam; lam = (downL + upL) / 2;
end
if nZ < oldNZ && oldNeed == 1
opts = rmfield(opts, 'x0');
W = mcLeastR(X, Y, lam, opts);
nZ = sum(sum(W.^2,2)>0);
% fprintf('restart, %f, sel feat: %i\n-----\n', lam, nZ);
end
% fprintf('sel feat: %i\n-----\n', nZ);
count = count + 1;
end