Perceptron learning




%% initial values setting clc; clear all; close all; t_data = [202 80 1; 163 100 1; 128 50 1; 450 44 -1; 350 80 -1; 300 44 -1]; % training data set w = [-6.5 41.5 1000]; % initial weight vector n = 0.0002; % learning rate hyper_x = 0:0.1:500; x = t_data; x(:,3) = 1; pos = t_data(1:3 , 1:2); neg = t_data(4:6 , 1:2); index = 1; sum_z = 0; | % iterate to get a prefer hyperplane while(1) t = t_data(index, 3); z = x(index, :)*w.'; z(z>0) = 1; z(z<0) = -1; plot(pos(:,1),pos(:,2), 'g+') hold on; plot(neg(:,1),neg(:,2), 'ro') d_w = n*(t-z)*x(index, :); w = w+d_w; hyper_y = (-w(3)-w(1)*hyper_x)/w(2); plot(hyper_x, hyper_y); hold off; index = index + 1; sum_z = sum_z + (t-z); % If an iteration is finished than initialize values if(index ==7) pause index = 1; if(sum_z ==0) disp('Classified all attributes!!'); break; else sum_z = 0; end end end |
댓글남기기