function gmm = hmm_to_gmm(hmm);
% gmm = hmm_to_gmm(hmm);
%
% Convert an HMM structure to the equivalent GMM structure without the
% dynamics.  hmm can be an array of HMM structures.
%
% 2007-01-30 ronw@ee.columbia.edu

% Copyright (C) 2007 Ron J. Weiss
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program.  If not, see <http://www.gnu.org/licenses/>.

for n = 1:length(hmm)
  h = convert_hmm_to_gaussian_emissions(hmm(n));

  gmm(n).name = h.name;
  gmm(n).nmix = h.nstates;
  gmm(n).means = h.means;
  gmm(n).covars = h.covars;

  gmm(n).priors = logsum(h.transmat, 1)';

  norm = logsum(gmm(n).priors);
  if isnan(norm)
    gmm(n).priors(isnan(gmm(n).priors)) = -Inf;
    norm = logsum(gmm(n).priors);
  end

  gmm(n).priors = gmm(n).priors-norm;
end
