-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauf63.m
70 lines (59 loc) · 1.02 KB
/
auf63.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
clear all;
close all;
clc;
% Finde alle möglichen Inputs
A = 0;
B = 1;
s = 2;
for i=1:8
tmp = [A;B];
A = [zeros(s,1),tmp];
B = [ones(s,1),tmp];
s = s*2;
end
datasize = 512;
X = [A;B];
% Finde Lables
y = zeros(datasize,1);
y(find(X(:,5)==0)) = 1;
y(1) = 0;
X = [ones(datasize,1),X];
% Lernen des Gewichtsvektors w
w = rand(10,1);
y_predict = X * w;
idx = find(y_predict < 0);
y_predict = ones(datasize,1);
y_predict(idx,:) = 0;
count = 0;
while(any(y - y_predict))
count = count + 1;
idx = find(y-y_predict,1,'first');
if(y(idx)==0);
w = w - X(idx,:)';
else
w = w + X(idx,:)';
endif
y_predict = X * w;
idx = find(y_predict < 0);
y_predict = ones(datasize,1);
y_predict(idx,:) = 0;
endwhile
%a circle
[xs,ys]=meshgrid(-100:100);
I=zeros(size(xs));
I(sqrt(xs.^2+ys.^2)<(0.3*size(xs,1)))=1;
%display
figure;
imagesc(I); colormap('gray'); axis equal off;
for i=1:199
for j=1:199
v = [1,I(i,j:j+2),I(i+1,j:j+2),I(i+2,j:j+2)];
v = v * w;
if(v<0)
kante = 0;
else
kante = 1;
endif
E(i,j) = kante;
end
end