about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/potentials/@upot
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/potentials/@upot
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/potentials/@upot')
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Entries10
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/approxeq_pot.m5
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/display.m4
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/divide_by_pot.m13
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/marginalize_pot.m18
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/multiply_by_pot.m12
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/normalize_pot.m13
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/pot_to_marginal.m9
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/upot.m15
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@upot/upot_to_opt_policy.m25
12 files changed, 126 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Entries b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Entries
new file mode 100644
index 00000000..25bc0a31
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Entries
@@ -0,0 +1,10 @@
+/approxeq_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/display.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/divide_by_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/marginalize_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/multiply_by_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/normalize_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/pot_to_marginal.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/upot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/upot_to_opt_policy.m/1.1.1.1/Wed May 29 15:59:58 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Repository b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Repository
new file mode 100644
index 00000000..b7cf8acd
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/potentials/@upot
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Root b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/approxeq_pot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/approxeq_pot.m
new file mode 100644
index 00000000..de47ee12
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/approxeq_pot.m
@@ -0,0 +1,5 @@
+function p = approxeq_pot(A, B, tol)
+
+if nargin < 3, tol = 1e-3; end
+
+p = approxeq(A.p, B.p, tol) & approxeq(A.u, B.u, tol);
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/display.m b/sourcecodes/bnt-master/BNT/potentials/@upot/display.m
new file mode 100644
index 00000000..bb8e76e9
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/display.m
@@ -0,0 +1,4 @@
+function display(pot)
+
+disp('utility potential object');
+disp(struct(pot));
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/divide_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/divide_by_pot.m
new file mode 100644
index 00000000..8ac75785
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/divide_by_pot.m
@@ -0,0 +1,13 @@
+function Tbig = divide_by_pot(Tbig, Tsmall)
+% DIVIDE_BY_POT Tbig /= Tsmall
+% Tbig = divide_by_pot(Tbig, Tsmall)
+%
+% Tsmall's domain must be a subset of Tbig's domain.
+
+smallp = extend_domain_table(Tsmall.p, Tsmall.domain, Tsmall.sizes, Tbig.domain, Tbig.sizes);
+smallp = smallp + (smallp==0);
+Tbig.p = Tbig.p ./ smallp;
+
+smallu = extend_domain_table(Tsmall.u, Tsmall.domain, Tsmall.sizes, Tbig.domain, Tbig.sizes);
+Tbig.u = Tbig.u - smallu;
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/marginalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/marginalize_pot.m
new file mode 100644
index 00000000..be4bf249
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/marginalize_pot.m
@@ -0,0 +1,18 @@
+function smallpot = marginalize_pot(bigpot, onto, maximize)
+% MARGINALIZE_POT Marginalize a upot onto a smaller domain.
+% smallpot = marginalize_pot(bigpot, onto, maximize)
+%
+% The maximize argument is ignored
+
+numer = marg_table(bigpot.p .* bigpot.u, bigpot.domain, bigpot.sizes, onto);
+denom = marg_table(bigpot.p, bigpot.domain, bigpot.sizes, onto);
+
+p = denom;
+% replace 0s by 1s before dividing. This is valid since demon(i) = 0 => numer(i) = 0
+denom = denom + (denom == 0); 
+u = numer ./ denom;
+
+ns = zeros(1, max(bigpot.domain));
+ns(bigpot.domain) = bigpot.sizes;
+
+smallpot = upot(onto, ns(onto), p, u);
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/multiply_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/multiply_by_pot.m
new file mode 100644
index 00000000..28b3586d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/multiply_by_pot.m
@@ -0,0 +1,12 @@
+function Tbig = multiply_by_pot(Tbig, Tsmall)
+% MULTIPLY_BY_POT Tbig *= Tsmall
+% Tbig = multiply_by_pot(Tbig, Tsmall)
+%
+% Tsmall's domain must be a subset of Tbig's domain.
+
+smallp = extend_domain_table(Tsmall.p, Tsmall.domain, Tsmall.sizes, Tbig.domain, Tbig.sizes);
+Tbig.p = Tbig.p .* smallp;
+
+smallu = extend_domain_table(Tsmall.u, Tsmall.domain, Tsmall.sizes, Tbig.domain, Tbig.sizes);
+Tbig.u = Tbig.u + smallu;
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/normalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/normalize_pot.m
new file mode 100644
index 00000000..dc3dfa8a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/normalize_pot.m
@@ -0,0 +1,13 @@
+function [pot, loglik] = normalize_pot(pot)
+% NORMALIZE_POT Convert the probability part of a utility potential
+% [pot, loglik] = normalize_pot(pot)
+
+[pot.p, lik] = normalise(pot.p);
+%pot.u = pot.u - sum(pot.u(:));
+%pot.u = pot.u ./ sum(pot.u(:)); % same as normalise(pot.u)
+%pot.u = normalise(pot.u);
+%pot.u = pot.u / 726.8121;
+pot.u = pot.u / 10;
+loglik = log(lik + (lik==0)*eps);
+
+      
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/pot_to_marginal.m b/sourcecodes/bnt-master/BNT/potentials/@upot/pot_to_marginal.m
new file mode 100644
index 00000000..4d3a1c37
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/pot_to_marginal.m
@@ -0,0 +1,9 @@
+function m = pot_to_marginal(pot)
+% POT_TO_MARGINAL Convert a upot to a structure.
+% m = pot_to_marginal(pot)
+
+m.domain = pot.domain;
+m.T = pot.p;
+m.U = pot.u;
+
+    
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/upot.m b/sourcecodes/bnt-master/BNT/potentials/@upot/upot.m
new file mode 100644
index 00000000..502858b8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/upot.m
@@ -0,0 +1,15 @@
+function pot = upot(domain, sizes, p, u)
+% UPOT Make a discrete utility potential.
+% pot = upot(domain, sizes, p, u)
+%
+% sizes(i) is the size of the i'th domain element.
+% p defaults to all 1s, u defaults to all 0s.
+
+if nargin < 3, p = myones(sizes); end
+if nargin < 4, u = 0*myones(sizes); end
+
+pot.domain = domain;
+pot.p = myreshape(p, sizes);
+pot.u = myreshape(u, sizes);
+pot.sizes = sizes(:)';
+pot = class(pot, 'upot');
diff --git a/sourcecodes/bnt-master/BNT/potentials/@upot/upot_to_opt_policy.m b/sourcecodes/bnt-master/BNT/potentials/@upot/upot_to_opt_policy.m
new file mode 100644
index 00000000..20f8d2ec
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@upot/upot_to_opt_policy.m
@@ -0,0 +1,25 @@
+function [policy, EU] = upot_to_opt_policy(pot)
+% UPOT_TO_OPT_POLICY Compute an optimal deterministic policy given a utility potential
+% [policy, EU] = upot_to_opt_policy(pot)
+%
+% policy(a,b, ..., z) = P(do z | a, b, ..), which will be a delta function
+% EU is the contraction of this potential, i.e., P .* U
+
+sz = pot.sizes; % mysize(pot.p);
+if isempty(sz)
+  EU = pot.u;
+  policy = [];
+  return;
+end
+
+parent_size = prod(sz(1:end-1));
+self_size = sz(end); 
+C = pot.p .* pot.u; % contraction
+C = reshape(C, parent_size, self_size);
+policy = zeros(parent_size, self_size);
+for i=1:parent_size
+  act = argmax(C(i,:));
+  policy(i, act) = 1;
+end
+policy = myreshape(policy, sz);
+EU = sum(C(:));