% hebb.m - script to do hebbian learning
%
% you must first load data2d.mat

% data array
X=D1;

[N K]=size(X);

% plot data
plot(X(1,:),X(2,:),'.')                     
axis image
hold on

% initialize weights
w=randn(N,1);        

% plot weight vector
h=plot([0 w(1)],[0 w(2)],'r',...
       'EraseMode','xor','LineWidth',2);      
  
num_trials=100;
eta=0.1/K;

for t=1:num_trials

  % compute neuron output for all data (can be done as one line)
  % compute dw: Hebbian learning rule 
  % update weight vector by dw

  set(h,'XData',[0 w(1)],'YData',[0 w(2)]);  % replot weight vector
  drawnow
  pause(0.25)
  
end

hold off
