-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMAED.m
107 lines (96 loc) · 3.21 KB
/
MAED.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
function sampleList = MAED(fea,selectNum,options)
% MAED: Manifold Adaptive Experimental Design
%
% sampleList = MAED(fea,selectNum,options)
%
% Input:
%
% fea - Data matrix. Each row of fea is a sample.
% selectNum - The number of samples to select.
% options - Struct value in Matlab. The fields in options
% that can be set:
%
% splitLabel - logical array with the size as the number
% of samples. If some of the inputs already
% have the label and there is no need
% select these samples, you should set the
% corresponding entry in 'splitLabel' as
% true; (Default: all false)
%
% W - Affinity matrix. You can either call
% "constructW" to construct the W, or
% construct it by yourself.
% If 'W' is not provided and 'ReguBeta'>0 ,
% MAED will build a k-NN graph with Heat kernel
% weight, where 'k' is a prameter.
%
% k - The parameter for k-NN graph (Default is 5)
% If 'W' is provided, this parameter will be
% ignored.
%
% ReguBeta - regularization paramter for manifold
% adaptive kernel.
%
% ReguAlpha - ridge regularization paramter. Default 0.01
%
%
% Output:
%
% sampleList - The index of the sample which should be labeled.
%
% Examples:
%
% See: http://www.zjucadcg.cn/dengcai/Data/ReproduceExp.html#MAED
%
%Reference:
%
% [1] Deng Cai and Xiaofei He, "Manifold Adaptive Experimental Design for
% Text Categorization", IEEE Transactions on Knowledge and Data
% Engineering, vol. 24, no. 4, pp. 707-719, 2012.
%
% version 2.0 --Jan/2012
% version 1.0 --Aug/2008
%
% Written by Deng Cai (dengcai AT gmail.com)
%
nSmp = size(fea,1);
splitLabel = false(nSmp,1);
if isfield(options,'splitLabel')
splitLabel = options.splitLabel;
end
K = constructKernel(fea,[],options);
if isfield(options,'ReguBeta') && options.ReguBeta > 0
if isfield(options,'W')
W = options.W;
else
if isfield(options,'k')
Woptions.k = options.k;
else
Woptions.k = 5;
end
if nSmp > 3000
tmpD = EuDist2(fea(randsample(nSmp,3000),:));
else
tmpD = EuDist2(fea);
end
Woptions.t = mean(mean(tmpD));
W = constructW(fea,Woptions);
end
D = full(sum(W,2));
L = spdiags(D,0,nSmp,nSmp)-W;
K=(speye(size(K,1))+options.ReguBeta*K*L)\K;
K = max(K,K');
end
if ~isfield(options,'Method')
options.Method = 'Seq';
end
ReguAlpha = 0.01;
if isfield(options,'ReguAlpha')
ReguAlpha = options.ReguAlpha;
end
switch lower(options.Method)
case {lower('Seq')}
sampleList = MAEDseq(K,selectNum,splitLabel,ReguAlpha);
otherwise
error('Optimization method does not exist!');
end