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.
132 lines
4.0 KiB
Matlab
132 lines
4.0 KiB
Matlab
function task_switch_saccades()
|
|
%calculate fn(a,b), where a and b are real numbers (in a limited range) and fn is + or -
|
|
Ainputs=[-60:5:60];
|
|
Binputs=[-60:5:60];
|
|
F=[-1,1];
|
|
Rinputs=[min(Ainputs)+min(Binputs):10:max(Ainputs)+max(Binputs)];
|
|
Acentres=[-60:10:60];
|
|
Bcentres=[-60:10:60];
|
|
|
|
%define weights, to produce a 2d basis function network, where nodes have gaussian RFs.
|
|
W=[];
|
|
for f=F
|
|
for a=Acentres
|
|
for b=Bcentres
|
|
if f==-1
|
|
r=a-b;
|
|
else
|
|
r=a+b;
|
|
end
|
|
W=[W;code(f,F),code(a,Ainputs,10,0,0),code(b,Binputs,10,0,0),code(r,Rinputs,10,0,0)];
|
|
end
|
|
end
|
|
end
|
|
|
|
%normalise weights
|
|
W=bsxfun(@rdivide,W,max(1e-6,sum(W,2)));
|
|
[n,m]=size(W)
|
|
|
|
%define test cases
|
|
X=zeros(m,3);
|
|
null=zeros(1,length(Rinputs));
|
|
%function approximation:
|
|
X(:,1)=[code(1,F),code(0,Ainputs,10),code(30,Binputs,10),null]'; %0+30=?
|
|
X(:,2)=[code(1,F),code(0,Ainputs,10),code(-30,Binputs,10),null]'; %0-30=?
|
|
X(:,3)=[code(-1,F),code(0,Ainputs,10),code(30,Binputs,10),null]'; %0-30=?
|
|
|
|
for k=1:size(X,2)
|
|
x=X(:,k);
|
|
[y,e,r]=dim_activation(W,x);
|
|
figure(k),clf
|
|
plot_result(x,r,y,Ainputs,Binputs,Rinputs);
|
|
print(gcf, '-dpdf', ['task_switch_saccades',int2str(k),'.pdf']);
|
|
end
|
|
|
|
|
|
|
|
function c=code(x,X,sigma,noise,norm)
|
|
c=zeros(1,length(X),'single');
|
|
if length(X)==2
|
|
c(x==X)=1;
|
|
else
|
|
c=10.*exp(-(0.5/sigma.^2).*(x-X).^2)./sigma;
|
|
end
|
|
if nargin>3 && noise
|
|
c=single(imnoise(uint8(125.*c),'poisson'))./125; %add poisson noise
|
|
end
|
|
if nargin>4 && norm
|
|
c=c./sum(c);
|
|
end
|
|
|
|
|
|
|
|
function plot_result(x,r,y,Ainputs,Binputs,Rinputs)
|
|
xC=x(1:2);
|
|
rC=r(1:2);
|
|
x=x(3:end);r=r(3:end);
|
|
xA=x(1:length(Ainputs));
|
|
xB=x(length(Ainputs)+[1:length(Binputs)]);
|
|
xR=x(length(Ainputs)+length(Binputs)+[1:length(Rinputs)]);
|
|
rA=r(1:length(Ainputs));
|
|
rB=r(length(Ainputs)+[1:length(Binputs)]);
|
|
rR=r(length(Ainputs)+length(Binputs)+[1:length(Rinputs)]);
|
|
top=1.05;
|
|
|
|
attributes=['anti-saccade';
|
|
' saccade'];
|
|
|
|
axes('Position',[0.12,0.35,0.08,0.24]),
|
|
bar(xC,'k'),axis([0.5,2+0.5,0,top])
|
|
set(gca,'XTick',[1:2],'XTickLabel',[],'FontSize',18);
|
|
text([1:2]-0.06,-0.07.*ones(1,2),attributes,'HorizontalAlignment','right','VerticalAlignment','middle','rotation',90,'FontSize',18);
|
|
|
|
axes('Position',[0.22,0.35,0.24,0.24]),
|
|
bar(xA,1,'k'),axis([0.5,length(xA)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[4:9:length(xA)-3],'XTickLabel',Ainputs(4:9:length(xA)-3),'FontSize',18);
|
|
xlabel({'fixation';'position'})
|
|
plot_decode(xA,Ainputs);
|
|
|
|
axes('Position',[0.48,0.35,0.24,0.24]),
|
|
bar(xB,1,'k'),axis([0.5,length(xB)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[4:9:length(xB)-3],'XTickLabel',Binputs(4:9:length(xB)-3),'FontSize',18);
|
|
xlabel({'target';'position'})
|
|
plot_decode(xB,Binputs);
|
|
|
|
axes('Position',[0.74,0.35,0.24,0.24]),
|
|
bar(xR,1,'k'),axis([0.5,length(xR)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[4:9:length(xR)-3],'XTickLabel',Rinputs(4:9:length(xR)-3),'FontSize',18);
|
|
xlabel({'saccade';'position'})
|
|
plot_decode(xR,Rinputs);
|
|
|
|
|
|
axes('Position',[0.12,0.64,0.08,0.24]),
|
|
bar(rC,'FaceColor',[0,0.7,0]),axis([0.5,2+0.5,0,top])
|
|
set(gca,'XTick',[],'FontSize',18);
|
|
|
|
axes('Position',[0.22,0.64,0.24,0.24]),
|
|
bar(rA,1,'FaceColor',[0,0.7,0]),axis([0.5,length(rA)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[],'FontSize',18);
|
|
plot_decode(rA,Ainputs);
|
|
|
|
axes('Position',[0.48,0.64,0.24,0.24]),
|
|
bar(rB,1,'FaceColor',[0,0.7,0]),axis([0.5,length(rB)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[],'FontSize',18);
|
|
plot_decode(rB,Binputs);
|
|
|
|
axes('Position',[0.74,0.64,0.24,0.24]),
|
|
bar(rR,1,'FaceColor',[0,0.7,0]),axis([0.5,length(rR)+0.5,0,top])
|
|
set(gca,'YTick',[],'XTick',[],'FontSize',18);
|
|
plot_decode(rR,Rinputs);
|
|
|
|
set(gcf,'PaperSize',[18 16].*0.8,'PaperPosition',[0 0.5 18 15].*0.8,'PaperOrientation','Portrait');
|
|
|
|
|
|
function plot_decode(x,inputs)
|
|
hold on,
|
|
ml=sum(x'.*inputs)./sum(x);
|
|
mlconv=1+((ml-min(inputs)).*(length(inputs)-1)./(max(inputs)-min(inputs)));
|
|
plot(mlconv.*[1,1],[0,100],'w--','LineWidth',2),
|
|
plot(mlconv.*[1,1],[0,100],'k--'),
|
|
ax=axis;
|
|
text('Position',[mlconv,ax(4)*0.98],'String',num2str(round(ml.*10)/10),'HorizontalAlignment','center','VerticalAlignment','Bottom','FontSize',18,'FontWeight','bold');
|