pacowong / bnt

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

Learning problem with 6 variables DBN with only one observable variable. What I'm doing wrong ? #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Here the Code : 

%% Construct DBN
O = 32; % num observable symbols
ss = 6; % slice size
intra = zeros(ss);

% One observation variable the #1
intra(2,1) = 1;
intra(3,1) = 1;
intra(4,1) = 1;
intra(5,1) = 1;
intra(6,1) = 1;

inter = zeros(ss);
inter(2, [2 3 4 5]) = 1;
inter(3, [2 3 4 6]) = 1;
inter(4, [2 3 4 5 6]) = 1;
inter(5, [2 4 5 6]) = 1;
inter(6, [3 4 5 6]) = 1;

onodes = 1; % observed
dnodes = 1:ss; % discrete
ns = [O 2*ones(1,ss-1)]; % binary nodes except observed node
eclass1 = [1 2 2 2 2 2];
eclass2 = [1 3:7];
eclass = [eclass1 eclass2];

bnet = mk_dbn(intra, inter, ns, 'discrete', dnodes, 'observed', onodes, 
'eclass1', eclass1, 'eclass2', eclass2);

%% Set Prior
% Use Uniform Prior :
for e=1:max(eclass)
  bnet.CPD{e} = tabular_CPD(bnet, e, 'CPT', 'unif');
end

%% DATA : sequences of 100 observations 
k = 300; % Number of samples
T = 100; % Length of samples
data = randi(32,k,T);

%% Learn DBN
engine = smoother_engine(jtree_2TBN_inf_engine(bnet));

ncases = k;%number of examples
cases = cell(1,ncases);
for i=1:ncases
%   ev = sample_dbn(bnet, T);
  cases{i} = cell(ss,T);
  cases{i}(onodes,:) = num2cell(data(onodes,1:T), 1);
end

[bnetH2, LLtrace] = learn_params_dbn_em(engine, cases, 'max_iter', 4);

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

Here is the error : 

??? Error using ==> reshape
To RESHAPE the number of elements must not change.

Error in ==> myreshape at 10
  T = reshape(T, sizes(:)');

Error in ==> dpot.dpot at 21
         pot.T = myreshape(T, sizes);

Error in ==> discrete_CPD.convert_to_pot at 28
  pot = dpot(domain, ns(domain), T);

Error in ==> jtree_2TBN_inf_engine.fwd at 15
  CPDpot{n} = convert_to_pot(bnet.CPD{e}, engine.pot_type, fam(:), ev2);

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

Error in ==> learn_params_dbn_em>EM_step at 131
  [engine, ll] = enter_evidence(engine, evidence);

Error in ==> learn_params_dbn_em at 82
  [engine, loglik, logpost] = EM_step(engine, evidence, temperature);

Error in ==> testDBN1 at 63
[bnetH2, LLtrace] = learn_params_dbn_em(engine, cases, 'max_iter', 4); 

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

I'm using Matlab 2010a on a win 7 x64 OS.

Please provide any additional information below.

The aim is to make classification over some data that look like the one I 
generated. Soi'd like to learn 2 DBNs over two labeled sets of data. But i'm 
not even capable of learning one DBN :P

It's been two days that I'm searching for what I have done wrong ... If you can 
tell me I would be very pleased.

Thank you.

PS: sorry for the mistakes in English ... its not my mother tongue :)

Original issue reported on code.google.com by camille....@gmail.com on 5 May 2011 at 6:45

Attachments: