高斯混合模型(matlab代码+注释)

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

这里我学习的是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
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值