bnmsgpasssendpimsg.asv
来自「关于医学诊断系统matlab实现 v 关于医学诊断系统matlab实现」· ASV 代码 · 共 46 行
ASV
46 行
function [nodes, edges] = bnMsgPassSendPiMsg(Z, X, nodes, edges, A)
%BNMSGPASSSENDPIMSG helper function for lungbayesdemo
% Reference: Neapolitan R., "Learning Bayesian Networks", Pearson Prentice Hall,
% Upper Saddle River, New Jersey, 2004.
childrenZ = nodes(Z).children;
childrenZ = setdiff(childrenZ, X);
for z = 1:length(nodes(Z).values) % for each values of z
v = nodes(Z).peye(z);
for y = 1:length(childrenZ)
v = v * edges(Z, childrenZ(y)).lambdaX(z);
end
edges(Z,X).peyeX(z) = v;
end
parentsX = nodes(X).parents;
if isempty(intersect(A,X))
w = 1;
for pa = 1:length(parentsX) % for each parent of X
w = kron(edges(parentsX(pa),X).peyeX, w); % need peyeX as a row
end
prob = shiftdim(nodes(X).CPT, length(size(nodes(X).CPT))-1); % so that x is the first dimension in prob
for x = 1:length(nodes(X).values)
nodes(X).peye(x) = prob(x,:) * w'; % % consider P(x | ... )
end
nodes(X).P = nodes(X).lambda .* nodes(X).peye;
nodes(X).P = nodes(X).P ./ sum(nodes(X).P); % normalize
childrenX = nodes(X).children;
for cx = 1:length(childrenX)
nodes = bnMsgpassSendPiMsg(X, childrenX(cx), nodes, edges, A);
end
end
if any(nodes(X).lambda ~= 1)
W = setdiff(parentsX, union(A,Z));
for w = 1:length(W)
[nodes, edges] = pearlsNetSendLambdaMsg(X, W(w), nodes, edges, A);
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?