%% TAKE HOME QUIZ (Quiz 2) % Name(s): %% Question 1: % First, solve the exercise in class using Hebbian Learning (Widrow-Hoff % learning rule 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]; alpha=0.04; %Initialize W, b: W=eye(2); b=[1;1]; % Fill in the following for Question 1: (Hebbian Learning for W, b) % You should do the update 200 times, and each time, choose one % of the 8 data points at random. % Leave this part- It plots the output using your W and b: figure(1) xx=linspace(-3,3); yy=W*X+repmat(b,1,8); plot(T(1,1),T(2,1),'r^',yy(1,1:2),yy(2,1:2),'r*'); hold on plot(T(1,3),T(2,3),'go',yy(1,3:4),yy(2,3:4),'g*'); plot(T(1,5),T(2,5),'bp',yy(1,5:6),yy(2,5:6),'b*'); plot(T(1,7),T(2,7),'ms',yy(1,7:8),yy(2,7:8),'m.'); % And the decision boundaries: L1=(-W(1,1)/(W(1,2)))*xx-(b(1)/W(1,2)); L2=(-W(2,1)/(W(2,2)))*xx-(b(2)/W(2,2)); plot(xx,L1,xx,L2); axis([-2 2 -2 2]); hold off W b %% Question 2: % Solve the problem using linear algebra. % Be sure to convert your answer above to a matrix W % and a vector b for the graphic routines below (nothing % past here needs to be edited) % Leave this part- It plots the output using your new W and b: figure(2) xx=linspace(-3,3); yy=W*X+repmat(b,1,8); plot(T(1,1),T(2,1),'r^',yy(1,1:2),yy(2,1:2),'r*'); hold on plot(T(1,3),T(2,3),'go',yy(1,3:4),yy(2,3:4),'g*'); plot(T(1,5),T(2,5),'bp',yy(1,5:6),yy(2,5:6),'b*'); plot(T(1,7),T(2,7),'ms',yy(1,7:8),yy(2,7:8),'m.'); % And the decision boundaries: L1=(-W(1,1)/(W(1,2)))*xx-(b(1)/W(1,2)); L2=(-W(2,1)/(W(2,2)))*xx-(b(2)/W(2,2)); plot(xx,L1,xx,L2); axis([-2 2 -2 2]); hold off W b