dag_to_jtree.m
来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 58 行
M
58 行
function [jtree, root, cliques, B, w, elim_order, moral_edges, fill_in_edges, strong] = dag_to_jtree(bnet, obs_nodes, stages, clusters)% DAG_TO_JTREE Moralize and triangulate a DAG, and make a junction tree from its cliques.% [jtree, root, cliques, B, w, elim_order] = dag_to_jtree(bnet, obs_nodes, stages, clusters)%% jtree(i,j) = 1 iff there is an arc between clique i and clique j % root = the root clique% cliques{i} = the nodes in clique i% B(i,j) = 1 iff node j occurs in clique i% w(i) = weight of clique iN = length(bnet.dag);if nargin < 2, obs_nodes = []; endif nargin < 3, stages = { 1:N }; endif nargin < 4, clusters = {}; end[MG, moral_edges] = moralize(bnet.dag);% Add extra arcs between nodes in each cluster to ensure they occur in the same cliquefor i=1:length(clusters) c = clusters{i}; MG(c,c) = 1;endMG = setdiag(MG, 0);% Find an optimal elimination ordering (NP-hard problem!)ns = bnet.node_sizes(:);ns(obs_nodes) = 1; % observed nodes have only 1 possible valuepartial_order = determine_elim_constraints(bnet, obs_nodes);if isempty(partial_order) strong = 0; elim_order = best_first_elim_order(MG, ns, stages);else strong = 1; elim_order = strong_elim_order(MG, ns, partial_order);end[MTG, cliques, fill_in_edges] = triangulate(MG, elim_order);% Connect the cliques up into a jtree,[jtree, root, B, w] = cliques_to_jtree(cliques, ns);%if isempty(partial_order)% [jtree, root, B, w] = cliques_to_jtree(cliques, ns);%else% disp('using strong triangulation');% [jtree, root, cliques, B, w] = cliques_to_strong_jtree(cliques, ns, elim_order, MTG);%endif 0 disp('testing dag to jtree'); % Find the cliques containing each node, and check they form a connected subtree clqs_con_node = cell(1,N); for i=1:N clqs_con_node{i} = find(B(:,i))'; end check_jtree_property(clqs_con_node, jtree);end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?