about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@root_CPD
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/CPDs/@root_CPD
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/CPDs/@root_CPD')
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CPD_to_pi.m12
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries7
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries.Log1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CPD_to_CPT.m5
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Entries2
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/convert_to_pot.m28
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_marg_prob_node.m9
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_prob_node.m9
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/root_CPD.m48
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@root_CPD/sample_node.m9
14 files changed, 134 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CPD_to_pi.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CPD_to_pi.m
new file mode 100644
index 00000000..65f4eb5e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CPD_to_pi.m
@@ -0,0 +1,12 @@
+function pi = CPD_to_pi(CPD, msg_type, n, ps, msg, evidence)
+% CPD_TO_PI Compute the pi vector (root)
+% function pi = CPD_to_pi(CPD, msg_type, n, ps, msg, evidence)
+
+self_ev = evidence{n};
+switch msg_type
+ case 'd',
+  error('root_CPD can''t create discrete msgs')
+ case 'g',
+  pi.mu = self_ev;
+  pi.Sigma = zeros(size(self_ev));
+end
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries
new file mode 100644
index 00000000..215e86ce
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries
@@ -0,0 +1,7 @@
+/CPD_to_pi.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/convert_to_pot.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/log_marg_prob_node.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/log_prob_node.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/root_CPD.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/sample_node.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries.Log
new file mode 100644
index 00000000..24f16336
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Entries.Log
@@ -0,0 +1 @@
+A D/Old////
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Repository
new file mode 100644
index 00000000..0f9893ad
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/CPDs/@root_CPD
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CPD_to_CPT.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CPD_to_CPT.m
new file mode 100644
index 00000000..ffc23a75
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CPD_to_CPT.m
@@ -0,0 +1,5 @@
+function CPT = CPD_to_CPT(CPD)
+% CPD_TO_CPT Convert the CPD to tabular form (root)
+% CPT = CPD_to_CPT(CPD)
+
+CPT = 1;
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Entries
new file mode 100644
index 00000000..7c0869aa
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Entries
@@ -0,0 +1,2 @@
+/CPD_to_CPT.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Repository
new file mode 100644
index 00000000..ac53f91a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/CPDs/@root_CPD/Old
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/convert_to_pot.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/convert_to_pot.m
new file mode 100644
index 00000000..6a25f1aa
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/convert_to_pot.m
@@ -0,0 +1,28 @@
+function pot = convert_to_pot(CPD, pot_type, domain, evidence)
+% CONVERT_TO_POT Convert a root CPD to one or more potentials
+% pots = convert_to_pot(CPD, pot_type, domain, evidence)
+
+assert(length(domain)==1);
+assert(~isempty(evidence(domain)));
+T = 1;   
+
+sz = CPD.sizes;
+ns = zeros(1, max(domain));
+ns(domain) = sz;
+
+switch pot_type
+ case 'u',
+  pot = upot(domain, 1, T, 0);
+ case 'd',
+  ns(domain) = 1;
+  pot = dpot(domain, ns(domain), T);          
+ case {'c','g'},
+  ns(domain) = 0;
+  pot = cpot(domain, ns(domain), 0);
+ case 'cg',
+  ddom = [];
+  cdom = domain; % we assume the root node is cts
+  %pot = cgpot(ddom, cdom, ns, {cpot([],[],0)});
+  pot = cgpot(ddom, cdom, ns);
+end
+
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_marg_prob_node.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_marg_prob_node.m
new file mode 100644
index 00000000..f45d3f4c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_marg_prob_node.m
@@ -0,0 +1,9 @@
+function L = log_marg_prob_node(CPD, self_ev, pev)
+% LOG_MARG_PROB_NODE Compute prod_m log int_{theta_i} P(x(i,m)| x(pi_i,m), theta_i) for node i (root)
+% L = log_marg_prob_node(CPD, self_ev, pev)
+%
+% self_ev{m} is the evidence on this node in case m
+% pev{i,m} is the evidence on the i'th parent in case m (ignored)
+% We always return L = 0.
+
+L = 0;
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_prob_node.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_prob_node.m
new file mode 100644
index 00000000..8d549631
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/log_prob_node.m
@@ -0,0 +1,9 @@
+function L = log_prob_node(CPD, self_ev, pev)
+% LOG_PROB_NODE Compute prod_m log P(x(i,m)| x(pi_i,m), theta_i) for node i (root)
+% L = log_prob_node(CPD, self_ev, pev)
+%
+% self_ev{m} is the evidence on this node in case m
+% pev{i,m} is the evidence on the i'th parent in case m (ignored)
+% We always return L = 0.
+
+L = 0;
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/root_CPD.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/root_CPD.m
new file mode 100644
index 00000000..b07df1e5
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/root_CPD.m
@@ -0,0 +1,48 @@
+function CPD = root_CPD(bnet, self, val)
+% ROOT_CPD Make a conditional prob. distrib. which has no parameters.
+% CPD = ROOT_CPD(BNET, NODE_NUM, VAL)
+%
+% The node must not have any parents and is assumed to always be observed.
+% It is a way of modelling exogenous inputs to a model.
+% VAL is the value to which the root is clamped (default: [])
+
+
+if nargin==0
+  % This occurs if we are trying to load an object from a file.
+  CPD = init_fields;
+  CPD = class(CPD, 'root_CPD', generic_CPD(1));
+  return;
+elseif isa(bnet, 'root_CPD')
+  % This might occur if we are copying an object.
+  CPD = bnet;
+  return;
+end
+CPD = init_fields;
+
+
+if nargin < 3, val = []; end
+
+ns = bnet.node_sizes;
+ps = parents(bnet.dag, self);
+if ~isempty(ps)
+  error('root CPDs should have no parents')
+end
+
+CPD.self = self;
+CPD.val = val;
+CPD.sizes = ns(self);
+
+clamped = 1;
+CPD = class(CPD, 'root_CPD', generic_CPD(clamped));
+
+
+%%%%%%%%%%%
+
+function CPD = init_fields()
+% This ensures we define the fields in the same order 
+% no matter whether we load an object from a file,
+% or create it from scratch. (Matlab requires this.)
+
+CPD.self = [];
+CPD.val = [];
+CPD.sizes = [];
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/sample_node.m b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/sample_node.m
new file mode 100644
index 00000000..5ced75f4
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@root_CPD/sample_node.m
@@ -0,0 +1,9 @@
+function y = sample_node(CPD, pev)
+% SAMPLE_NODE Draw a random sample from P(Y|pa(y), theta)  (root)
+% Y = SAMPLE_NODE(CPD, PEV)
+%
+% pev{i} is the evidence on the i'th parent.
+% Since a root has no parents, we ignore pev,
+% and return the value the root was clamped to when it was created.
+
+y = CPD.val;