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

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