Mercurial > hg > camir-ismir2012
comparison toolboxes/FullBNT-1.0.7/KPMstats/est_transmat.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cc4b1211e677 |
---|---|
1 function [A,C] = est_transmat(seq) | |
2 % ESTIMATE_TRANSMAT Max likelihood of a Markov chain transition matrix | |
3 % [A,C] = estimate_transmat(seq) | |
4 % | |
5 % seq is a vector of positive integers | |
6 % | |
7 % e.g., seq = [1 2 1 2 3], C(1,2)=2, C(2,1)=1, C(2,3)=1, so | |
8 % A(1,:)=[0 1 0], A(2,:) = [0.5 0 0.5], | |
9 % all other entries are 0 | |
10 | |
11 % Use a trick with sparse matrices to count the number of each transition. | |
12 % From http://www.mathworks.com/company/newsletter/may03/dna.shtml | |
13 | |
14 C = full(sparse(seq(1:end-1), seq(2:end),1)); | |
15 A = mk_stochastic(C); |