-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomLabelMask.m
More file actions
34 lines (25 loc) · 835 Bytes
/
randomLabelMask.m
File metadata and controls
34 lines (25 loc) · 835 Bytes
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
% get a random label mask for choosing some instances as labels
%
% randomLabelMask(hypergraph, labelNum, labelRatio)
%
% hypergraph - the labeled hypergraph (or graph)
% labelNum - number of labeled instances or []
% labelRatio - the ratio of labeled instances or []
%
% output: a sparse 1 x instanceNum logical vector
%
function out = randomLabelMask(c, labelRatio, classLabels)
% Hypergraph Analysis Toolbox (HAT)
% Copyright 2011, written by Li PU @ lia.epfl.ch, li.pu@epfl.ch
% Modifications:
% 24-aug-2011, created [Li PU]
out = classLabels;
for i=1:c
labelIndices = find(classLabels==i);
vnum = length(labelIndices);
%num of masked instances for each label
labelNum = ceil(length(labelIndices)*labelRatio);
k = randperm(vnum);
k = k(1:labelNum);
out(labelIndices(k)) = -1;
end