function [Est,al,tab,bx]=lrLearnD(y,x)
  // [Est,al]=lrLearnD(y,x)    learning of Mixture logistic
  //                          regression model - categorical
  // y    class label (column - nd x 1)
  // x    data vectors (vectors in rows - nd x nx)
  // Est  estimation structure
  // al   stationary probs.

  nc=max(y);
  n1=min(y);
  if n1~=1, 
    disp('Error: y must start with 1'); 
    return
  end
  bx=max(x,'c');
  nv=prod(bx);
  tab=[];
  for i=1:nc 
    c=find(y==i);
    Y=y(c);
    X=x(:,c);
    nx=size(X,2);
    hs=1e-8*ones(nv,1);
    for t=1:nx
      k=psi2row(X(:,t),bx);
      hs(k)=hs(k)+1;
    end           
    tab=[tab hs];
  end
  for i=1:nc
    Est(i).th=fnorm(tab(:,i)');
  end
  
  ga=vals(y);
  al=ga(2,:)/sum(ga(2,:));
endfunction
