-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP2_Katarzyna_Giadla.m
178 lines (160 loc) · 4.95 KB
/
P2_Katarzyna_Giadla.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
close all; clear all; clc;
wart_in = [0 1; 0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;
0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1;0 1]; %wart_ in - jakie wartoœci mo¿e przyjmowaæ wêze³ wejœciowy
% -> poniewa¿ nasze obrazy przyjmuj¹ rozmiar 5x5,
%zatem wêze³ wejœciowy mo¿e przyj¹æ 25 wartoœci 0 lub 1
%ustawione pionowo
wart_out = 1; %iloϾ wyjϾ z sieci
%metoda 1 - perceptron
%net = newp(wart_in, wart_out);
%metoda 2 - tworzenie sieci jednowarstwowej
net = newlin(wart_in, wart_out, 0, 0.01);
%kolumnowa reprezentacja binarna ka¿dej litery
% A a B b C c D d E e F f H h I i K k L l
Learn_in = [0 0 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1;
1 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0;
1 1 1 0 1 0 1 0 1 1 1 1 0 0 0 0 0 0 0 0;
1 0 0 0 1 0 0 1 1 0 1 0 0 0 0 0 1 0 0 0;
0 0 0 0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ie
%okreœliliœmy wspó³czynnik uczenia
%net.trainParam.showWindow = false;
net = train(net, Learn_in, Learn_out); %uczenie sieci
%litery do testu
test_A = [0;1;1;1;0;
1;0;0;0;1;
1;0;0;0;1;
1;1;1;1;1;
1;0;0;0;1];
test_a = [0;1;1;0;0;
0;0;0;1;0;
0;1;1;1;0;
1;0;0;1;0;
0;1;1;1;1];
test_B = [1;1;1;0;0;
1;0;0;1;0;
1;1;1;0;0;
1;0;0;1;0;
1;1;1;0;0];
test_b = [1;0;0;0;0;
1;0;0;0;0;
1;1;1;0;0;
1;0;0;1;0;
1;1;1;0;0];
test_C = [1;1;1;1;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;1;1;1;0];
test_c = [0;0;0;0;0;
0;0;0;0;0;
0;1;1;0;0;
1;0;0;0;0;
0;1;1;0;0];
test_D = [1;1;1;0;0;
1;0;0;1;0;
1;0;0;1;0;
1;0;0;1;0;
1;1;1;0;0];
test_d = [0;0;0;1;0;
0;0;0;1;0;
0;1;1;1;0;
1;0;0;1;0;
0;1;1;1;0];
test_E = [1;1;1;1;0;
1;0;0;0;0;
1;1;1;0;0;
1;0;0;0;0;
1;1;1;1;0];
test_e = [0;1;1;0;0;
1;0;0;1;0;
1;1;1;0;0;
1;0;0;0;0;
0;1;1;0;0];
test_F = [1;1;1;1;0;
1;0;0;0;0;
1;1;1;0;0;
1;0;0;0;0;
1;0;0;0;0];
test_f = [0;1;1;0;0;
1;0;0;0;0;
1;1;1;0;0;
1;0;0;0;0;
1;0;0;0;0];
test_H = [1;0;0;0;1;
1;0;0;0;1;
1;1;1;1;1;
1;0;0;0;1;
1;0;0;0;1];
test_h = [1;0;0;0;0;
1;0;0;0;0;
1;1;1;1;0;
1;0;0;1;0;
1;0;0;1;0];
test_I = [1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0];
test_i = [1;0;0;0;0;
0;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0];
test_K = [1;0;0;1;0;
1;0;1;0;0;
1;1;0;0;0;
1;0;1;0;0;
1;0;0;1;0];
test_k = [1;0;0;0;0;
1;0;0;0;0;
1;0;1;0;0;
1;1;0;0;0;
1;0;1;0;0];
test_L = [1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;1;1;1;0];
test_l = [1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;0;0;0;0;
1;1;1;0;0];
efekt1 = sim(net, test_A); %test sieci
efekt2 = sim(net, test_a);
[efekt1 efekt2]
if round(efekt1) <= 0 %zaokr¹glenie
disp('Ma³a litera');
else
disp('Wielka litera');
end
if round(efekt2) <= 0
disp('Ma³a litera');
else
disp('Wielka litera');
end