-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsample_tables.m
22 lines (17 loc) · 885 Bytes
/
sample_tables.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
% function stateCounts = sample_tables(stateCounts,hyperparams,beta_vec,Kz)
% Sample the number of tables in restaurant i serving dish j given the mode
% sequence z_{1:T} and hyperparameters. Also sample the override variables.
function stateCounts = sample_tables(stateCounts,hyperparams,beta_vec,Kz)
% Split \alpha and \kappa using \rho:
rho0 = hyperparams.rho0;
alpha0 = hyperparams.alpha0_p_kappa0*(1-rho0);
kappa0 = hyperparams.alpha0_p_kappa0*rho0;
N = stateCounts.N;
% Sample M, where M(i,j) = # of tables in restaurant i served dish j:
M = randnumtable([alpha0*beta_vec(ones(1,Kz),:)+kappa0*eye(Kz); alpha0*beta_vec],N);
% Sample barM (the table counts for the underlying restaurant), where
% barM(i,j) = # tables in restaurant i that considered dish j:
[barM sum_w] = sample_barM(M,beta_vec,rho0);
stateCounts.M = M;
stateCounts.barM = barM;
stateCounts.sum_w = sum_w;