Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = f(p)
- if p >= 0 then
- x = 1;
- else
- x = -1;
- end;
- endfunction
- n = 50;
- K1 = 15*rand(2,n)+5;
- K2 = 15*rand(2,n)+25;
- S = ones(1, 100);
- S = S*-1;
- P = [K1,K2];
- X = cat(1, P, S);
- disp(X(3,1));
- T = zeros(1, 2*n);
- for i=n+1 : 2*n
- T(1, i) = 1;
- end;
- W = rand(1,3);
- wspolczynnik_uczenia = 0.5;
- // PUNKTY
- plot(K1(1,:), K1(2,:),'rx', K2(1,:), K2(2,:),'bo');
- for i=1:2*n
- blad = 1;
- i=1;
- while blad ~= 0
- disp(i);
- i = i+1;
- pobudzenie = 0;
- for j=1:3
- pobudzenie = pobudzenie + (W(j) * X(j,i));
- end;
- blad = T(i) - f(pobudzenie);
- for j=1:3
- W(j) = W(j) + (wspolczynnik_uczenia * blad * X(j, i));
- end;
- end;
- end;
- for i=1:3
- disp("Waga " + string(i) + " = " + string(W(i)));
- end;
- // WYKRES
- x = 15 : 0.1 : 25;
- y = -(W(2)/W(3))*x - (W(1)/W(3));
- plot(x, y);
- // przed uczeniem
- k=0;
- for i=-10:0.1:10
- k=k+1;
- XX(k)=i;
- YY(k)=-((W(2)/W(3))*i)-(W(1)*1)/W(3);
- end
- plot2d(XX, YY, style=[color("green")])//linia decyzyjna przed uczeniem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement