clear; clf;
format compact

wt=.998; c=811.338; slope=26.4754; thresh=0.3857;

retint=24*60*60;

for cond=1:22;

    clear dtim;
    clear dpos;

    wp=1-wt;
    nitems = 12;
    nlists=cond;
    for cc=1:nitems*nlists; totserpos(cc)=0; end;

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

    for kl=1:nlists
        for jk=1:(nitems*nlists-12*kl)
            dtim(jk)=dtim(jk)+60;
        end
    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,nitems)+1;
    end

    for i=1:nitems*nlists; for j=1:nitems*nlists;
            prob(i,j)=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 n=1:nitems; serpos(n)=min(1,serpos(n)); end

    results(cond)=mean(serpos);

end

plot(results)
hold on
