wolffd@0: function count = compute_counts(data, sz) wolffd@0: % COMPUTE_COUNTS Count the number of times each combination of discrete assignments occurs wolffd@0: % count = compute_counts(data, sz) wolffd@0: % wolffd@0: % data(i,t) is the value of variable i in case t wolffd@0: % sz(i) : values for variable i are assumed to be in [1:sz(i)] wolffd@0: % wolffd@0: % Example: to compute a transition matrix for an HMM from a sequence of labeled states: wolffd@0: % transmat = mk_stochastic(compute_counts([seq(1:end-1); seq(2:end)], [nstates nstates])); wolffd@0: wolffd@0: assert(length(sz) == size(data, 1)); wolffd@0: P = prod(sz); wolffd@0: indices = subv2ind(sz, data'); % each row of data' is a case wolffd@0: %count = histc(indices, 1:P); wolffd@0: count = hist(indices, 1:P); wolffd@0: count = myreshape(count, sz); wolffd@0: