-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchecker.m
More file actions
298 lines (260 loc) · 11 KB
/
checker.m
File metadata and controls
298 lines (260 loc) · 11 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
%checker Tema2 MN
total_points = 0;
no_tests = 4;
no_pcs = 2;
no_train_images = 10000;
err = 10^-2;
addpath ('functions/');
printf('---------------------------------------------------------------------------------------------------------\n');
printf('---------------------------------------------------------------------------------------------------------\n');
printf('------------------------------------------ Testare Tema 1 MN --------------------------------------------\n');
printf('---------------------------------------------------------------------------------------------------------\n');
printf('---------------------------------------------------------------------------------------------------------\n');
im = "image";
pcs = [3, 30];
%%% -----------------------------------------------------------
%%% Test Task 1
%%% -----------------------------------------------------------
printf ('---------------------------------------------------------------------------------------------------------\n');
printf ('-------------------------------------------------Task 1--------------------------------------------------\n');
task1_points = 0;
for i = 1:no_tests
for j = 1:no_pcs
% Creare nume fisiere de intrare si de referinta
name = strcat (im, num2str (i));
image_ref = strcat ('ref/task1_', name);
image_ref = strcat (image_ref, '_');
image_ref = strcat (image_ref, num2str (pcs(j)));
image_ref = strcat (image_ref, '.gif');
image_in = strcat ('in/', name);
image_in = strcat (image_in, '.gif');
image_ref_mat = imread (image_ref);
image_in_mat = imread (image_in);
image_result_mat = task1 (image_in_mat, pcs(j));
success = 1;
[m, n] = size (image_ref_mat);
for k = 1:m
for l = 1:n
if abs (image_ref_mat(k,l) - image_result_mat(k,l)) > err
success = 0;
break;
endif
endfor
if success == 0
break;
endif
endfor
if success == 0
printf ('Task 1 - image %d - %d PCs .....................................................Incorect [%d / %d]\n' , i, pcs(j), 0, 2.5);
else
printf ('Task 1 - image %d - %d PCs .....................................................Corect [%d / %d]\n' , i, pcs(j), 2.5, 2.5);
task1_points += 2.5;
total_points += 2.5;
endif
endfor
endfor
printf ('Task 1 = [%d / 20]\n', task1_points);
%%% -----------------------------------------------------------
%%% Test Task 2
%%% -----------------------------------------------------------
printf ('---------------------------------------------------------------------------------------------------------\n');
printf ('-------------------------------------------------Task 2--------------------------------------------------\n');
task2_points = 0;
for i = 1:no_tests
for j = 1:no_pcs
% Creare nume fisiere de intrare si de referinta
name = strcat (im, num2str (i));
image_ref = strcat ('ref/task2_', name);
image_ref = strcat (image_ref, '_');
image_ref = strcat (image_ref, num2str (pcs(j)));
image_ref = strcat (image_ref, '.gif');
image_in = strcat ('in/', name);
image_in = strcat (image_in, '.gif');
image_ref_mat = imread (image_ref);
image_in_mat = imread (image_in);
image_result_mat = task2 (image_in_mat, pcs(j));
success = 1;
[m, n] = size (image_ref_mat);
for k = 1:m
for l = 1:n
if abs (image_ref_mat(k,l) - image_result_mat(k,l)) > err
success = 0;
break;
endif
endfor
if success == 0
break;
endif
endfor
if success == 0
printf ('Task 2 - image %d - %d PCs .....................................................Incorect [%d / %d]\n' , i, pcs(j), 0, 2.5);
else
printf ('Task 2 - image %d - %d PCs .....................................................Corect [%d / %d]\n' , i, pcs(j), 2.5, 2.5);
task2_points += 2.5;
total_points += 2.5;
endif
endfor
endfor
printf ('Task 2 = [%d / 20]\n', task2_points);
%%% -----------------------------------------------------------
%%% Test Task 3
%%% -----------------------------------------------------------
printf ('---------------------------------------------------------------------------------------------------------\n');
printf ('-------------------------------------------------Task 3--------------------------------------------------\n');
task3_points = 0;
for i = 1:no_tests
for j = 1:no_pcs
% Creare nume fisiere de intrare si de referinta
name = strcat (im, num2str (i));
image_ref = strcat ('ref/task3_', name);
image_ref = strcat (image_ref, '_');
image_ref = strcat (image_ref, num2str (pcs(j)));
image_ref = strcat (image_ref, '.gif');
image_in = strcat ('in/', name);
image_in = strcat (image_in, '.gif');
image_ref_mat = imread (image_ref);
image_in_mat = imread (image_in);
image_result_mat = task3 (image_in_mat, pcs(j));
success = 1;
[m, n] = size (image_ref_mat);
for k = 1:m
for l = 1:n
if abs (image_ref_mat(k,l) - image_result_mat(k,l)) > err
success = 0;
break;
endif
endfor
if success == 0
break;
endif
endfor
if success == 0
printf ('Task 3 - image %d - %d PCs .....................................................Incorect [%d / %d]\n' , i, pcs(j), 0, 2.5);
else
printf ('Task 3 - image %d - %d PCs .....................................................Corect [%d / %d]\n' , i, pcs(j), 2.5, 2.5);
task3_points += 2.5;
total_points += 2.5;
endif
endfor
endfor
printf ('Task 3 = [%d / 20]\n', task3_points);
%%% -----------------------------------------------------------
%%% Test Task 4
%%% -----------------------------------------------------------
printf ('---------------------------------------------------------------------------------------------------------\n');
printf ('-------------------------------------------------Task 4--------------------------------------------------\n');
task4_points = 0;
random_photos = [1431, 2327, 5264, 6774, 8390];
% Pregatirea datelor de antrenament.
[train_mat, train_val] = prepare_data ('mnist.mat', no_train_images);
[new_train_mat, miu, F, Vk] = magic_with_pca (train_mat, 23);
name = 'Digit Recognition - ref/DR_';
name_in = 'Digit Recognition - in/image';
for i = 1:2
test_name = strcat (name, num2str (i));
test_name = strcat (test_name, '_');
if i == 1
train = train_mat;
else
train = new_train_mat;
endif
for j = 1:5
image_ref = strcat (test_name, num2str (j));
image_ref = strcat (image_ref, '.png');
im = visualise_image (train, random_photos (j));
im_ref = imread (image_ref);
% Transformama im si im_ref in double pt a se face corect calculul.
im = double (im);
im_ref = double (im_ref);
[m, n] = size(im);
[p, q] = size (im_ref);
if m != p || n != q
success = 0;
else
success = 1;
for k = 1:28
for l = 1:28
if abs (im (k,l) - im_ref (k,l)) > err
success = 0;
break;
endif
endfor
if success == 0
break;
endif
endfor
endif
if success == 0
if i == 1
printf ('Task 4 - data image %d ..............................................................Incorect [%d / %d]\n' , j, 0, 2);
else
printf ('Task 4 - data processing image %d ...................................................Incorect [%d / %d]\n' , j, 0, 1);
endif
else
if i == 1
printf ('Task 4 - data image %d .............................................................Corect [%d / %d]\n' , j, 2, 2);
task4_points += 2;
total_points += 2;
else
printf ('Task 4 - data processing image %d ..................................................Corect [%d / %d]\n' , j, 1, 1);
task4_points += 1;
total_points += 1;
endif
endif
endfor
endfor
for i = 1:2
test_name = strcat (name, num2str (i + 2));
test_name = strcat (test_name, '_');
for j = 1:10
image_in = strcat (name_in, num2str (j));
image_in = strcat (image_in, '.png');
image_ref = strcat (test_name, num2str (j));
image_ref = strcat (image_ref, '.txt');
im = imread (image_in);
im = prepare_photo (im);
if i == 2
im = classifyImage (im, train_mat, train_val, 23);
endif
[m, n] = size (im);
ref = dlmread (image_ref);
success = 1;
for k = 1:n
if im (k) != ref (k)
success = 0;
break;
endif
endfor
if success == 0
if i == 1
printf ('Task 4 - invert image %d .....................................................Incorect [%d / %d]\n' , j, 0, 0.5 * i);
else
printf ('Task 4 - prediction %d ..........................................................Incorect [%d / %d]\n' , j, 0, 1.5);
endif
else
if i == 1
printf ('Task 4 - invert image %d .....................................................Corect [%d / %d]\n' , j, 0.5 * i, 0.5 * i);
task4_points += 0.5 * i;
total_points += 0.5 * i;
else
printf ('Task 4 - prediction %d ..........................................................Corect [%d / %d]\n' , j, 1.5, 1.5);
task4_points += 1.5;
total_points += 1.5;
endif
endif
endfor
endfor
printf ('Task 4 = [%d / 35]\n', task4_points);
%%% -----------------------------------------------------------
%%% Test Readme
%%% -----------------------------------------------------------
printf ('---------------------------------------------------------------------------------------------------------\n');
printf ('---------------------------------------------------------------------------------------------------------\n');
if exist('Readme.pdf') == 2
printf ('Readme ..............................................................................Found [%d / %d]\n', 5, 5);
total_points += 5;
else
printf ('Readme ..........................................................................Not Found [%d / %d]\n', 0, 5);
endif
printf ('Total = [%d / 100]\n', total_points);
rmpath ('functions/');