//// Linear associator with Hebb and weight decay: PCA a la Oja clear; clf; w=[0.1;0.4]; // (arbitrary) starting value a=-%pi/6; rot=[cos(a) sin(a);-sin(a) cos(a)]; // rotation matrix //// Training for i=1:1000 rPre=0.05*rand(2,1,'normal').*[4;1]; rPre=rot*rPre; //training examples plot(rPre(1),rPre(2),'.') // plot training point rPost=w'*rPre; // network update w=w+0.1*rPost*(rPre-rPost*w); // Hebbian training w_traj(:,i)=w; // recording of weight history end //// Plotting results plot(w_traj(1,:),w_traj(2,:),'r') plot([0 w(1)],[0 w(2)],'k','linewidth',2) plot([-1 1],[0 0],'k'); plot([0 0],[-1 1],'k') axis([-1 1 -1 1]);