clear;  format compact; clf
rand('state',0)
c=8.8582 ; wt=0.9506; thresh1=0.4868 ; thresh2=0.4309 ; slope=8.1177; nitems = 6; nlists=5;  wphon=1-wt;

for i=1:nitems; for j=1:nitems; bigsmallmat1(i,j)=0; bigsmallmat2(i,j)=0; end; end

ncycles=5;

for cycle=1:ncycles

    for conf=0:1;
        if conf==0; thresh=thresh1;  end
        if conf==1;  thresh=thresh2;  end

        clear dtim;
        clear dpos;

        if conf==0; dphon(1:6)=randperm(6); dphon(7:12)=randperm(6); dphon(13:18)=randperm(6); dphon(19:24)=randperm(6); dphon(25:30)=randperm(6);
        end

        if conf==1; dphon=[1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5]; end

        dtim=zeros(1,30);
        ccc=0;
        for z=30:-1:1;
            dtim(z)=ccc; ;
            ccc=ccc+.4;
        end
        eee=0;
        for z=30:-1:1;
            eee=eee+1;
            for counter=6:6:250
                if eee>counter; dtim(z)=dtim(z)+30; end;
            end
        end

        startdtim=dtim;

        for n=1:30; for nb=1:1; sumsim(n,nb)=0.0; end; end

        rinc=1;
        for n=1:30;
            if n>25; rinc=rinc+1; end
            dtim=startdtim+rinc-0.5;

            for i=1:nitems*nlists; dtim(i)=log(dtim(i)); end
            for m=1:30;
                distance=wt*abs(dtim(n)-dtim(m))+wphon*abs(dphon(n)-dphon(m));
                sumsim(n) = sumsim(n) + exp(-c*distance);
            end
            for out=1:30
                distance(out)=wt*abs(dtim(n)-dtim(out))+wphon*abs(dphon(n)-dphon(out));
                sim(out)=exp(-c*distance(out));
                prob(n,out)=sim(out)/sumsim(n);
            end
        end

        for cck=1:30; for ccj=1:30;
                prob(cck,ccj)=1/(1+exp(-slope*(prob(cck,ccj)-thresh)));
            end; end

        for m=0:5; smallmat((6-m),:)=prob((30-m),:); end
        for j=1:6; for jk=1:6; vsmallmat(j,jk)=smallmat(j,24+jk); end; end

        sumprob=sum(vsmallmat);
        for n=1:nitems; if sumprob(n)>1; vsmallmat(:,n)=vsmallmat(:,n)/sumprob(n); end; end

        if conf==0; bigsmallmat1=bigsmallmat1+vsmallmat; end
        if conf==1; bigsmallmat2=bigsmallmat2+vsmallmat; end
    end
end

bigsmallmat1=bigsmallmat1/ncycles;
bigsmallmat2=bigsmallmat2/ncycles;

axis([1 6 0 1])
plot(bigsmallmat1)
hold on
plot(bigsmallmat2)
