function [W,b,err]=WidHoff(X,T,NumEpochs) % function [W,b,err]=WidHoff(X,T) % Data in X should be dimension x num of points % Target data should be dimension x num of points % OUTPUT: Weight matrix W is dim(T) x dim(X), and b is dim(T) % % What's the difference between this file and WidHoff, WidHoff1? % In this example, we allow passes through the data (Epochs) % Incoming data is not randomized in each pass. % We use a predetermined alpha (alpha not passed as an argument) % % Some error checks to be sure data is input correctly and initializations: [rX,cX]=size(X); [rT,cT]=size(T); if cX~=cT error('Error in inputs: Number of points do not match.\n'); end NumPoints=cX; W=randn(rT,rX); b=randn(rT,1); for i=1:NumEpochs % Main Code: for j=1:NumPoints ThisOut=W*X(:,j)+b; ThisErr=T(:,j)-ThisOut; err(i,j)=norm(ThisErr); alpha=0.9999/(X(:,j)'*X(:,j)); %Update the weights and biases using Widrow-Hoff: W=W+alpha*ThisErr*X(:,j)'; b=b+alpha*ThisErr; end end