annotate toolboxes/FullBNT-1.0.7/KPMstats/est_transmat.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [A,C] = est_transmat(seq)
wolffd@0 2 % ESTIMATE_TRANSMAT Max likelihood of a Markov chain transition matrix
wolffd@0 3 % [A,C] = estimate_transmat(seq)
wolffd@0 4 %
wolffd@0 5 % seq is a vector of positive integers
wolffd@0 6 %
wolffd@0 7 % e.g., seq = [1 2 1 2 3], C(1,2)=2, C(2,1)=1, C(2,3)=1, so
wolffd@0 8 % A(1,:)=[0 1 0], A(2,:) = [0.5 0 0.5],
wolffd@0 9 % all other entries are 0
wolffd@0 10
wolffd@0 11 % Use a trick with sparse matrices to count the number of each transition.
wolffd@0 12 % From http://www.mathworks.com/company/newsletter/may03/dna.shtml
wolffd@0 13
wolffd@0 14 C = full(sparse(seq(1:end-1), seq(2:end),1));
wolffd@0 15 A = mk_stochastic(C);