Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //perceotron.sce
- x = [1 -2 0 -1; 0 1.5 -0.5 -1; -1 1 0.5 -1]'
- w = [1 -1 0 0.5]'
- k = 0.1
- d = [-1 -1 1]
- [r c] = size(x)
- while(1)
- e = 0
- for i=1:c
- net = w'*x(: , i)
- if net> 0
- o = 1
- else
- o = -1
- end
- r = d(i)-o
- e = e + 0.5*(d(i)-o)^2 //square error minimization
- w=w+k*r.*x(:, i)
- end
- if e == 0
- break
- end
- end
- save('val.sod', 'w', 'x');
- //perceptronrecall.sce
- load('val.sod', 'w', 'x')
- [r c] = size(x)
- for i=1:c
- net = w'*x(: , i)
- if net> 0
- o = 1
- else
- o = -1
- end
- end
Add Comment
Please, Sign In to add comment