Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/compute_counts.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function count = compute_counts(data, sz) |
matthiasm@8 | 2 % COMPUTE_COUNTS Count the number of times each combination of discrete assignments occurs |
matthiasm@8 | 3 % count = compute_counts(data, sz) |
matthiasm@8 | 4 % |
matthiasm@8 | 5 % data(i,t) is the value of variable i in case t |
matthiasm@8 | 6 % sz(i) : values for variable i are assumed to be in [1:sz(i)] |
matthiasm@8 | 7 % |
matthiasm@8 | 8 % Example: to compute a transition matrix for an HMM from a sequence of labeled states: |
matthiasm@8 | 9 % transmat = mk_stochastic(compute_counts([seq(1:end-1); seq(2:end)], [nstates nstates])); |
matthiasm@8 | 10 |
matthiasm@8 | 11 assert(length(sz) == size(data, 1)); |
matthiasm@8 | 12 P = prod(sz); |
matthiasm@8 | 13 indices = subv2ind(sz, data'); % each row of data' is a case |
matthiasm@8 | 14 %count = histc(indices, 1:P); |
matthiasm@8 | 15 count = hist(indices, 1:P); |
matthiasm@8 | 16 count = myreshape(count, sz); |
matthiasm@8 | 17 |