赞
踩
(1)以下matlab代码实现了高斯混合模型:
function [Alpha, Mu, Sigma] = GMM_EM(Data, Alpha0, Mu0, Sigma0)
%% EM 迭代停止条件
loglik_threshold = 1e-10;
%% 初始化参数
[dim, N] = size(Data);
M = size(Mu0,2);
loglik_old = -realmax;
nbStep = 0;
Mu = Mu0;
Sigma = Sigma0;
Alpha = Alpha0;
Epsilon = 0.0001;
while (nbStep < 1200)
nbStep = nbStep+1;
%% E-步骤 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i=1:M
% PDF of each point
Pxi(:,i) = GaussPDF(Data, Mu(:,i), Sigma(:,:,i));
end
% 计算后验概率 beta(i|x)
Pix_tmp = repmat(Alpha,[N 1]).*Pxi;
Pix = Pix_tmp ./ (repmat(sum(Pix_tmp,2),[1 M])+realmin);
Beta = sum(Pix);
%% M-步骤 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i=1:M
% 更新权值
Alpha(i) = Beta(i) / N;
% 更新均值
Mu(:,i) = Data*Pix(:,i) / Beta(i);
% 更新方差
Data_tmp1 = Data - repmat(Mu(:,i),1,N);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。