%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
%%%%  File:   B_approx.notes.txt
%%%%  Author: Alexander Petrov, http://alexpetrov.com
%%%%  Date:   Feb 10, 2006
%%%%
%%%%  Script generating the figures in A. Petrov's (2006)
%%%%  two-page abstract in the Proceedings of the International
%%%%  Conference on Cognitive Modeling (ICCM06).
%%%%
%%%%  The Matlab functions BASE_ACT.M, B_APPROX.M, and PLOT_ACT.M
%%%%  are available on-line at http://alexpetrov.com/softw/
%%%%
%%%%  To re-create the figures, open this text in the Matlab editor,
%%%%  highlight the blocks, and execute them by pressing F9.
%%%%


%%--  Figure 1 in the ICCM06 abstract paper
%%    See work/papers/BLAct/BLAct-ICCM06.doc
clear all ;
k=[Inf 2 1 0];l={'exact','k=2','k=1','k=0'};Nk=length(k);
grid=[0.1:0.5:80]';ax1=[-1 80 -1 2];ax2=[-1 80 -1 1];xtick=[0:10:80];
p=1;refs{p}=[0 5 10 30:5:60]';ttl{p}='uniform';
B{p}=plot_act(refs{p},grid,k);err{p}=B{p}-repmat(B{p}(:,1),1,Nk);
Ex=B{p}(:,1);K2=B{p}(:,2);K1=B{p}(:,3);K0=B{p}(:,4);
clf;subplot(2,1,1);h=plot(grid,K0,'ko',grid,K1,'k-',grid,Ex,'k:');axis(ax1);
set(h(1),'MarkerSize',3);set(gca,'xtick',xtick,'ytick',[-1:.5:2]);
ylabel('Base-level activation');legend('k=0','k=1','Exact',4);  %xlabel('Time (arbitrary units)');
Ex=err{p}(:,1);K2=err{p}(:,2);K1=err{p}(:,3);K0=err{p}(:,4);
subplot(2,1,2);h=plot(grid,K0,'ko',grid,K1,'k-',grid,Ex,'k:');axis(ax2);
set(h(1),'MarkerSize',3);set(gca,'xtick',xtick,'ytick',[-1:.5:1]);
xlabel('Time (arbitrary units)');ylabel('Approximation error');legend('k=0','k=1',4);
% Set page width = 5in, height = 5in. Copy-and-paste to MS Word.
% Format Word figure size = 75%, keep aspect ratio.

%%--  Figure 2 in the ICCM06 abstract paper
p=2;refs{p}=[0;sort(rand(40,1)).*30;50+sort(rand(20,1)).*10];ax1=[-1 80 .5 3.5];
B{p}=plot_act(refs{p},grid,k);err{p}=B{p}-repmat(B{p}(:,1),1,Nk);
Ex=B{p}(:,1);K2=B{p}(:,2);K1=B{p}(:,3);K0=B{p}(:,4);
clf;subplot(2,1,1);h=plot(grid,K0,'ko',grid,K1,'k-',grid,Ex,'k:');axis(ax1);
set(h(1),'MarkerSize',3);set(gca,'xtick',xtick,'ytick',[-1:.5:2]);
ylabel('Base-level activation');legend('k=0','k=1','Exact',4);  %xlabel('Time (arbitrary units)');
Ex=err{p}(:,1);K2=err{p}(:,2);K1=err{p}(:,3);K0=err{p}(:,4);
subplot(2,1,2);h=plot(grid,K0,'ko',grid,K1,'k-',grid,Ex,'k:');axis(ax2);
set(h(1),'MarkerSize',3);set(gca,'xtick',xtick,'ytick',[-1:.5:1]);
xlabel('Time (arbitrary units)');ylabel('Approximation error');legend('k=0','k=1',4);
% Set page width = 5in, height = 5in. Copy-and-paste to MS Word.
% Format Word figure size = 75%, keep aspect ratio.



%%%%%%% Exploratory stuff, for extra credit... ;-)

k=[Inf 2 1 0];l={'exact','k=2','k=1','k=0'};Nk=length(k);
grid=[0.1:0.5:70]';ax1=[0 70 -1 2];ax2=[0 70 -.8 .8];
refs{1}=[0:5:50]';ttl{1}='uniform';
refs{2}=(refs{1}.^2)./50;ttl{2}='decelerating';
refs{3}=49.9-flipud(refs{2});ttl{3}='accelerating';
refs{4}=[0;sort(rand(length(refs{1})-2,1)).*50;50];ttl{4}='random';
%plot(cat(2,refs{:}),'.-');legend(ttl{:},4);
for p=1:4 B{p}=plot_act(refs{p},grid,k);end
for p=1:4 err{p}=B{p} - repmat(B{p}(:,1),1,Nk);end
for p=1:4 subplot(4,2,2*p-1);plot(grid,B{p});ylabel('act');axis(ax1);end
for p=1:4 subplot(4,2,2*p);plot(grid,err{p});ylabel('err');axis(ax2);end
for p=1:4*2 subplot(4,2,p);title(ttl{ceil(p/2)});end



for p=[1,4] subplot(2,2,min(p+1,4)-1);plot(grid,B{p});ylabel('act');axis(ax1);end
for p=[1 4] subplot(2,2,min(p+1,4));plot(grid,err{p});ylabel('err');axis(ax2);end

p=5;refs{p}=[0 2 4 20 22 24 40 42 44 60 62 64]';ttl{5}='pulsating';
B{p}=plot_act(refs{p},grid,k);err{p}=B{p}-repmat(B{p}(:,1),1,Nk);
subplot(2,1,1);plot(grid,B{p});axis(ax1);
subplot(2,1,2);plot(grid,err{p});axis([0 70 -.5 .5]);

p=6;refs{p}=[0;sort(rand(98,1)).*50;50];ttl{p}='dense random';
B{p}=plot_act(refs{p},grid,k);err{p}=B{p}-repmat(B{p}(:,1),1,Nk);
subplot(2,1,1);plot(grid,B{p});;
subplot(2,1,2);plot(grid,err{p});axis([0 70 -.5 .5]);

p=7;refs{p}=[0;sort(rand(40,1)).*30;50+sort(rand(20,1)).*10];
ttl{p}='dense pulsating random';
B{p}=plot_act(refs{p},grid,k);err{p}=B{p}-repmat(B{p}(:,1),1,Nk);
subplot(2,1,1);h=plot(grid,B{p}(:,2),'r-',grid,B{p}(:,end),'bo');
axis([0 70 0 4]);set(h(1),'LineWidth',3);
subplot(2,1,2);h=plot(grid,err{p}(:,2),'r-',grid,err{p}(:,end),'bo');
axis([0 70 -.5 .5]);set(h(1),'LineWidth',3);
h=refline(0,0);set(h,'Color','b','LineStyle','-');


