function model = model_train_data(data,ngmm)
% model = model_train_data(data,ngmm)
%    Just return a model of the specified data
% 2007-04-30 dpwe@ee.columbia.edu

% Train the GMM (KPMstats/)
if ngmm == 1
  % special case - single gauss is full-covar
  cov_type = 'full';
  mm = mean(data)';
  ss = cov(data) + 0.001*eye(size(mm,1));  % avoid singular
  pp = 1;
else
  cov_type = 'diag';
  [mm,ss,pp] = mixgauss_em(data', ngmm, 'cov_type', cov_type);
end

% Return results
model.mean = mm;
model.sigma = ss;
if ngmm == 1
  model.invsigma = inv(ss);
end
model.prior = pp;
model.nmix = ngmm;
