% In case user did not remove degeneracies from the input similarities,
% avoid degenerate solutions by adding a small amount of noise to the
% input similarities
if~nonoise
rns=randn('state');randn('state',0);
S=S+(eps*S+realmin_*100).*rand(N,N);
randn('state',rns);
end;
% Place preferences on the diagonal of S
iflength(p)==1fori=1:NS(i,i)=p;end;
elsefori=1:NS(i,i)=p(i);end;
end;
% Numerical stability -- replace -INF with -realmax
n=find(S<-realmax_);if~isempty(n),warning('-INF similarities detected; changing to -REALMAX to ensure numerical stability');S(n)=-realmax_;end;clear('n');
if~isempty(find(S>realmax_,1)),error('+INF similarities detected; change to a large positive value (but smaller than +REALMAX)');end;