comparison toolboxes/FullBNT-1.0.7/KPMstats/dirichlet_sample.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function theta = dirichlet_sample(alpha, N)
2 % SAMPLE_DIRICHLET Sample N vectors from Dir(alpha(1), ..., alpha(k))
3 % theta = sample_dirichlet(alpha, N)
4 % theta(i,j) = i'th sample of theta_j, where theta ~ Dir
5
6 % We use the method from p. 482 of "Bayesian Data Analysis", Gelman et al.
7
8 assert(alpha > 0);
9 k = length(alpha);
10 theta = zeros(N, k);
11 scale = 1; % arbitrary
12 for i=1:k
13 %theta(:,i) = gamrnd(alpha(i), scale, N, 1);
14 theta(:,i) = gamma_sample(alpha(i), scale, N, 1);
15 end
16 %theta = mk_stochastic(theta);
17 S = sum(theta,2);
18 theta = theta ./ repmat(S, 1, k);