
function [mix] = mixtrain(X,y,c);
%
% function [mix] = mixtrain(X,y,c)
%
% trains a Gaussian mixture model based on data (X,y) 
% and stores the result in 'mix'. c is a
% regularization parameter (assumed to be zero)

if (nargin<3), c = 0; end;

[n,d] = size(X);

for i=1:2,
  I = find(y==i-1); % i=1 corresponds to y=0
  mix{i}.mu  = mean(X(I,:));
  mix{i}.cov = cov(X(I,:),1) + c*eye(d); % c regularizes the estimate
  mix{i}.icov= inv(mix{i}.cov); % inverse covariance
  mix{i}.p   = length(I)/n; % prior class probability
end;
