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.
112 lines
3.4 KiB
Matlab
112 lines
3.4 KiB
Matlab
function task_switch_mapping()
|
|
%Implements task described in Salinas 2004
|
|
Context=[1:5]; %magenta,orange,cyan,green,yellow
|
|
Orient=[1:2]; %horiz/vert
|
|
Colour=[1:2]; %red/blue
|
|
Resp=[-60:5:60];
|
|
|
|
null=zeros(1,2);
|
|
%define weights, to produce a basis function network.
|
|
W=[];
|
|
for f=Context
|
|
for o=Orient
|
|
for c=Colour
|
|
if f==1, r=(o-1.5).*40;
|
|
elseif f==2, r=-(o-1.5).*40;
|
|
elseif f==3, r=(c-1.5).*80;
|
|
elseif f==4, r=-(c-1.5).*80;
|
|
else r=0;
|
|
end
|
|
W=[W;code(f,Context,0),code(o,Orient,0),code(c,Colour,0),code(r,Resp,6,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(Resp));
|
|
X(:,1)=[code(1,Context,0),code(1,Orient,0),code(1,Colour,0),null]'; %magenta-horiz/red=?
|
|
X(:,2)=[code(2,Context,0),code(1,Orient,0),code(1,Colour,0),null]'; %orange-horiz/red=?
|
|
X(:,3)=[code(3,Context,0),code(1,Orient,0),code(1,Colour,0),null]'; %cyan-horiz/red=?
|
|
X(:,4)=[code(4,Context,0),code(1,Orient,0),code(1,Colour,0),null]'; %green-horiz/red=?
|
|
X(:,5)=[code(5,Context,0),code(1,Orient,0),code(1,Colour,0),null]'; %yellow-horiz/red=?
|
|
X(:,6)=[code(1,Context,0),code(2,Orient,0),code(2,Colour,0),null]'; %magenta-vert/blue=?
|
|
|
|
for k=1:size(X,2)
|
|
x=X(:,k);
|
|
[y,e,r]=dim_activation(W,x);
|
|
figure(k),clf
|
|
plot_result(x,r,y,Resp);
|
|
print(gcf, '-dpdf', ['task_switch_mapping',int2str(k),'.pdf']);
|
|
end
|
|
|
|
|
|
|
|
function c=code(x,X,sigma,noise,norm)
|
|
c=zeros(1,length(X),'single');
|
|
if sigma==0
|
|
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,Resp)
|
|
attributes=['magenta';
|
|
' orange';
|
|
' cyan';
|
|
' green';
|
|
' yellow';
|
|
' horiz.';
|
|
' vert.';
|
|
' red';
|
|
' blue'];
|
|
|
|
mIn=size(attributes,1);
|
|
xIn=x(1:mIn);
|
|
xOut=x(1+mIn:end);
|
|
rIn=r(1:mIn);
|
|
rOut=r(1+mIn:end);
|
|
top=1.05;
|
|
|
|
axes('Position',[0.12,0.38,0.35,0.24])
|
|
bar(xIn,'k'),axis([0.5,mIn+0.5,0,top])
|
|
set(gca,'XTick',[1:mIn],'XTickLabel',[],'FontSize',14);
|
|
text([1:mIn]-0.06,-0.07.*ones(1,mIn),attributes,'HorizontalAlignment','right','VerticalAlignment','middle','rotation',90,'FontSize',14);
|
|
|
|
axes('Position',[0.48,0.38,0.45,0.24])
|
|
bar(xOut,1,'k'),axis([0.5,length(Resp)+0.5,0,top]);plot_decode(xOut,Resp);
|
|
set(gca,'XTick',[5:4:22],'XTickLabel',[-40:20:40],'YTick',[],'FontSize',14);
|
|
xlabel('saccade position')
|
|
|
|
axes('Position',[0.12,0.68,0.35,0.24])
|
|
bar(rIn,'FaceColor',[0,0.7,0]),axis([0.5,mIn+0.5,0,top])
|
|
set(gca,'XTick',[1:mIn],'XTickLabel',[],'FontSize',14);
|
|
|
|
axes('Position',[0.48,0.68,0.45,0.24])
|
|
bar(rOut,1,'FaceColor',[0,0.7,0]);axis([0.5,length(Resp)+0.5,0,top]);plot_decode(rOut,Resp)
|
|
set(gca,'XTick',[],'YTick',[],'FontSize',14);
|
|
|
|
|
|
%set(gcf,'PaperSize',[20 6],'PaperPosition',[0.3 -0.2 20 6],'PaperOrientation','Portrait');
|
|
set(gcf,'PaperSize',[14 6],'PaperPosition',[0.3 -0.2 14 6],'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,0.98.*ax(4)],'String',num2str(round(ml.*10)/10),'HorizontalAlignment','center','VerticalAlignment','Bottom','FontSize',14,'FontWeight','bold');
|