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.
add sample function of mixture model from prior
- Loading branch information
Showing
4 changed files
with
44 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function [X, z] = mixGaussSample(Theta, w, n ) | ||
% Genarate samples form a Gaussian mixture model with GaussianWishart prior. | ||
% Input: | ||
% Theta: cell of GaussianWishart priors of components | ||
% w: weight of components | ||
% n: number of data | ||
% Output: | ||
% X: d x n data matrix | ||
% z: 1 x n response variable | ||
% Written by Mo Chen ([email protected]). | ||
z = discreteRnd(w,n); | ||
d = Theta{1}.dim(); | ||
X = zeros(d,n); | ||
for i = 1:numel(w) | ||
idx = z==i; | ||
[mu,Sigma] = Theta{i}.sample(); % invpd(wishrnd(W0,v0)); | ||
X(:,idx) = gaussRnd(mu,Sigma,sum(idx)); | ||
end |
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