-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuo_nn_dataset.m
71 lines (70 loc) · 2.27 KB
/
uo_nn_dataset.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
function [X,y] = uo_nn_dataset(seed, ncol, target, freq)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input:
% target: if <>[] : target numbers.
% if = [] : the function is asked to randomly generate 'ncol'
% digits.
% freq :
% Output:
% y : if <>[] : y(i)=1 if X(:,i) is one of the target digits in 'target'; y(i)=0 otherwise.
% if = [] : y(i) integer stored in X(:,i).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = [
0 0 1 0 0, 0 1 1 0 0, 0 0 1 0 0, 0 0 1 0 0, 0 0 1 0 0, 0 0 1 0 0, 0 1 1 1 0; % 1
0 1 1 1 0, 1 0 0 0 1, 0 0 0 0 1, 0 0 0 1 0, 0 0 1 0 0, 0 1 0 0 0, 1 1 1 1 1; % 2
0 1 1 1 0, 1 0 0 0 1, 0 0 0 0 1, 0 0 1 1 0, 0 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0; % 3
0 0 1 1 0, 0 1 0 1 0, 1 0 0 1 0, 1 0 0 1 0, 1 1 1 1 1, 0 0 0 1 0, 0 0 0 1 0; % 4
1 1 1 1 1, 1 0 0 0 0, 1 1 1 1 0, 0 0 0 0 1, 0 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0; % 5
0 0 1 1 1, 0 1 0 0 0, 1 0 0 0 0, 1 1 1 1 0, 1 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0; % 6
1 1 1 1 1, 0 0 0 0 1, 0 0 0 0 1, 0 0 0 1 0, 0 0 1 0 0, 0 1 0 0 0, 1 0 0 0 0; % 7
0 1 1 1 0, 1 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0, 1 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0; % 8
0 1 1 1 0, 1 0 0 0 1, 1 0 0 0 1, 0 1 1 1 1, 0 0 0 0 1, 0 0 0 0 1, 0 1 1 1 0; % 9
0 1 1 1 0, 1 0 0 0 1, 1 0 0 0 1, 1 0 0 0 1, 1 0 0 0 1, 1 0 0 0 1, 0 1 1 1 0; % 0
];
N = N';
%%
xval = 10;
maxsigma = 1.;
minsigma = 0.25;
if xval > 0
N = xval*((N-1)+N);
end
if ~isempty(seed) rng(seed); end;
nT = size(target,2);
nPixels = size(N,1);
%% Generation
for j=1:ncol
if nT > 0 & rand() < (freq-0.1*nT)/(1-0.1*nT)
i = target(randi([1,nT]));
else
i = randi(10);
end
X(:,j) = N(:,i);
if isempty(target)
y(j) = i;
else
if any(i == target)
y(j) = 1;
else
y(j) = 0;
end
end
end
%% Blur
for j=1:ncol
l = zeros(1,nPixels);
sigma = minsigma + (maxsigma-minsigma)*rand();
for k = 1:nPixels
ii = randi([1 nPixels]);
while l(ii)==1
ii = randi([1 nPixels]);
end
l(ii) = 1;
if X(ii,j) > 0
X(ii,j) = xval + sigma*xval*randn();
else
X(ii,j) = -(xval + sigma*xval*randn());
end
end
end
end