Instar Learning Law



function w = instar_law(I,N,time,dt)

% w = instar_law(I,N,time,dt)
% computes the dynamics of weights of feedforward connections from an
% Input field (F1) to a Coding field (F2) according to the instar learning
% law
%
% Grossberg, S. (1976). Adaptive pattern classification and universal
% recoding, I: Parallel development and coding of neural feature detectors.
% Biological Cybernetics, 23, 121-134.
%
% w: Weights from Input to Coding fields (F1-to-F2)
%
% I: Input activation (1xM, where M is the number of input nodes;
% each input element is assumed to be normalized between 0 and 1)
%
% N: Number of coding nodes
%
% time: Time (in secs) for which the weight dynamics are calculated
%
% dt: Time step (in secs) for numerical integration % forward Euler's
% method is employed
%

if (sum(size(I))-1~=length(I))|(size(I,1)~=1)
    error('I should be a row vector')
end
if length(I)==0
    error('I should have atleast one element/feature')
end
if (max(I)>1)|(min(I)<0)
    error('Elements in I should be between 0 and 1')
end
if N==0
    error('N should be a positive integer')
end
if dt>time
    error('time should be greater than dt')
end

% Random initialization of the weights from Input to Coding fields
w=rand(length(I),N,ceil(time/dt)+1);

for t=2:ceil(time/dt)+1

    % Computing activations of coding nodes at each time step
    for j=1:N
        y(j)=sum(w(:,j,t-1)'.*I);
    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Winner-take-all (WTA) coding
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Finding the WTA node
    J=find(y==max(y));
    % If multiple nodes have the same maximum activation, then randomly choose
    % among them a winner
    Jw=randperm(length(J));
    J=J(Jw(1));

    % Algorithmically suppressing other nodes
    for j=1:N
        if j~=J
            y(j)=0;
        end
    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Instar learning law
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    % Weights' update
    w(:,:,t)=w(:,:,t-1)+dt*(repmat(y,length(I),1).*(repmat(I,N,1)'-w(:,:,t-1)));

end

for k=1:length(I)
    figure
    plot(0:dt:time,squeeze(w(k,J,:)))
    axis([0 time 0 1])
    xlabel('Time (s)','Fontsize',12)
    ylabel('Weight strength','Fontsize',12)
    title(['Instar weight from F1 node #' num2str(k) ' to F2 node'],'Fontsize',12)
    box off
end

return