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

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:cc4b1211e677
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);