【问题标题】:Bayes Net Toolbox for MATLAB适用于 MATLAB 的贝叶斯网络工具箱
【发布时间】:2016-03-14 19:05:52
【问题描述】:

我刚开始学习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

要重塑,元素的数量不能改变。

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 ] );

【问题讨论】:

    标签: matlab bayesian-networks


    【解决方案1】:

    我有一个错误:

    node_sizes = [ 4 2 3 5];
    

    应该是:

    node_sizes = 2*ones(1,N);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-31
      • 2013-07-29
      • 1970-01-01
      • 2013-04-08
      • 2013-11-27
      • 2011-01-09
      • 2012-07-14
      相关资源
      最近更新 更多