function [M,I] = softmax1(X,temperature) 

% SOFTMAX1   Specialized variant of SOFTMAX for one-dimensional data.
%
% M = SOFTMAX1(X,TEMPERATURE)
% [M,I] = SOFTMAX1(X,TEMPERATURE)
%
% X must be a vector (either row or column). No error checks are made.
% M and I are scalars.  The semantics is the same as in SOFTMAX.
%
% See also SOFTMAX, ANYRND1.

% Original coding by Alex Petrov, Ohio State University
% $Revision: 1.1 $  $Date: 2001/08/01 18:15 $
%
% Part of the utils toolbox version 1.1 for MATLAB version 5 and up.
% http://alexpetrov.com/softw/utils/
% Copyright (c) Alexander Petrov 1999-2006, http://alexpetrov.com
% Please read the LICENSE and NO WARRANTY statement in ../utils_license.m

if (temperature < eps)
  [M,I] = max(X) ;
else
  p = exp(X./temperature) ;
  cum_p = cumsum(p./sum(p)) ;
  u = rand ;                 % uniform random deviate
  hits = (cum_p <= u) ;
  I = sum(hits) + 1 ;
  M = X(I) ;
end

%-- Return M and I
%%%%% End of SOFTMAX1.M
