You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cognition/dim_activation_hierarchical.m

39 lines
1.3 KiB
Matlab

function [y,e,r,yTrace]=dim_activation_hierarchical(W,X,incFeedback,iterations,y)
epsilon1=1e-6;
epsilon2=1e-3;
if nargin<4 || isempty(iterations), iterations=75; end
if nargin<3 || isempty(incFeedback), incFeedback=0; end
numStages=length(W);
for s=1:numStages
[n{s},m{s}]=size(W{s});
if nargin<5 || isempty(y{s})
y{s}=zeros(n{s},1,'single'); %initialise prediction neuron outputs
end
r{s}=zeros(m{s},1,'single'); %initialise recurrent, top-down, inputs
%set feedback weights equal to feedforward weights normalized by maximum value:
V{s}=bsxfun(@rdivide,abs(W{s}),max(1e-6,max(abs(W{s}),[],2)));
V{s}=V{s}'; %avoid having to take transpose at each iteration
end
y{s+1}=[];
r{s+1}=[];
for t=1:iterations
x{1}=(X(:,min(t,size(X,2))));
for s=1:numStages
%update responses
if incFeedback
x{s}=[x{s};r{s+1}];%include driving top-down input from subsequent processing stage
%x{s}=[x{s};y{s+1}];%include modulatory top-down input from subsequent processing stage
end
r{s}=V{s}*y{s};
e{s}=x{s}./max(epsilon2,r{s});
y{s}=max(epsilon1,y{s}).*(W{s}*e{s});
%y{s}=y{s}.*(1+1.*r{s+1}); %old method of providing top-down modulation
x{s+1}=y{s}; %define feedforward input to subsequent processing stage
if nargout>3, yTrace{s}(:,t)=y{s}; end
end
end