clear; clf; format compact

slope=5; thresh=0.75; wt=0.9; nlists=5; wp=1-wt; nitems = 5;

for cval=1:3;
    if cval==1; c=2; end;
    if cval==2; c=4; end;
    if cval==3; c=6; end;

    for retint=1:1:100

        clear dtim;
        clear dpos;

        for j=1:nitems*nlists; dtim(j)=(nitems*nlists-j); end
        dtim=dtim*2;

        cc=-1;
        for j=nitems*nlists:-1:1;
            if rem(j,nitems)==0; cc=cc+1; end
            dtim(j)=dtim(j)+cc*10;
        end
        dtim=dtim+retint;


        for j=1:nitems*nlists; dpos(j)=0; end
        for j=nitems*nlists:-1:1;
            dpos(j)=dpos(j)+rem(j-1,5)+1;
        end


        for nnb=1:nitems*nlists; for nnc=1:nitems*nlists;
                prob(nnb,nnc)=0;
            end; end

        for n=1:nitems*nlists; dtim(n)=log(dtim(n)); end


        for itemnum=1:nitems*nlists
            dd=0;
            for m=1:nitems*nlists
                distance=wt*abs(dtim(itemnum)-dtim(m))+wp*abs(dpos(itemnum)-dpos(m));
                dd = dd + exp(-c*distance);
            end
            for n=1:nitems*nlists
                prob(n,itemnum)=(exp( -c*(wt*abs(dtim(itemnum)-dtim(n))+wp*abs(dpos(itemnum)-dpos(n)))))/(dd);
            end

        end

        minimat=prob((nitems*nlists)-nitems+1:(nitems*nlists),(nitems*nlists)-nitems+1:(nitems*nlists));

        for k=1:nitems; for j=1:nitems;
                minimat(k,j)=1/(1+exp(-slope*(minimat(k,j)-thresh)));
            end; end

        serpos=sum(minimat');

        for g=1:nitems; serpos(g)=min(1,serpos(g)); end

        results(retint,cval)=mean(serpos);

    end

end

plot(results,'oc')
