dbn_to_hmm.m

来自「Bayes网络工具箱」· M 代码 · 共 41 行

M
41
字号
function [prior, transmat, obsmat1, obsmat] = dbn_to_hmm(bnet, onodes)% DBN_TO_HMM Compute the discrete HMM matrices from a simple DBN% [prior, transmat, obsmat1, obsmat] = dbn_to_hmm(bnet, onodes)ss = length(bnet.intra);evidence = cell(1,2*ss);hnodes = mysetdiff(1:ss, onodes);prior = multiply_CPTs(bnet, [], hnodes, evidence);transmat = multiply_CPTs(bnet, hnodes, hnodes+ss, evidence);obsmat1 = multiply_CPTs(bnet, hnodes, onodes, evidence);obsmat = multiply_CPTs(bnet, hnodes+ss, onodes+ss, evidence);% obsmat1 = obsmat if the observation matrices are tied across slices%%%%%%%%%%%%function mat = multiply_CPTs(bnet, pdom, cdom, evidence)% MULTIPLY_CPTS Make a matrix Pr(Y|X), where X represents all the parents, and Y all the children% We assume the children have no intra-connections.%% e.g., Consider the DBN with interconnectivity i->i', j->j',k', k->i',k'% Then transition matrix = Pr(i,j,k -> i',j',k') = Pr(i,k->i') Pr(j->j') Pr(j,k->k')dom = [pdom cdom];ns = bnet.node_sizes;bigpot = dpot(dom, ns(dom));for j=cdom(:)'  e = bnet.equiv_class(j);  fam = family(bnet.dag, j);  pot = CPD_to_dpot(bnet.CPD{e}, fam, ns, bnet.cnodes, evidence);  bigpot = multiply_by_pot(T, pot);endpsize = prod(ns(pdom));csize = prod(ns(cdom));T = pot_to_marginal(bigpot);mat = reshape(T.T, [psize csize]);          

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?