about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/HMM/dhmm_logprob_path.m
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/HMM/dhmm_logprob_path.m')
-rw-r--r--sourcecodes/bnt-master/HMM/dhmm_logprob_path.m15
1 files changed, 15 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/HMM/dhmm_logprob_path.m b/sourcecodes/bnt-master/HMM/dhmm_logprob_path.m
new file mode 100644
index 00000000..11a1e3af
--- /dev/null
+++ b/sourcecodes/bnt-master/HMM/dhmm_logprob_path.m
@@ -0,0 +1,15 @@
+function [ll, p] = prob_path(prior, transmat, obsmat, qs)
+% PROB_PATH Compute the prob. of a specific path (state sequence) through an HMM.
+% [ll, p] = prob_path(prior, transmat, obsmat, states)
+%
+% ll = log prob path
+% p(t) = Pr(O(t)) * Pr(Q(t) -> Q(t+1)) for 1<=t<T, p(T) = Pr(O(T))
+
+T = size(obsmat, 2);
+p = zeros(1,T);
+p(1) = prior(qs(1)) * obsmat(qs(1),1);
+for t=2:T
+  p(t) = transmat(qs(t-1), qs(t)) * obsmat(qs(t),t);
+end
+
+ll = sum(log(p));