这里我学习的是Statistical Patte7rn Recognition Toolbox中的emgmm代码,代码中的主要知识点在之前的GMM文档中基本解释清楚,包括EM算法中的两个步骤。我自己先看原理,再去看代码,在给代码注释的过程中我又重新把整个理论体系梳理了一遍,还是很感谢这种方式,踏踏实实地做一件事情。
主函数 emgmm
子函数
pdfgauss 多元高斯分布概率密度估计
knnrule knnclass 模型参数初始化过程中使用的数据分类方法
mlcgmm 对于数据类别已知的GMM参数估计
melgmm EM算法中M步参数估计
function model=emgmm(X,options,init_model)
% EMGMM Expectation-Maximization Algorithm for Gaussian mixture model.
%
% Synopsis:
% model = emgmm(X)
% model = emgmm(X,options)
% model = emgmm(X,options,init_model)
%
% Description:
% This function implements the Expectation-Maximization algorithm
% (EM) [Schles68][DLR77] which computes the maximum-likelihood
% estimate of the paramaters of the Gaussian mixture model (GMM).
% The EM algorithm is an iterative procedure which monotonically
% increases log-likelihood of the current estimate until it reaches
% a local optimum.
%
% The number of components of the GMM is given in options.ncomp
% (default 2).
%
%%%%EM算法迭代停止条件
% The following three stopping are condition used:
% 1. Improvement of the log-likelihood is less than given
% threshold
% logL(t+1) - logL(t) < options.eps_logL
%%%logL(t)单调递增,随着下界的提升,逐渐逼近其最大值。当它不再变化或者变化幅度很小时,停止迭代.
% 2. Change of the squared differences of a estimated posteriory
% probabilities is less than given threshold
% ||alpha(t+1) - alpha(t)||^2 < options.eps_alpha
%%%%E步给定参数,求出隐含变量的期望;M步根据期望重新估计参数,返回到E步,得出新的隐含变量的期望。通过求取二者向量的L2范数,当其
%%%%不变或者变化很小时,停止迭代。
% 3. Number of iterations exceeds given threshold.
% t >= options.tmax
%%%%设置迭代次数上限
% The type of estimated covariance matrices is optional:
% options.cov_type = 'full' full covariance matrix (default)
% options.cov_type = 'diag' diagonal covarinace matrix
% cov_options.type = 'spherical' spherical covariance matrix
%%%%在模型参数初始化中,采用knn给样本数据分类并采用极大似然估计法进行参数估计,下面三种就是knn中心点初始化方法
% The initial model (estimate) is selected:
% 1. randomly (options.init = 'random')
% 2. using C-means (options.init = 'cmeans')
% 3. using the user specified init_model.
%
% Input:
% X [dim x num_data] Data sample.
%
% options [struct] Control paramaters:
% .ncomp [1x1] Number of components of GMM (default 2).
% .tmax [1x1] Maximal number of iterations (default inf).
% .eps_logL [1x1] Minimal improvement in log-likelihood (default 0).
% .eps_alpha [1x1] Minimal change of Alphas (default 0).
% .cov_type [1x1] Type of estimated covarince matrices (see above).
% .init [string] 'random' use random initial model (default);
% 'cmeans' use K-means to find initial model.
% .verb [1x1] If 1 then info is displayed (default 0).
%
% init_model [struct] Initial model:
% .Mean [dim x ncomp] Mean vectors.
% .Cov [dim x dim x ncomp] Covariance matrices.
% .Priors [1 x ncomp] Weights of mixture components.
% .Alpha [ncomp x num_data] (optional) Distribution of hidden state.
% .t [1x

本文通过分析Statistical Pattern Recognition Toolbox中的emgmm代码,详细讲解了高斯混合模型(GMM)的实现过程,特别是EM算法的E步和M步。在阅读代码和添加注释的过程中,作者对GMM理论进行了深入梳理,同时介绍了pdfgauss、knnrule、knnclass和mlcgmm等关键函数的作用。
&spm=1001.2101.3001.5002&articleId=49468973&d=1&t=3&u=7a6153acbe1e41dc8ea2e188499a61c7)
1236

被折叠的 条评论
为什么被折叠?



