Skip to content

Commit

Permalink
mixBernRnd, mixBernEm, nbBern not done
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Mar 6, 2016
1 parent fae1b73 commit 30740bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TODO:
extract demos
ch08: BP, EP, NBMn
ch08: BP, EP
ch14: Cart

17 changes: 17 additions & 0 deletions chapter09/Untitled.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
close all; clear;
d = 2;
k = 3;
n = 1000000;
[X,z,mu] = mixBernRnd(d,k,n);
model = nbBern(X,z);
mu
model.mu
% [label,model,llh] = mixBernEm(X,k);
% plot(llh);
% d = 2;
% n = 1000;
% mu = rand(d,1);
% X = bsxfun(@le,rand(d,n), mu);
%
% m = mean(X,2)
% mu
11 changes: 5 additions & 6 deletions chapter09/mixBernRnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
% Output:
% X: d x n data matrix
% z: 1 x n response variable
% center: d x k centers of clusters
% mu: d x k parameters of each Bernoulli component
% Written by Mo Chen ([email protected]).
alpha = 1;

w = dirichletRnd(alpha,ones(1,k)/k);
% w = dirichletRnd(1,ones(1,k)/k);
w = ones(1,k)/k;
z = discreteRnd(w,n);
mu = rand(1,k);

mu = rand(d,k);
X = zeros(d,n);
for i = 1:k
idx = z==i;
X(:,idx) = rand(d,sum(idx)) < mu(k);
X(:,idx) = bsxfun(@le,rand(d,sum(idx)), mu(:,k));
end

0 comments on commit 30740bf

Please sign in to comment.