MATLAB 贝叶斯网络工具箱
我是学习 Bayes Net Toolbox for MATLAB 的新手,我尝试过这个:
N = 4;
dag = zeros( N, N );
C = 1; S = 2; R = 3; W = 4;
dag( C, [R S] ) = 1;
dag( R, W ) = 1;
dag( S, W ) = 1;
discrete_nodes = 1:N;
node_sizes = [ 4 2 3 5];
onodes = [];
bNet = mk_bnet( dag, node_sizes, 'discrete', discrete_nodes, 'observed', onodes );
bNet.CPD{C} = tabular_CPD( bNet, C, 'CPT', [0.5 0.5] );
bNet.CPD{R} = tabular_CPD( bNet, R, 'CPT', [0.8 0.2 0.2 0.8 ] );
bNet.CPD{S} = tabular_CPD( bNet, S, 'CPT', [0.5 0.9 0.5 0.1] );
bNet.CPD{W} = tabular_CPD( bNet, W, 'CPT', [1 0.1 0.1 0.01 0 0.9 0.9 0.99 ] );
engine = jtree_inf_engine( bNet);
evidence = cell( 1,N );
evidence{W} = 2;
[engine, loglik] = enter_evidence( engine, evidence );
marg = marginal_nodes( engine, S );
marg.T
p = marg.T(2)
但它没有工作,它打印:
??? Error using ==> reshape
To reshape, the number of elements can not change.
Error in ==> myreshape at 10
T = reshape(T, sizes(:)');
Error in ==> tabular_CPD.tabular_CPD at 90
CPD.CPT = myreshape(T, fam_sz);
Error in ==> bnet at 19
bNet.CPD{R} = tabular_CPD( bNet, R, 'CPT', [0.8 0.2 0.2 0.8 ] );
I'm new to learning the Bayes Net Toolbox for MATLAB, and I have tried this:
N = 4;
dag = zeros( N, N );
C = 1; S = 2; R = 3; W = 4;
dag( C, [R S] ) = 1;
dag( R, W ) = 1;
dag( S, W ) = 1;
discrete_nodes = 1:N;
node_sizes = [ 4 2 3 5];
onodes = [];
bNet = mk_bnet( dag, node_sizes, 'discrete', discrete_nodes, 'observed', onodes );
bNet.CPD{C} = tabular_CPD( bNet, C, 'CPT', [0.5 0.5] );
bNet.CPD{R} = tabular_CPD( bNet, R, 'CPT', [0.8 0.2 0.2 0.8 ] );
bNet.CPD{S} = tabular_CPD( bNet, S, 'CPT', [0.5 0.9 0.5 0.1] );
bNet.CPD{W} = tabular_CPD( bNet, W, 'CPT', [1 0.1 0.1 0.01 0 0.9 0.9 0.99 ] );
engine = jtree_inf_engine( bNet);
evidence = cell( 1,N );
evidence{W} = 2;
[engine, loglik] = enter_evidence( engine, evidence );
marg = marginal_nodes( engine, S );
marg.T
p = marg.T(2)
But it doesn't work, and it prints:
??? Error using ==> reshape
To reshape, the number of elements must not change.
Error in ==> myreshape at 10
T = reshape(T, sizes(:)');
Error in ==> tabular_CPD.tabular_CPD at 90
CPD.CPT = myreshape(T, fam_sz);
Error in ==> bnet at 19
bNet.CPD{R} = tabular_CPD( bNet, R, 'CPT', [0.8 0.2 0.2 0.8 ] );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我犯了一个错误:
应该是:
I had a mistake in:
It should have been: