clear all; format compact; clf

%set the parameter values
c=7; thresh=0.6; slope=8;


nitems = 4; %specify number of items in the list


%First specify the temporal distances of items at the start of recall
%Here assume SOA of 0.5 seconds
startdtim=[4 3 2 1 ];


for itemnum=1:nitems %for each item in the list...
    ss=0; %set its summed sim to other items to zero
    rinc=2; %rinc is the amount of time taken to recall each item; here assume 1 second
    d=startdtim+rinc*(itemnum-1); %calculate the temporal distance of all items at the time each item is recalled
    d
    for i=1:nitems; d(i)=log(d(i)); end %log transform the temporal distances    
    
    for n=1:nitems %for each item, calc the similarity and add to the total 
         ss = ss+ exp(-c*(abs(d(itemnum)-d(n))));
    end
    %ss now has the summed similarities for itemnum 
    
    %Now we need a nitems*nitems matrix, called prob, where each entry is
    %the probability of recalling a given item in a given output position
    for n=1:nitems
        prob(n,itemnum)=(exp(-c*(abs( d(itemnum)-d(n)))))/(ss);
    end
end


prob'

%implement the thresholding 
for i=1:nitems+0; for j=1:nitems;
    prob(i,j)=1/(1+exp(-slope*(prob(i,j)-thresh)));
end; end

prob'



%normalise columns if column sum to > 1
sumprob=sum(prob);
for n=1:nitems; if sumprob(n)>1; prob(:,n)=prob(:,n)/sumprob(n); end; end

plot(prob)
