bayesnet / bnt

Bayes Net Toolbox for Matlab
460 stars 247 forks source link

There might be a bug in jtree_inf_engine and var_elim_inf_engine #43

Closed yzhang2016 closed 8 years ago

yzhang2016 commented 8 years ago

Hi,

I am not sure whether it is a bug in junction tree inference and variable elimination.

For the following BN model, when computing marginal for each node given node 1, I tested Junction tree inference , variable elimination and pear_inf_engine. I found that the results by Junction tree and variable elimination are incorrect while pear_inf_engine is correct. I have no idea what happens in the Junition tree and the variable elimination engine .

I computed the marginal given node 1 for each other node manually. For node 8 and node 9, only pearl_infer_engine got the right results.

I put the learned bnet model (matlab format) in the attachment. Model configuration :

image

## Results : P(A8 = 2 | A1) P(A9 = 2 | A1) Result : jtree image

Result : var_elim image

Result : pearl image

## _Manual _: image

code: ---------------------------  jtree_Engine = jtree_inf_engine(bnet) ; var_Engine = var_elim_inf_engine(bnet) ; pearl_Engine = pearl_inf_engine(bnet) ;

jtree_conMarg = compMarginal (bnet,jtree_Engine) ; varconMarg = compMarginal (bnet,var_Engine) ; pearlconMarg = compMarginal (bnet,pearl_Engine) ;


function [conMarg] = compMarginal (bnet,engine) %% First node : exp, 8 states, others : AUs, binary numNodes = size(bnet.dag,1) ; numAUs = numNodes - 1; numCls = bnet.node_sizes(1) ;
evidence = cell(1,numNodes) ; conMarg = zeros(numCls,numAUs) ; for i = 1 : numCls evidence{1} = i ; engine = enter_evidence(engine,evidence) ; for j = 1 : numAUs temNodeInd = j + 1 ; temMarg = marginal_nodes(engine,temNodeInd) ; conMarg(i,j) = temMarg.T(2) ; end end

bnet_learnedModel.zip