about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@root_CPD
diff options
context:
space:
mode:
authorziejd22017-09-28 15:04:40 -0500
committerziejd22017-09-28 15:04:40 -0500
commit8070dc963753142bb86c4ed698d91fd623ed28e7 (patch)
treed0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/BNT/CPDs/@root_CPD
parent7cc31810d53176e805532b2789955f4eedbce6bb (diff)
downloadBNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning.

I am calling this BNW_1.02. It can be accessed at:
compbio.uthsc.edu/BNW_1.02
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;