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