-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReconstructDataset.m
More file actions
50 lines (44 loc) · 1.44 KB
/
ReconstructDataset.m
File metadata and controls
50 lines (44 loc) · 1.44 KB
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
%%
%
function do()
svmpath = 'D:\微云网盘\357812021\DropBox\Dropbox\Lab\毕设\SVM\libsvm-master\libsvm-master\windows\';
procpath = 'D:\微云网盘\357812021\DropBox\Dropbox\Lab\毕设\DataProcess\';
datapath = 'D:\微云网盘\357812021\WorkSpace\TsinghuaLab\data\6dmg';
path(path, svmpath);
path(path, procpath);
path(path, datapath);
load('trainfeatures.mat');
load('trainy.mat');
[mtrainFeatures] = LDAFeatureComp(trainfeatures,trainy);
[ntrain,ntrainy,ntest,ntesty] = rebuild(mtrainFeatures,trainy, 1000);
save('ndataset.mat','ntrain','ntrainy','ntest','ntesty');
end
function [train, trainy, test, testy] = rebuild(origin, originy, testSize)
[num,dim] = size(origin);
seg = [];
label = originy;
last = min(label);
seg(end+1) = last;
for i= 1: num
if( label(i) > last)
seg(end+1) = i;
last = label(i);
end
end
seg(end+1) = num+1;
ntypes = length(seg)-1;
test = zeros(ntypes*testSize, dim);
testy= zeros(ntypes*testSize, 1);
mask = [];
idx =1;
for i = 1: ntypes
testMask = randsample(seg(i): seg(i+1)-1, testSize);
test( (i-1)*testSize + 1: i*testSize,:) = origin(testMask,:);
testy((i-1)*testSize + 1: i*testSize,:) = originy(testMask,:);
mask(end+1:end + testSize) = testMask;
end
origin(mask,:) = [];
originy(mask,:) = [];
train = origin;
trainy = originy;
end