about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m
diff options
context:
space:
mode:
authorziejd22018-03-14 23:23:33 -0500
committerGitHub2018-03-14 23:23:33 -0500
commit1ff6baa44e22b91eefb48aea6f3befa078c0489b (patch)
treee0fd79d2e32fd2aedda2eadaed0f19af3514c520 /sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m
parent6882395afdadf4e982b25b5215071a0932730950 (diff)
parentc80226899f5cdd9f11c163817d59445213f5bef0 (diff)
downloadBNW-1ff6baa44e22b91eefb48aea6f3befa078c0489b.tar.gz
Merge pull request #1 from ziejd2/octave_php_separate
Octave php separate
Diffstat (limited to 'sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m')
-rw-r--r--sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m36
1 files changed, 36 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m b/sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m
new file mode 100644
index 00000000..4d0dc501
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/learning/learn_params_dbn.m
@@ -0,0 +1,36 @@
+function bnet = learn_params_dbn(bnet, data)
+% LEARN_PARAM_DBN Estimate params of a DBN for a fully observed model
+% bnet = learn_params_dbn(bnet, data)
+%
+% data(i,t) is the value of node i in slice t (can be a cell array)
+% We currently assume there is a single time series
+%
+% We set bnet.CPD{i} to its ML/MAP estimate.
+%
+% Currently we assume each node in the first 2 slices has its own CPD (no param tying);
+% all nodes in slices >2 share their params with slice 2 as usual.
+
+[ss T] = size(data);
+
+% slice 1
+for j=1:ss
+  if adjustable_CPD(bnet.CPD{j})
+    fam = family(bnet.dag,j);
+    bnet.CPD{j} = learn_params(bnet.CPD{j}, data(fam,1));
+  end
+end
+
+
+% slices 2:T
+% data2(:,t) contains [data(:,t-1); data(:,t)].
+% Then we extract out the rows corresponding to the parents in the current and previous slice.
+data2 = [data(:,1:T-1);
+	 data(:,2:T)];
+for j=1:ss
+  j2 = j+ss;
+  if adjustable_CPD(bnet.CPD{j2})
+    fam = family(bnet.dag,j2);
+    bnet.CPD{j2} = learn_params(bnet.CPD{j2}, data2(fam,:));
+  end
+end
+