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.

65 lines
2.0 KiB
Matlab

function [H]=ism_dim_conv(Fmaps,Locations,H)
numCodebookEntries=length(Fmaps);
numClasses=length(Locations);
[a,b]=size(Fmaps{1}); %size of input image
%set parameters
epsilon1=1e-6;
epsilon2=1e-3;
iterations=50;
if nargin<3 || isempty(H), %initialise prediction neuron outputs to zero
H=zeros(a,b,numClasses,'single');
end
val=zeros(0,numCodebookEntries);
for i=1:numCodebookEntries
val(i)=max(max(Fmaps{i}));
end
includedCodebookEntries=find(val>0.001);
%set feedback weights equal to feedforward weights normalized by maximum value
for c=1:numClasses
%calc normalisation values by taking into account all weights contributing to each RF type
maxVal=0;
for i=includedCodebookEntries
maxVal=max(maxVal,max(max(abs(Locations{c}{i}))));
end
%apply normalisation to calculate feedback weight values, and rotate feedback masks
for i=includedCodebookEntries
v{c}{i}=abs(Locations{c}{i})./max(1e-6,maxVal);
v{c}{i}=rot90(v{c}{i},2);
end
end
%iterate DIM equations to determine neural responses
for t=1:iterations
%update error-detecting neuron responses
for i=includedCodebookEntries
%calculate predictive reconstruction of the input
recon=single(0);
for c=1:numClasses
recon=recon+conv2(H(:,:,c),v{c}{i},'same');
%recon=recon+convnfft(H(:,:,c),v{c}{i},'same');
end
%calc error between reconstruction and actual input
%E{i}=Fmaps{i}./max(epsilon2,recon);
E{i}=Fmaps{i}./(epsilon2+recon);
end
%update prediction neuron responses
for c=1:numClasses
%convolve image error maps with vote weights in order to find the accumulator
%array containing a count of votes
input=single(0);
for i=includedCodebookEntries
input=input+conv2(E{i},Locations{c}{i},'same');
%input=input+convnfft(E{i},Locations{c}{i},'same');
end
%modulate prediction neuron responses using current feedforward input
%H(:,:,c)=max(epsilon1,H(:,:,c)).*input;
H(:,:,c)=(epsilon1+H(:,:,c)).*input;
end
end