comparison toolboxes/FullBNT-1.0.7/HMM/transmat_train_observed.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 [transmat, initState] = transmat_train_observed(labels, nstates, varargin)
2 % transmat_train_observed ML estimation from fully observed data
3 % function [transmat, initState] = transmat_train_observed(labels, nstates, varargin)
4 %
5 % If all sequences have the same length
6 % labels(ex,t)
7 % If sequences have different lengths, we use cell arrays
8 % labels{ex}(t)
9
10 [dirichletPriorWeight, mkSymmetric, other] = process_options(...
11 varargin, 'dirichletPriorWeight', 0, 'mkSymmetric', 0);
12
13 if ~iscell(labels)
14 [numex T] = size(labels);
15 if T==1
16 labels = labels';
17 end
18 %fprintf('T=%d, numex=%d\n', T, numex);
19 labels = num2cell(labels,2); % each row gets its own cell
20 end
21 numex = length(labels);
22
23 counts = zeros(nstates, nstates);
24 counts1 = zeros(nstates,1);
25 for s=1:numex
26 labs = labels{s}; labs = labs(:)';
27 dat = [labs(1:end-1); labs(2:end)];
28 counts = counts + compute_counts(dat, [nstates nstates]);
29 q = labs(1);
30 counts1(q) = counts1(q) + 1;
31 end
32 pseudo_counts = dirichletPriorWeight*ones(nstates, nstates);
33 if mkSymmetric
34 counts = counts + counts';
35 end
36 transmat = mk_stochastic(counts + pseudo_counts);
37 initState = normalize(counts1 + dirichletPriorWeight*ones(nstates,1));
38
39