-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubsample.m
25 lines (22 loc) · 854 Bytes
/
subsample.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
% create a subset of a given dataset by randomly subsampling
function dataset = subsample (task, dataset)
fprintf('Subsampling %d instances from dataset %s\n', dataset.subsample, dataset.name);
cacheFile = sprintf('%s/subsample_%s.mat', task.dataDir, dataset.name);
if loadCache(cacheFile, task.forceFresh, getConst('CACHE_VER_SUBSAMPLE'))
N = size(dataset.X, 1);
Ns = min(dataset.subsample, N);
idx = randperm(N, Ns);
save(cacheFile, 'version', 'idx', '-v7.3');
end
dataset.X = double(dataset.X(idx, :));
switch dataset.neighborType
case 'affinity'
dataset.affinity = double(dataset.affinity(idx, idx));
case 'value'
dataset.value = double(dataset.value(idx));
case 'label'
dataset.label = double(dataset.label(idx));
case 'tag'
dataset.tag = double(dataset.tag(idx, :));
end
end