%% Script file: Online Training (Hebbian Learning) % Example 1: T, G and F. %% Load the Data and Graph the Results. T1=[1 1 1 -1;-1 1 -1 -1;-1 1 -1 -1;-1 1 -1 -1]; T2=[-1 1 1 1;-1 -1 1 -1;-1 -1 1 -1;-1 -1 1 -1]; G1=[1 1 1 -1;1 -1 -1 -1; 1 1 1 -1 ; 1 1 1 -1]; G2=[-1 1 1 1;-1 1 -1 -1; -1 1 1 1; -1 1 1 1]; F1=[1 1 1 -1;1 1 -1 -1;1 -1 -1 -1;1 -1 -1 -1]; F2=[-1 1 1 1;-1 1 1 -1;-1 1 -1 -1;-1 1 -1 -1]; gg=colormap(gray); gg=gg(end:-1:1,:); %I'm reversing the usual grayscale values X=[T1(:) T2(:) G1(:) G2(:) F1(:) F2(:)]; %X is 16 x 6 T=[1 1 0 0 0 0;0 0 1 1 0 0;0 0 0 0 1 1]; figure(1) for j=1:6 subplot(2,3,j); imagesc(reshape(X(:,j),4,4)); colormap(gg); end %% This part is the linear neural network % Main code start NumPoints=6; NumEpochs=60; [W,b,EpochErr]=WidHoff2(X,T,NumEpochs); %% Output results Z=W*X+b*ones(1,NumPoints) figure(2) plot(EpochErr); % There is a better way to do this- I need to go from vector form of output % to the integer form: class 1, class 2, or class 3 for the confusion matrix code. for i=1:6 [v,idxT(i)]=max(T(:,i)); [v,idxZ(i)]=max(Z(:,i)); end % % This is the confusion matrix code from the k-NN material. % C=conf_matrix(idxT,idxZ,3);