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.
106 lines
2.9 KiB
Matlab
106 lines
2.9 KiB
Matlab
function categorise_medin_schaffer_expt2()
|
|
|
|
%Medin & Schaffer (1978) Expt 2
|
|
training=[1,1,1,0;
|
|
1,0,1,0;
|
|
1,0,1,1;
|
|
1,1,0,1;
|
|
0,1,1,1;
|
|
1,1,0,0;
|
|
0,1,1,0;
|
|
0,0,0,1;
|
|
0,0,0,0];
|
|
class=[1;1;1;1;1;0;0;0;0];
|
|
testing=[1,0,0,1;
|
|
1,0,0,0;
|
|
1,1,1,1;
|
|
0,0,1,0;
|
|
0,1,0,1;
|
|
0,0,1,1;
|
|
0,1,0,0];
|
|
Xfeatures=[0,1];
|
|
Xclass=[0,1];
|
|
|
|
%define weights
|
|
|
|
W{1}=zeros(4,4*length(Xfeatures)+length(Xclass));
|
|
%rule 1: if feature 1=1, than class 1
|
|
t=[1,0.5,0.5,0.5];
|
|
W{1}(1,:)=[code_all(t,Xfeatures),code(1,Xclass)];
|
|
%exception: 5th training item
|
|
W{1}(2,:)=[code_all(training(5,:),Xfeatures),code(class(5),Xclass)];
|
|
%rule 2: if feature 1=0, than class 0
|
|
t=[0,0.5,0.5,0.5];
|
|
W{1}(3,:)=[code_all(t,Xfeatures),code(0,Xclass)];
|
|
%exception: 6th training item
|
|
W{1}(4,:)=[code_all(training(6,:),Xfeatures),code(class(6),Xclass)];
|
|
|
|
W{2}=zeros(4,4*length(Xfeatures)+length(Xclass));
|
|
%rule 1: if feature 3=1, than class 1
|
|
t=[0.5,0.5,1,0.5];
|
|
W{2}(1,:)=[code_all(t,Xfeatures),code(1,Xclass)];
|
|
%exception: 4th training item
|
|
W{2}(2,:)=[code_all(training(4,:),Xfeatures),code(class(4),Xclass)];
|
|
%rule 2: if feature 3=0, than class 0
|
|
t=[0.5,0.5,0,0.5];
|
|
W{2}(3,:)=[code_all(t,Xfeatures),code(0,Xclass)];
|
|
%exception: 7th training item
|
|
W{2}(4,:)=[code_all(training(7,:),Xfeatures),code(class(7),Xclass)];
|
|
|
|
W{3}=[];
|
|
for c=0:1
|
|
%one prediction neuron for each prototype
|
|
ind=find(class==c);
|
|
W{3}=[W{3};[code_all(mean(training(ind,:)),Xfeatures),code(c,Xclass)]];
|
|
end
|
|
|
|
|
|
for wType=1:length(W)
|
|
%normalise weights
|
|
W{wType}=bsxfun(@rdivide,W{wType},max(1e-6,sum(W{wType},2)));
|
|
[n,m]=size(W{wType})
|
|
|
|
%simulate categorization expt
|
|
for k=1:size(testing,1)
|
|
x=[code_all(testing(k,:),Xfeatures),0*Xclass]';
|
|
[y,e,r]=dim_activation(W{wType},x);
|
|
|
|
predict=r(m-(length(Xclass)-1):m)';
|
|
category(wType,k)=sum(Xclass.*predict)./sum(predict);
|
|
end
|
|
end
|
|
|
|
%plot results
|
|
figure(1),clf
|
|
axes('Position',[0.16,0.15,0.6,0.6]),
|
|
plot(category(1,:),'b-s','LineWidth',2,'MarkerFaceColor','b','MarkerSize',8),hold on
|
|
plot(category(2,:),'-d','LineWidth',2,'Color',[0,0.7,0],'MarkerFaceColor',[0,0.7,0],'MarkerSize',8),
|
|
plot(category(3,:),'r-o','LineWidth',2,'MarkerFaceColor','r','MarkerSize',8),
|
|
axis([0.5,7.5,0,1])
|
|
legend(['rule+exception 1 ';
|
|
'rule+exception 2 ';
|
|
'prototype '],'Location',[0.362,0.85,0.2,0.06]);
|
|
hold on, plot([0,10],[0.5,0.5],'k--')
|
|
set(gca,'XTick',[1:7],'XTickLabel',[1:7],'FontSize',12)
|
|
xlabel('transfer item');ylabel('probability of A')
|
|
set(gcf,'PaperSize',[7 8],'PaperPosition',[0.25 0 8 8],'PaperOrientation','Portrait');
|
|
print(gcf, '-dpdf','categorise_medin_schaffer_expt2.pdf');
|
|
|
|
|
|
|
|
|
|
|
|
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);
|