%% Examples of using a Linear Network %% First, use our Widrow-Hoff function: X=[1,1,2,2,-1,-2,-1,-2;1,2,-1,0,2,1,-1,-2]; T=[-1,-1,-1,-1,1,1,1,1;-1,-1,1,1,-1,-1,1,1]; lr=0.04; iters=250; [W,b,EpochErr]=wid_hoff1(X',T',lr,iters); %% Second, using Matlab's toolbox: X=[1,1,2,2,-1,-2,-1,-2;1,2,-1,0,2,1,-1,-2]; T=[-1,-1,-1,-1,1,1,1,1;-1,-1,1,1,-1,-1,1,1]; net2=linearlayer(0,0.04); net2=train(net2,X,T); net2.IW{1} net2.b{1} %% Here are the plotting commands tt=linspace(-2,2); y1=(-W(1,1)*tt-b(1))/W(1,2); y2=(-W(2,1)*tt-b(2))/W(2,2); % Here, I'll give more complicated commands to plot the different classes % with different symbols: plot(X(1,1:2),X(2,1:2),'ko'); %Plot Class 1 hold on; %Do not erase the graph. plot(X(1,3:4),X(2,3:4),'m*'); %Plot Class 2 plot(X(1,5:6),X(2,5:6),'g^'); %Plot Class 3 plot(X(1,7:8),X(2,7:8),'bo'); %Plot Class 4 plot(tt,y1,tt,y2); axis([-2.5,2.5,-2.5,2.5]); %Fix the viewing window hold off; % The simpler plotting commands are commented out below: %tt=linspace(-2,2); %y1=(-W(1,1)*tt-b(1))/W(1,2); %y2=(-W(2,1)*tt-b(2))/W(2,2); %plot(X(1,:),X(2,:),'x',tt,y1,tt,y2); %axis([-2,2,-2,2]);