matthiasm@8: function bnet = learn_params_dbn(bnet, data) matthiasm@8: % LEARN_PARAM_DBN Estimate params of a DBN for a fully observed model matthiasm@8: % bnet = learn_params_dbn(bnet, data) matthiasm@8: % matthiasm@8: % data(i,t) is the value of node i in slice t (can be a cell array) matthiasm@8: % We currently assume there is a single time series matthiasm@8: % matthiasm@8: % We set bnet.CPD{i} to its ML/MAP estimate. matthiasm@8: % matthiasm@8: % Currently we assume each node in the first 2 slices has its own CPD (no param tying); matthiasm@8: % all nodes in slices >2 share their params with slice 2 as usual. matthiasm@8: matthiasm@8: [ss T] = size(data); matthiasm@8: matthiasm@8: % slice 1 matthiasm@8: for j=1:ss matthiasm@8: if adjustable_CPD(bnet.CPD{j}) matthiasm@8: fam = family(bnet.dag,j); matthiasm@8: bnet.CPD{j} = learn_params(bnet.CPD{j}, data(fam,1)); matthiasm@8: end matthiasm@8: end matthiasm@8: matthiasm@8: matthiasm@8: % slices 2:T matthiasm@8: % data2(:,t) contains [data(:,t-1); data(:,t)]. matthiasm@8: % Then we extract out the rows corresponding to the parents in the current and previous slice. matthiasm@8: data2 = [data(:,1:T-1); matthiasm@8: data(:,2:T)]; matthiasm@8: for j=1:ss matthiasm@8: j2 = j+ss; matthiasm@8: if adjustable_CPD(bnet.CPD{j2}) matthiasm@8: fam = family(bnet.dag,j2); matthiasm@8: bnet.CPD{j2} = learn_params(bnet.CPD{j2}, data2(fam,:)); matthiasm@8: end matthiasm@8: end matthiasm@8: