这就是交易。因此,我按照 BNT 手册中的说明创建了一个 BN,它是洒水器,但我添加了冬季和夏季的节点类。像这样:
Cloudy------ / \ | Sprinkler Rain | \ / | | Wet Class
Where class depends only on wether is cloudy or raining. With the same specification as http://bnt.googlecode.com/svn/trunk/docs/usage.html#basics
And the class is also binary, the table is:
C R Class prob --------------- 1 1 1 0 2 1 1 0.4 1 2 1 0.4 2 2 1 0.9 etc.
So my question using the var_elimination_eng because for some reason jtree is not working, I get this the marg.T after entering evidence for rainy:
ans =
0.800000000000000
0.200000000000000
这是正确的吗?我执行得好吗?或者我错过了什么?谢谢。
相同的假设 1=false=冬季,2=true=夏季
编辑:
所以是的,类节点的 CPT 是 8 个条目
C R Class prob --------------- 1 1 1 0 2 1 1 0.4 1 2 1 0.4 2 2 1 0.9 1 1 2 1 2 1 2 0.6 1 2 2 0.6 2 2 2 0.6 2 2 2 0.1
These are 1 - Oposite. The code is:
N = 5
dag = zeros(N,N)
C = 1; S = 2; R = 3; W = 4; Class = 5
dag(C, [S R]) = 1
dag( R, W) = 1
dag(S, W) = 1
dag(C, Class) = 1
dag(R, Class) = 1
discrete_nodes = 1:N
nodes_size = 2*ones(1,N)
bnet = mk_bnet(dag, nodes_size, names, {'Clody', 'S', 'R', 'W', 'Class'}, 'discrete', discrete_nodes)
bnet.CPD{C} = tabular_CPD(bnet, C, [0.5 0.5])
bnet.CPD{R} = tabular_CPD(bnet, R, [0.8 0.2 0.2 0.8])
bnet.CPD{S} = tabular_CPD(bnet, S, [0.5 0.9 0.5 0.1])
bnet.CPD{W} = tabular_CPD(bnet, W, [1 0.1 0.1 0.01 0 0.9 0.9 0.99])
bnet.CPD{Class} = tabular_CPD(bnet, Class, [0 0.4 0.4 0.9 1 0.6 0.6 0.1])
evidence = cell(1, N)
evidence{R} = 2
engine = var_elim_inf_engine(bnet)
[engine loglik] = enter_evidence(engine, evidence)
marg = marginal_nodes(engine, R)
marg = marginal_nodes(engine, Class)
marg.T
这是我使用的代码,至于jtree,它在matlab上给了我一些错误,该错误已经消失,但是,我认为变量elimin更容易理解,因为我现在正在阅读它。
谢谢。
最佳答案
在这种情况下,“类别”的条件概率表 (CPT) 应具有 8 (2*2*2) 个元素。推理引擎的后验输出 (marg.T) 似乎适合二进制变量。
它的意思是:“‘类’节点有 0.8 的概率处于状态 1,有 0.2 的概率处于状态 2”。从此时起,由用户决定是否将“类别”指定为状态 1 或 2。
当涉及到分类时,在最简单(且不太可取)的情况下,您可以定义后验概率阈值 0.5 并说:
if P(class=1)> 0.5
class = 1
else
class = 2
end
在评估二元分类的性能时,您可以查看 predictive accuracy or Area Under the ROC curve (AUC)或者more intelligent things考虑到“类”状态的先验概率。
P.S. 你说连接树引擎在这种情况下不起作用,但它应该起作用。您可能遗漏了一点,BNT 工具箱 .zip 文件中应该有一个 junction_tree 示例(我不太记得 .m 文件的名称是什么)。如果您使用连接树推理引擎,您将看到获得与变量消除相同的答案。
关于matlab - Matlab 中用于分类的贝叶斯网络 (BNT),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17935919/