clear; clf; format compact

c=12.3708; wt1=0.9420; wt2=0.7850; thresh=0.6910; slope = 5.8319;
nitems =3; nlists=3;

for cond=0:1;

    if cond==0; wt=wt1; end; if cond==1; wt=wt2; end; wp=1-wt;

    if cond==0; dtim=[4.8 4.2 3.6 3.0 2.4 1.8 1.2 .6 0]; end
    if cond==1; dtim=[4.8 4.35 3.9 2.85 2.4 1.95 0.9 .45 0]; end

    dpos=[3 2 1 3 2 1 3 2 1];

    for n=1:nitems*nlists; dd(n)=0.0; end

    for n=1:nitems*nlists;
        cdtim=dtim;
        cdtim=cdtim+n^1.5;
        for nbb=1:nitems*nlists; cdtim(nbb)=log(cdtim(nbb)); end
        for m=1:nitems*nlists;
            distance=wt*(abs(cdtim(n)-cdtim(m)))+wp*(abs(dpos(n)-dpos(m)));
            dd(n) = dd(n) + (exp(-c*(distance)));
        end
        for out=1:9;
            distance(out)=wt*(abs(cdtim(n)-cdtim(out)))+wp*(abs(dpos(n)-dpos(out)));
            prob(n,out)=exp(-c*(distance(out)))/dd(n);
        end
    end


    for i=1:9; for j=1:9;
            prob(i,j)=1/(1+exp(-slope*(prob(i,j)-thresh)));
        end; end

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

    for n=1:9; serpos(n)=prob(n,n); end

    plot(serpos)

    hold on

end
