forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refined doc for ch11. demo needs check
- Loading branch information
Showing
10 changed files
with
90 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
% Class for Gaussian distribution used by Dirichlet process | ||
classdef Gauss | ||
properties | ||
n_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
function x = dirichletRnd(a, m) | ||
% Sampling from a Dirichlet distribution. | ||
% Generate samples from a Dirichlet distribution. | ||
% Input: | ||
% a: k dimensional vector | ||
% m: k dimensional mean vector | ||
% Outpet: | ||
% x: generated sample x~Dir(a,m) | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 2 | ||
a = a*m; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
function x = discreteRnd(p, n) | ||
% Sampling from a discrete distribution (multinomial). | ||
% Generate samples from a discrete distribution (multinomial). | ||
% Input: | ||
% p: k dimensional probability vector | ||
% n: number of samples | ||
% Ouput: | ||
% x: k x n generated samples x~Mul(p) | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 1 | ||
n = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
function x = gaussRnd(mu,Sigma,n) | ||
% Sampling from a Gaussian distribution. | ||
function x = gaussRnd(mu, Sigma, n) | ||
% Generate samples from a Gaussian distribution. | ||
% Input: | ||
% mu: d x 1 mean vector | ||
% Sigma: d x d covariance matrix | ||
% n: number of samples | ||
% Outpet: | ||
% x: d x n generated sample x~Gauss(mu,Sigma) | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 2 | ||
n = 1; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
function [label, Theta, w, llh] = mixDpGb(X, alpha, theta) | ||
% Collapsed Gibbs sampling for Dirichlet process (infinite) mixture model (a.k.a. | ||
% DPGM). Any component model can be used, such as Gaussian | ||
% Collapsed Gibbs sampling for Dirichlet process (infinite) mixture model. | ||
% Any component model can be used, such as Gaussian. | ||
% Input: | ||
% X: d x n data matrix | ||
% alpha: parameter for Dirichlet process prior | ||
% theta: class object for prior of component distribution (such as Gauss) | ||
% Output: | ||
% label: 1 x n cluster label | ||
% Theta: 1 x k structure of trained components | ||
% w: 1 x k component weight vector | ||
% llh: loglikelihood | ||
% Written by Mo Chen ([email protected]). | ||
n = size(X,2); | ||
[label,Theta,w] = mixDpGbOl(X,alpha,theta); | ||
nk = n*w; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
function [label, Theta, w, llh] = mixDpGbOl(X, alpha, theta) | ||
% Online collapsed Gibbs sampling for Dirichlet process (infinite) mixture model (a.k.a. | ||
% DPGM). Any component model can be used, such as Gaussian | ||
% Online collapsed Gibbs sampling for Dirichlet process (infinite) mixture model. | ||
% Input: | ||
% X: d x n data matrix | ||
% alpha: parameter for Dirichlet process prior | ||
% theta: class object for prior of component distribution (such as Gauss) | ||
% Output: | ||
% label: 1 x n cluster label | ||
% Theta: 1 x k structure of trained components | ||
% w: 1 x k component weight vector | ||
% llh: loglikelihood | ||
% Written by Mo Chen ([email protected]). | ||
n = size(X,2); | ||
Theta = {}; | ||
nk = []; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
function [label, Theta, w, llh] = mixGaussGb(X, opt) | ||
% Collapsed Gibbs sampling for Dirichlet process (infinite) Gaussian mixture model (a.k.a. | ||
% DPGM). | ||
% 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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters