Menu

#4 bug in mk_stochastic

open
nobody
None
5
2008-01-25
2008-01-25
Anonymous
No

mk_stochastic does not properly convert the counts when the counts for a particular configuration of parent nodes is zero. This can result in an error. The fix is to replace line 23 in mk_stochastic

%S = Z + (Z==0);

with the following 3 lines:

ix = find(Z == 0);

T(ix,:) = ones(length(ix), ns(end));

S = sum(T,2);

here is a small example that reproduces the same error:

N=3
dag=zeros(N,N)
dag(1,3)=1
dag(2,3)=1

% training data (I made sure that the case [3,3,:] never appears)

A =[ 1 1 2
2 1 1
2 3 2
1 2 1
3 1 2
2 3 2
1 3 3
1 1 3
2 2 1
3 1 2]

discrete_nodes = 1:N;
node_sizes=[3 3 3]
bnet = mk_bnet(dag, node_sizes, 'discrete', discrete_nodes);

for jj=1:N
bnet.CPD{jj} = tabular_CPD(bnet, jj);
end

nsamples=size(A,1);
samples=cell(N,nsamples);

for ii=1:nsamples
for jj=1:N
samples{jj,ii}=A(ii,jj);
end
end

bnet = learn_params(bnet, samples);
engin = jtree_inf_engine(bnet);

evi= cell(N,1);
engin = enter_evidence(engin, evi)
MR= marginal_nodes(engin,[1]);
% if different from the prior, then something is screwy....

MR.T

for gg=1:3
s=struct(bnet.CPD{gg});
CP{gg} = s.CPT
end

---
Bob Welch
indianpeaks@comcast.net

Discussion


Log in to post a comment.