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.
53 lines
1.6 KiB
Matlab
53 lines
1.6 KiB
Matlab
function [y,e,r,ytrace,rtrace]=dim_activation_hierarchical(W,xtrace,V,interconnects,y,iterations)
|
|
epsilon1=1e-6;
|
|
epsilon2=1e-4;
|
|
if nargin<3 || isempty(V), initV=1; else, initV=0; end
|
|
if nargin<5 || isempty(y), initY=1; else, initY=0; end
|
|
if nargin<6 || isempty(iterations), iterations=50; end
|
|
|
|
numStages=length(W);
|
|
for s=1:numStages
|
|
[n(s),m(s)]=size(W{s});
|
|
|
|
if initV
|
|
%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)));
|
|
end
|
|
V{s}=V{s}'; %avoid having to take transpose at each iteration
|
|
|
|
if initY
|
|
y{s}=zeros(n(s),1,'single'); %initialise prediction neuron outputs
|
|
end
|
|
|
|
%pre-allocate arrays for speed:
|
|
if nargout>3
|
|
ytrace{s}=zeros(n(s),iterations,'single');
|
|
end
|
|
if nargout>4
|
|
rtrace{s}=zeros(m(s),iterations,'single');
|
|
end
|
|
end
|
|
|
|
for t=1:iterations
|
|
for s=1:numStages
|
|
xind=min(t,size(xtrace{s},2));%use last column of x values if t is larger than number of columns
|
|
if t>1
|
|
%provide input from other processing stages by copying part of the that stage's reconstruction to form part of the input to this stage
|
|
for s2=1:numStages
|
|
xtrace{s}(interconnects{s,s2},xind)=r{s2}(interconnects{s2,s});
|
|
end
|
|
end
|
|
|
|
%update responses
|
|
r{s}=V{s}*y{s};
|
|
%e{s}=xtrace{s}(:,xind)./(epsilon2+r{s});
|
|
e{s}=xtrace{s}(:,xind)./max(epsilon2,r{s});
|
|
%y{s}=(epsilon1+y{s}).*(W{s}*e{s});
|
|
y{s}=max(epsilon1,y{s}).*(W{s}*e{s});
|
|
|
|
if nargout>3, ytrace{s}(:,t)=y{s}; end
|
|
if nargout>4, rtrace{s}(:,t)=r{s}; end
|
|
|
|
end
|
|
end
|