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