forked from pascanur/DeepLearningBenchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlp.m
162 lines (130 loc) · 3.99 KB
/
mlp.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
% script using the neural network toolbox for benchmarking a simple mlp/logreg
n_examples = 6000;
bmark = fopen('mlp_matlab.bmark', 'w');
data_x = rand(32,n_examples);
data_y = rand(10,n_examples);
% mlp_32_10
for i = 1:n_examples
cs_dx{i} = data_x(:,i);
cs_dy{i} = data_y(:,i);
end
% batch datasert
for i = 1:n_examples/60
dx = data_x(:, (i-1)*60+1:i*60);
dy = data_y(:, (i-1)*60+1:i*60);
bcs_dx{i} = dx;
bcs_dy{i} = dy;
end
disp(' small dataset created ...')
net = newff(data_x, data_y,[],{'softmax'});
net = init(net);
net.inputWeights{1,1}.learnFcn = 'learngd';
net.biases{1}.learnFcn = 'learngd';
net.adaptParam.passes = 1;
tic;
net = adapt(net, cs_dx, cs_dy);
t = toc
fprintf(bmark, 'mlp_32_10\t');
fprintf(bmark, 'matlab{cpu/double/1}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using meam square error (the default)\n');
net = init(net);
net.inputWeights{1,1}.learnFcn = 'learngd';
net.biases{1}.learnFcn = 'learngd';
net.adaptParam.passes = 1;
tic;
for i = 1:n_examples/60
net = adapt(net, bcs_dx{i}, bcs_dy{i});
end
t = toc
fprintf(bmark, 'mlp_32_10\t');
fprintf(bmark, 'matlab{cpu/double/60}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using meam square error (the default)\n');
data_x = rand(784, n_examples);
data_y = rand(10,n_examples);
for i = 1: n_examples
cl_dx{i} = data_x(:,i);
cl_dy{i} = data_y(:,i);
end
for i = 1:n_examples/60
dx = data_x(:, (i-1)*60+1:i*60);
dy = data_y(:, (i-1)*60+1:i*60);
bcl_dx{i} = dx;
bcl_dy{i} = dy;
end
disp(' large dataset created ...')
% mlp_784_10
net = newff(data_x, data_y,[],{'softmax'});
init(net);
net.inputWeights{1,1}.learnFcn = 'learngd';
net.biases{1}.learnFcn = 'learngd';
net.adaptParam.passes = 1;
tic;
net = adapt(net, cl_dx, cl_dy);
t = toc
fprintf(bmark, 'mlp_784_10\t');
fprintf(bmark, 'matlab{cpu/double/1}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
net = init(net);
tic;
for i = 1:n_examples/60
net = adapt(net, bcl_dx{i}, bcl_dy{i});
end
t = toc
fprintf(bmark, 'mlp_784_10\t');
fprintf(bmark, 'matlab{cpu/double/60}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
% mlp_784_500_10
net = newff(data_x, data_y,500,{'logsig','softmax'});
init(net);
net.inputWeights{1,1}.learnFcn = 'learngd';
net.biases{1}.learnFcn = 'learngd';
net.adaptParam.passes = 1;
net.layerWeights{2,1}.learnFcn = 'learngd';
tic
net = adapt(net, cl_dx, cl_dy);
t = toc
fprintf(bmark, 'mlp_784_500_10\t');
fprintf(bmark, 'matlab{cpu/double/1}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
net = init(net);
tic;
for i = 1:n_examples/60
net = adapt(net, bcl_dx{i}, bcl_dy{i});
end
t = toc
fprintf(bmark, 'mlp_784_500_10\t');
fprintf(bmark, 'matlab{cpu/double/60}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
%mlp_784_1000_1000_1000_10
net = newff(data_x, data_y,[1000,1000,1000],{'logsig','logsig','logsig','softmax'});
init(net);
net.inputWeights{1,1}.learnFcn = 'learngd';
net.biases{1}.learnFcn = 'learngd';
net.adaptParam.passes = 1;
net.layerWeights{2,1}.learnFcn = 'learngd';
net.layerWeights{3,2}.learnFcn = 'learngd';
net.layerWeights{4,3}.learnFcn = 'learngd';
tic;
net = adapt(net, cl_dx, cl_dy);
t = toc
fprintf(bmark, 'mlp_784_1000_1000_1000_10\t');
fprintf(bmark, 'matlab{cpu/double/1}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
net = init(net);
tic;
for i = 1:n_examples/60
net = adapt(net, bcl_dx{i}, bcl_dy{i});
end
t = toc
fprintf(bmark, 'mlp_784__1000_1000_1000_10\t');
fprintf(bmark, 'matlab{cpu/double/60}\t');
fprintf(bmark, '%.2f\n', n_examples/t);
fprintf(bmark, '# Could not find NLL, using mean square error (the default)\n');
fclose(bmark)