marginal_nodes.m

来自「贝叶斯网络matlab源程序,可用于分类,欢迎大家下载测试」· M 代码 · 共 78 行

M
78
字号
function marginal = marginal_nodes(engine, query, add_ev)% MARGINAL_NODES Compute the marginal on the specified query nodes (stab_cond_gauss)% marginal = marginal_nodes(engine, query, add_ev)%% 'query' must be a singleton set.% add_ev is an optional argument; if 1, we will "inflate" the marginal of observed nodes% to their original size, adding 0s to the positions which contradict the evidenceif nargin < 3, add_ev = 0; endif isempty(engine.evidence)    hquery = query;  else       hquery = [];    for i = query        if isempty(engine.evidence{i})        hquery = [hquery i];        end    endendbnet = bnet_from_engine(engine);nclq = length(engine.cliques);clique = 0;for i = 1:nclq  if mysubset(hquery, engine.cliques{i})    pot = struct(engine.clpot{i});    %if mysubset(hquery, pot.cheaddom) | mysubset(hquery, pot.ddom)    if mysubset(hquery, pot.domain)     clique = i;      break;    end  endendif isempty(hquery)     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     % If all requested variables are observed, no query is necessary %     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%     marginal.mu = [];     marginal.Sigma = [];     marginal.T = 1.0;     marginal.domain = query;else    if clique == 0        marginal = marginal_difclq_nodes(engine, hquery);    else         marginal = marginal_singleclq_nodes(engine, clique, hquery);    end    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    % Change the format of output, so that it is identical to the %    % format obtained by the same request for the junction-tree   %    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    marginal.domain = query;    bnet = bnet_from_engine(engine);    dquery = myintersect(bnet.dnodes,hquery);    ns = bnet.node_sizes(dquery);    if length(ns) == 0    marginal.T = 1;    else        if length(ns) == 1            ns = [1 ns];        end        marginal.T = reshape(marginal.T,ns);    endendif add_ev  bnet = bnet_from_engine(engine);  %marginal = add_ev_to_dmarginal(marginal, engine.evidence, bnet.node_sizes);  marginal = add_evidence_to_gmarginal(marginal, engine.evidence, bnet.node_sizes, bnet.cnodes);end

⌨️ 快捷键说明

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