function [W,b,err,dW]=WidHoff(X,T) % 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) % 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=zeros(rT,rX); b=zeros(rT,1); err=zeros(1,cX); dW=zeros(NumPoints,rX); dW(1,:)=W; % Main Code: for j=1:NumPoints ThisOut=W*X(:,j)+b; ThisErr=T(:,j)-ThisOut; err(j)=norm(ThisErr); alpha=0.08; %Update the weights and biases using Widrow-Hoff: W=W+alpha*ThisErr*X(:,j)'; b=b+alpha*ThisErr; dW(j+1,:)=W; end