%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Name: E_step.m % Input: x - a nxd matrix (nx3 if using RGB) % Q - vector of values from the complete data log-likelihood function % h - a nxk matrix, the expectation of the hidden variable z given the data set and distribution params % pi - vector of mixing coefficients % m - cluster means % S - cluster covariance matrices % k - the number of clusters % Output: h - a nxk matrix, the expectation of the hidden variable z given the data set and distribution params %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [h] = E_step(x, h, pi, m, S, k) [num_data, ~] = size(x); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % perform E-step of EM algorithm %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% parts = zeros(num_data, k); for i = 1:k parts(:, i) = pi(i) * mvnpdf(x, m(i, :), S(:, :, i)); end s = sum(parts); for j = 1:num_data h(j, :) = parts(j, :) ./ s; end end