function [K] = elkernel(prior1, transmat1, obsmat1, prior2, transmat2, obsmat2, T, beta)
%
% function [K] = elkernel(prior1, transmat1, obsmat1, prior2, transmat2, obsmat2, T, beta)
%
% Code to compute the kernel similarity between two multinomial emission hidden Markov models.
% Each hmm (1 and 2) is represented in the same way as in Kevin Murphy's Bayes Net / HMM toolkit.
% prior: a state distribution vector
% transmat: a transition matrix of conditional probability of next state given past state
% obsmat: an emission matrix for each symbol given each state
% The T parameter controls how many time steps to use in the integration. We recommend T=10.
% The beta parameter controls how much transition tables are taken to a power. We recommend beta=1.
%
prior1 = prior1.^beta;
prior2 = prior2.^beta;
transmat1 = transmat1.^beta;
transmat2 = transmat2.^beta;
obsmat1 = obsmat1.^beta;
obsmat2 = obsmat2.^beta;
pot = obsmat1*obsmat2';
sep1 = prior1*prior2';
sep1 = sep1.*pot;
for t=1:T
sep1 = pot.*(transmat1*sep1*transmat2');
end
K = sum(sum(sep1));