function hmm = newhmm(ns,no,r);
% Creates a new hiden Markov model parameter structure, with 'ns'
% hidden states, and 'no' output states. The initial, transition and
% output probabilities are all initialized randomly. The optional third 
% parammeter controls the extent of the possible bias in these
% probability matrices. A value of r=0 indicates (non-random)
% completely uniform initial, transition and output
% probabilities. Small values of r allow slight biases, whereas larger
% values can allow biases of up to (r+1).
  if nargin<3, r = 1; end;
  
  p0 = condprob(1,ns,r);
  Pt = condprob(ns,ns,r);
  Po = condprob(ns,no,r);
  
  hmm = struct('p0',p0,'Pt',Pt,'Po',Po);

  % ------------------------------

function [P] = condprob(n,m,r);
  % Creates a random stochastic matrix of size n,m: all enteries are
  % non-negative and each of the n rows sums up to one. The maximal ratio 
  % between enteries in a the same row is (r+1).
  P = ones(n,m) + r*rand(n,m); % P(i,j) are iid and uniform in (1..r+1)
  P = op(P,'./',sum(P,2)); % Normalize rows






