dbn_to_hmm.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 54 行

M
54
字号
function [startprob, transprob, obsprob] = dbn_to_hmm(bnet)% DBN_TO_HMM % Convert DBN params to HMM params% [startprob, transprob, obsprob] = dbn_to_hmm(bnet, onodes)% startprob(i)% transprob(i,j)% obsprob{k}(i,o) if k'th observed node is discrete% obsprob{k}.mu(:,i), .Sigma(:,:,i) if k'th observed node is Gaussian%% Called by constructor and by update_enginess = length(bnet.intra);onodes = bnet.observed;hnodes = mysetdiff(1:ss, onodes);evidence = cell(ss, 2);ns = bnet.node_sizes;Q = prod(ns(hnodes));tmp = dpot_to_table(compute_joint_pot(bnet, hnodes, evidence));startprob = reshape(tmp, Q, 1);tmp = dpot_to_table(compute_joint_pot(bnet, hnodes+ss, evidence, [hnodes hnodes+ss]));transprob = mk_stochastic(reshape(tmp, Q, Q));obsprob = cell(1, length(onodes));for i=1:length(onodes)  if bnet.ar_hmm    CPD = struct(bnet.CPD{bnet.equiv_class(onodes(i))});    obsprob{i}.mu0 = CPD.mean;    obsprob{i}.Sigma0 = CPD.cov;    CPD = struct(bnet.CPD{bnet.equiv_class(onodes(i)+ss)});    obsprob{i}.mu = CPD.mean;    obsprob{i}.Sigma = CPD.cov;    obsprob{i}.W = CPD.weights;  else    jpot = pot_to_marginal(compute_joint_pot(bnet, onodes(i), evidence, [hnodes onodes(i)]));    if myismember(onodes(i), bnet.dnodes)      O = ns(onodes(i));      tmp = reshape(jpot.T, Q, O);      assert(is_stochastic(tmp));      obsprob{i} = tmp;      %obsprob{i} = mk_stochastic(reshape(jpot.T, Q, O));    else      %obsprob{i} = jpot;      obsprob{i}.mu = jpot.mu;      C = jpot.Sigma;      obsprob{i}.Sigma = C;      obsprob{i}.inv_Sigma = inv(C);      d = length(jpot.mu);      obsprob{i}.denom = (2*pi)^(d/2)*sqrt(abs(det(C)));    end  endend

⌨️ 快捷键说明

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