-
Notifications
You must be signed in to change notification settings - Fork 0
/
tcdataGenerator.m
44 lines (40 loc) · 1.14 KB
/
tcdataGenerator.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
function [x y] = tcdataGenerator(nsamples, per, type)
% generate two classes data
% x -- dataset, size = [nsamples 2]
% y -- labels, size = [nsamples 1]
% per -- percentage of positive samples
if nargin == 1
type = 'normal';
per = 0.5;
end
if nargin == 2
type = 'normal';
end
npos = round(nsamples*per);
nneg = nsamples - npos;
switch lower(type)
case 'normal'
% Random arrays from the normal distribution
data_pos = [];
data_neg = [];
for i = 1:npos
data_pos = [data_pos; normrnd([1 4], 1)];
end
for i = 1:nneg
data_neg = [data_neg; normrnd([4 1], 1)];
end
labels_pos = ones(npos, 1);
labels_neg = -ones(nneg, 1);
x = [data_pos; data_neg];
y = [labels_pos; labels_neg];
case 'linear'
% Linear Seperable Data in 2-dimension
data_pos= mvnrnd ( [1,1]*2, eye(2), npos );
labels_pos = ones(npos, 1);
data_neg= mvnrnd ( [-1,-1]*2, eye(2), nneg);
labels_neg = -ones(nneg, 1);
x = [data_pos; data_neg];
y = [labels_pos; labels_neg];
otherwise
% normal
end