Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 1.14 KB | None | 0 0
  1. function x = f(p)
  2.     if p >= 0 then
  3.         x = 1;
  4.     else
  5.         x = -1;    
  6.     end;
  7. endfunction
  8.  
  9. n = 50;
  10. K1 = 15*rand(2,n)+5;
  11. K2 = 15*rand(2,n)+25;
  12.  
  13. S = ones(1, 100);
  14. S = S*-1;
  15.  
  16. P = [K1,K2];
  17. X = cat(1, P, S);
  18. disp(X(3,1));
  19.  
  20. T = zeros(1, 2*n);
  21. for i=n+1 : 2*n
  22.     T(1, i) = 1;
  23. end;
  24.  
  25. W = rand(1,3);
  26.  
  27. wspolczynnik_uczenia = 0.5;
  28.  
  29. // PUNKTY
  30. plot(K1(1,:), K1(2,:),'rx', K2(1,:), K2(2,:),'bo');
  31.  
  32. for i=1:2*n
  33.    
  34.     blad = 1;
  35.    
  36.     i=1;
  37.     while blad ~= 0
  38.         disp(i);
  39.         i = i+1;
  40.         pobudzenie = 0;
  41.         for j=1:3
  42.             pobudzenie = pobudzenie + (W(j) * X(j,i));
  43.         end;
  44.        
  45.         blad = T(i) - f(pobudzenie);
  46.         for j=1:3
  47.             W(j) = W(j) + (wspolczynnik_uczenia * blad * X(j, i));
  48.         end;
  49.     end;
  50.    
  51.  
  52.    
  53. end;
  54.  
  55.  
  56. for i=1:3
  57.     disp("Waga " + string(i) + " = " + string(W(i)));
  58. end;
  59.  
  60.  
  61.  
  62.  
  63. // WYKRES
  64. x = 15 : 0.1 : 25;
  65. y = -(W(2)/W(3))*x - (W(1)/W(3));
  66. plot(x, y);
  67.  
  68. // przed uczeniem
  69. k=0;
  70. for i=-10:0.1:10
  71. k=k+1;
  72. XX(k)=i;
  73. YY(k)=-((W(2)/W(3))*i)-(W(1)*1)/W(3);
  74. end
  75.  
  76. plot2d(XX, YY, style=[color("green")])//linia decyzyjna przed uczeniem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement