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/categorise_nosofsky_etal_ex...

81 lines
2.3 KiB
Matlab

function categorise_nosofsky_etal_expt2()
%Nosofsky, Clark and Shin (1989) expt 2
human{1}=[0.113,0.94,0.92,0.133;
0.08,0.953,0.92,0.167;
0.06,0.867,0.773,0.113;
0.04,0.413,0.327,0.04];
human{2}=[0.379,0.436,0.543,0.164;
0.793,0.893,0.857,0.314,
0.814,0.836,0.836,0.15;
0.229,0.279,0.257,0.036];
Xfeatures=[1:4];
Xclass=[1,2];
%define weights
loprec=1;
hiprec=4;
W{1}(1,:)=[code(2.33,Xfeatures,loprec),code(2.66,Xfeatures,loprec),code(1,Xclass)];
W{1}(2,:)=[code(4,Xfeatures,hiprec),code(2.5,Xfeatures,loprec),code(2,Xclass)];
W{1}(3,:)=[code(2.5,Xfeatures,loprec),code(1,Xfeatures,hiprec),code(2,Xclass)];
W{1}(4,:)=[code(1,Xfeatures,hiprec),code(2.5,Xfeatures,loprec),code(2,Xclass)];
W{2}=W{1};
W{2}(4,:)=[code(2.5,Xfeatures,loprec),code(4,Xfeatures,hiprec),code(2,Xclass)];
for rule=1:length(W)
%normalise weights
W{rule}=bsxfun(@rdivide,W{rule},max(1e-6,sum(W{rule},2)));
[n,m]=size(W{rule})
%simulate categorization expt
for i=Xfeatures
for j=Xfeatures
x=[code(i,Xfeatures),code(j,Xfeatures),0*Xclass]';
[y,e,r]=dim_activation(W{rule},x);
predict=r(m-(length(Xclass)-1):m)';
category(j,i)=sum(Xclass.*predict)./sum(predict);
end
end
%plot results
category=flipud(category);
figure(2*rule-1),clf
imagesc(2-category,[0,1])
colormap('gray')
axis('equal','tight')
set(gca,'XTick',Xfeatures,'YTick',Xfeatures,'YTickLabel',int2str(fliplr(Xfeatures)'),'FontSize',17)
xlabel('feature 1');ylabel('feature 2')
set(gcf,'PaperSize',[8 8],'PaperPosition',[0 0.25 8 7.5],'PaperOrientation','Portrait');
print(gcf, '-dpdf',['categorise_nosofsky_etal_expt2_rule',int2str(rule),'_model.pdf']);
figure(2*rule),clf
imagesc(human{rule},[0,1])
colormap('gray')
axis('equal','tight')
set(gca,'XTick',Xfeatures,'YTick',Xfeatures,'YTickLabel',int2str(fliplr(Xfeatures)'),'FontSize',17)
xlabel('feature 1');ylabel('feature 2')
set(gcf,'PaperSize',[8 8],'PaperPosition',[0 0.25 8 7.5],'PaperOrientation','Portrait');
print(gcf, '-dpdf',['categorise_nosofsky_etal_expt2_rule',int2str(rule),'_human.pdf']);
end
function c=code_all(x,X)
c=[];
for i=1:length(x)
c=[c,code(x(i),X)];
end
function c=code(x,X,precision)
if nargin<3 || isempty(precision)
precision=2;
end
c=zeros(1,length(X));
c=exp(-precision.*(x-X).^2);
c=c./sum(c);