Shailrshah

Perceptron Learning Rule

Jan 13th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.63 KB | None | 0 0
  1. //perceotron.sce
  2. x = [1 -2 0 -1; 0 1.5 -0.5 -1; -1 1 0.5 -1]'
  3. w = [1 -1 0 0.5]'
  4. k = 0.1
  5. d = [-1 -1 1]
  6. [r c] = size(x)
  7. while(1)
  8.     e = 0
  9.     for i=1:c
  10.         net = w'*x(: , i)
  11.         if net> 0
  12.             o = 1
  13.         else
  14.             o = -1
  15.         end
  16.         r = d(i)-o
  17.         e = e + 0.5*(d(i)-o)^2 //square error minimization
  18.         w=w+k*r.*x(:, i)
  19.     end
  20.     if e == 0
  21.         break
  22.     end
  23. end
  24. save('val.sod', 'w', 'x');
  25.  
  26. //perceptronrecall.sce
  27. load('val.sod', 'w', 'x')
  28. [r c] = size(x)
  29. for i=1:c
  30.     net = w'*x(: , i)
  31.     if net> 0
  32.             o = 1
  33.     else
  34.             o = -1
  35.     end
  36. end
Add Comment
Please, Sign In to add comment