Code covered by the BSD License  

Highlights from
EM algorithm for Gaussian mixture model

image thumbnail

EM algorithm for Gaussian mixture model


Mo Chen (view profile)


23 Dec 2009 (Updated )

EM algorithm for Gaussian mixture. Works on arbitray dimensions with high speed and precision.

logsumexp(x, dim)
function s = logsumexp(x, dim)
% Compute log(sum(exp(x),dim)) while avoiding numerical underflow.
%   By default dim = 1 (columns).
% Written by Michael Chen (
if nargin == 1, 
    % Determine which dimension sum will use
    dim = find(size(x)~=1,1);
    if isempty(dim), dim = 1; end

% subtract the largest in each column
y = max(x,[],dim);
x = bsxfun(@minus,x,y);
s = y + log(sum(exp(x),dim));
i = find(~isfinite(y));
if ~isempty(i)
    s(i) = y(i);

Contact us