ido / bnt-old

Automatically exported from code.google.com/p/bnt
0 stars 1 forks source link

DBN - Inference error on the example HMM problem #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I have recently started learning the BayesNet toolbox and I faced some problems 
with running test experiments. I hope someone could help me.

> What steps will reproduce the problem?

I run the below script to test the inference algorithm on DBNs using the sample 
codes from the online tutorial for a simple HMM:

------------------------------------------------------------------
clc
clear

intra = zeros(2);
intra(1,2) = 1; % node 1 in slice t connects to node 2 in slice t

inter = zeros(2);
inter(1,1) = 1; % node 1 in slice t-1 connects to node 1 in slice t

Q = 2; % num hidden states
O = 2; % num observable symbols

ns = [Q O];
dnodes = 1:2;
onodes = [2];

bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes);

% Create CPDs
for i=1:3
  bnet.CPD{i} = tabular_CPD(bnet, i);
end

% Create the engine
engine = smoother_engine(jtree_2TBN_inf_engine(bnet));

% Add evidence
T = 10;
ss = 2;
ev = sample_dbn(bnet, T);
evidence = cell(ss,T);
evidence(onodes,:) = ev(onodes, :); % all cells besides onodes are empty
engine = enter_evidence(engine, evidence);

% Compute the marginal
t = 5;
nodes = [1 2];
m = marginal_nodes(engine, nodes, t);
------------------------------------------------------------------

> What is the expected output? What do you see instead?

I get the following error when I run the script:

------------------------------------------------------------------
??? Error using ==> times
Matrix dimensions must agree.

Error in ==> mult_by_table at 7
bigT(:) = bigT(:) .* Ts(:); % must have bigT(:) on LHS to preserve shape

Error in ==> dpot.multiply_by_pot at 11
   Tbig.T = mult_by_table(Tbig.T, Tbig.domain, Tbig.sizes, Tsmall.T, Tsmall.domain, Tsmall.sizes);

Error in ==> jtree_inf_engine.init_pot at 17
  clpot{c} = multiply_by_pot(clpot{c}, pots{i});

Error in ==> jtree_2TBN_inf_engine.fwd1 at 20
[f.clpot, f.seppot] =  init_pot(engine.jtree_engine1, CPDclqs, CPDpot, 
engine.pot_type,
engine.observed1);

Error in ==> smoother_engine.enter_evidence at 12
[f{1}, ll(1)] = fwd1(engine.tbn_engine, ev(:,1), 1);
------------------------------------------------------------------

> What version of the product are you using? On what operating system?

I have installed the FullBNT-1.0.7 version.

> Please provide any additional information below.

I am using Matlab 7.7.0

Original issue reported on code.google.com by janza...@gmail.com on 27 Jun 2011 at 5:04

GoogleCodeExporter commented 9 years ago
hi 
Email Address::::   rafe.torabi@gmail.com

help me ; help me plz I write code for Inference but it have error below::: 

??? Error using ==> subsindex Function 'subsindex' is not defined for values of 
class 'cell'. 

Error in ==> discrete_CPD.convert_to_table at 14 T = CPT(index{:}); 

Error in ==> discrete_CPD.convert_to_pot at 20 

T = convert_to_table(CPD, domain, evidence); 

Error in ==> jtree_inf_engine.enter_evidence at 57 

pot{n} = convert_to_pot(bnet.CPD{e}, pot_type, fam(:), evidence); 

Error in ==> Rafe_inference at 116 engine,loglik? = 
enter_evidence(engine,evidence); 

my code is ::::: 

clear all 

clc 

A?=xlsread('E:\DATA MINING\final_cut.xlsx'); 

N=6; 

dag=zeros(N,N); 

AS=1;AM=2;CC=3;SC=4;VT=5;DA=6; 

dag(3:6,AS)=1;dag(2,3)=1;dag(3,4)=1; 

discrete_nodes=1:N; 

node_sizes=3 9 9 21 10?; 

onodes=2:6; 

bnet=mk_bnet(dag,node_sizes,'observed',onodes); 

draw_graph(bnet.dag); 

bnet.CPD{AS}=tabular_CPD(bnet,AS); 

bnet.CPD{AM}=tabular_CPD(bnet,AM); 

bnet.CPD{CC}=tabular_CPD(bnet,CC); 

bnet.CPD{SC}=tabular_CPD(bnet,SC); 

bnet.CPD{VT}=tabular_CPD(bnet,VT); 

bnet.CPD{DA}=tabular_CPD(bnet,DA); 

TrainingSamples?=cell(N,size(A,1)); 

for i = 1 : size(A,1) 

TrainingSamples?(1,i)={A(i,1)'}; 
TrainingSamples?(2,i)={A(i,2)'}; 
TrainingSamples?(3,i)={A(i,3)'}; 
TrainingSamples?(4,i)={A(i,4)'}; 
TrainingSamples?(5,i)={A(i,5)'}; 
TrainingSamples?(6,i)={A(i,6)'}; 
end 

bnet=learn_params(bnet,TrainingSamples?); 

engine = jtree_inf_engine(bnet); 

evidence = cell(1,N); 

evidence{AM} = {A(i,2)'}; 

evidence{CC} = {A(i,3)'}; 

evidence{SC} = {A(i,4)'}; 

evidence{VT} = {A(i,5)'}; 

evidence{DA} = {A(i,6)'}; 

engine,loglik? = enter_evidence(engine,evidence); 

marg = marginal_nodes(engine, AS); 

Original comment by rafe.tor...@gmail.com on 19 Sep 2011 at 4:51

Attachments: