function [Est,al]=lrLearn(y,x)                                
  // [Est,al]=lrLearn(y,x)    
  //           learning of Mixture logistic regression model 
  // 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'); 
    Est=[]; al=[];
    return
  end
  [n1,n2]=size(x);
  if n1>n2, disp('Variables in x should be rows'), end
  for i=1:nc
    c=find(y==i);
    Y=y(c);
    X=x(:,c);
    th=mean(X,'c');
    cv=cov(X');
    if det(cv)<1e-5, 
      cv=.1*eye(cv)+cv; 
    end
    Est(i).th=th;
    Est(i).cv=cv;
  end
  ga=vals(y);
  al=ga(2,:)/sum(ga(2,:));
endfunction
