function a=softmax(EstQ,tau) % FUNCTION a=softmax(EstQ, tau) % Input: Estimated payoff values in EstQ (size 1 x N, % where N is the number of machines % tau - "temperature": High values- the probs are all % close to equal; Low values, becomes "greedy" % Output: The machine that we should play (a number between 1 and N) % A little error checking first- See that tau has a value. if tau==0 fprintf('Error in the SoftMax program-\n'); fprintf('Tau must be greater than zero\n'); a=0; return end %Compute the probabilities using the softmax computation. Temp=exp(EstQ./tau); S1=sum(Temp); Probs=Temp./S1; %These are the probabilities we’ll use %Select machine "a" using probability Probs(a) we just computed. x=rand; TotalBins=histc(x,[0,cumsum(Probs)']); a=find(TotalBins==1);