annotate toolboxes/FullBNT-1.0.7/bnt/learning/learn_params_dbn.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function bnet = learn_params_dbn(bnet, data)
wolffd@0 2 % LEARN_PARAM_DBN Estimate params of a DBN for a fully observed model
wolffd@0 3 % bnet = learn_params_dbn(bnet, data)
wolffd@0 4 %
wolffd@0 5 % data(i,t) is the value of node i in slice t (can be a cell array)
wolffd@0 6 % We currently assume there is a single time series
wolffd@0 7 %
wolffd@0 8 % We set bnet.CPD{i} to its ML/MAP estimate.
wolffd@0 9 %
wolffd@0 10 % Currently we assume each node in the first 2 slices has its own CPD (no param tying);
wolffd@0 11 % all nodes in slices >2 share their params with slice 2 as usual.
wolffd@0 12
wolffd@0 13 [ss T] = size(data);
wolffd@0 14
wolffd@0 15 % slice 1
wolffd@0 16 for j=1:ss
wolffd@0 17 if adjustable_CPD(bnet.CPD{j})
wolffd@0 18 fam = family(bnet.dag,j);
wolffd@0 19 bnet.CPD{j} = learn_params(bnet.CPD{j}, data(fam,1));
wolffd@0 20 end
wolffd@0 21 end
wolffd@0 22
wolffd@0 23
wolffd@0 24 % slices 2:T
wolffd@0 25 % data2(:,t) contains [data(:,t-1); data(:,t)].
wolffd@0 26 % Then we extract out the rows corresponding to the parents in the current and previous slice.
wolffd@0 27 data2 = [data(:,1:T-1);
wolffd@0 28 data(:,2:T)];
wolffd@0 29 for j=1:ss
wolffd@0 30 j2 = j+ss;
wolffd@0 31 if adjustable_CPD(bnet.CPD{j2})
wolffd@0 32 fam = family(bnet.dag,j2);
wolffd@0 33 bnet.CPD{j2} = learn_params(bnet.CPD{j2}, data2(fam,:));
wolffd@0 34 end
wolffd@0 35 end
wolffd@0 36