forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixGaussGb.m
31 lines (31 loc) · 888 Bytes
/
mixGaussGb.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function [label, Theta, w, llh] = mixGaussGb(X, opt)
% Collapsed Gibbs sampling for Dirichlet process (infinite) Gaussian mixture model (a.k.a. DPGM).
% This is a wrapper function which calls underlying Dirichlet process mixture model.
% Input:
% X: d x n data matrix
% opt(optional): prior parameters
% Output:
% label: 1 x n cluster label
% Theta: 1 x k structure of trained Gaussian components
% w: 1 x k component weight vector
% llh: loglikelihood
% Written by Mo Chen ([email protected]).
[d,n] = size(X);
mu = mean(X,2);
Xo = bsxfun(@minus,X,mu);
s = sum(Xo(:).^2)/(d*n);
if nargin == 1
kappa0 = 1;
m0 = mean(X,2);
nu0 = d;
S0 = s*eye(d);
alpha0 = 1;
else
kappa0 = opt.kappa;
m0 = opt.m;
nu0 = opt.nu;
S0 = opt.S;
alpha0 = opt.alpha;
end
prior = GaussWishart(kappa0,m0,nu0,S0);
[label, Theta, w, llh] = mixDpGb(X,alpha0,prior);