about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/potentials/@dpot
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/potentials/@dpot')
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Entries17
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/approxeq_pot.m5
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/display.m4
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/divide_by_pot.m14
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/domain_pot.m5
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/dpot.m26
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/dpot_to_table.m3
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/find_most_prob_entry.m10
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/get_fields.m13
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/marginalize_pot.m17
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_by_pot.m13
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_pots.m12
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/normalize_pot.m12
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/pot_to_marginal.m12
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/set_domain_pot.m5
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/subsasgn.m3
-rw-r--r--sourcecodes/bnt-master/BNT/potentials/@dpot/subsref.m3
19 files changed, 176 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Entries b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Entries
new file mode 100644
index 00000000..d37ad7eb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Entries
@@ -0,0 +1,17 @@
+/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/Thu Aug  5 15:25:08 2004//
+/domain_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/dpot.m/1.1.1.1/Tue Oct  1 19:04:44 2002//
+/dpot_to_table.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/find_most_prob_entry.m/1.1.1.1/Sun Jun 16 19:06:20 2002//
+/get_fields.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/marginalize_pot.m/1.1.1.1/Wed Aug  4 19:59:14 2004//
+/multiply_by_pot.m/1.1.1.1/Wed Aug  4 19:59:14 2004//
+/multiply_pots.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/normalize_pot.m/1.1.1.1/Wed Aug  4 15:54:48 2004//
+/pot_to_marginal.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/set_domain_pot.m/1.1.1.1/Wed May 29 15:59:58 2002//
+/subsasgn.m/1.1.1.1/Wed Apr 27 18:34:48 2005//
+/subsref.m/1.1.1.1/Wed Apr 27 18:34:48 2005//
+D
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Repository b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Repository
new file mode 100644
index 00000000..485f27df
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/potentials/@dpot
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Root b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/approxeq_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/approxeq_pot.m
new file mode 100644
index 00000000..b0f8d0ed
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/approxeq_pot.m
@@ -0,0 +1,5 @@
+function p = approxeq_pot(A, B, tol)
+
+if nargin < 3, tol = 1e-3; end
+
+p = approxeq(A.T, B.T, tol);
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/display.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/display.m
new file mode 100644
index 00000000..1b0647bb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/display.m
@@ -0,0 +1,4 @@
+function display(pot)
+
+disp('discrete potential object');
+disp(struct(pot));
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/divide_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/divide_by_pot.m
new file mode 100644
index 00000000..aae4790c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/divide_by_pot.m
@@ -0,0 +1,14 @@
+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.
+
+%process sparse dpot, we do not concern only one of the two pots is sparse
+if issparse(Tbig.T) && issparse(Tsmall.T)
+   Tbig.T = divide_by_sparse_table(Tbig.T, Tbig.domain, Tbig.sizes, Tsmall.T, Tsmall.domain, Tsmall.sizes);
+else
+   Tbig.T = divide_by_table(Tbig.T, Tbig.domain, Tbig.sizes, Tsmall.T, Tsmall.domain, Tsmall.sizes);
+end
+
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/domain_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/domain_pot.m
new file mode 100644
index 00000000..a67cef02
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/domain_pot.m
@@ -0,0 +1,5 @@
+function dom = domain_pot(pot)
+% DOMAIN_POT Return the domain of this dpot.
+% dom = domain_pot(pot)
+
+dom = pot.domain;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot.m
new file mode 100644
index 00000000..74b5dd9e
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot.m
@@ -0,0 +1,26 @@
+function pot = dpot(domain, sizes, T)
+% DPOT Make a discrete (sparse) potential.
+% pot = dpot(domain, sizes, T, spar)
+%
+% sizes(i) is the size of the i'th domain element.
+% T defaults to all 1s.
+
+%assert(length(sizes) == length(domain));
+
+pot.domain = domain(:)'; % so we can see it when we display
+if nargin < 3
+  pot.T = myones(sizes);
+  %pot.T = ones(1,prod(sizes)); % 1D vector
+else 
+   if isempty(T)
+      pot.T = [];
+   else
+      if issparse(T)
+         pot.T = T;   
+      else
+         pot.T = myreshape(T, sizes);  
+      end
+   end
+end
+pot.sizes = sizes(:)';
+pot = class(pot, 'dpot');
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot_to_table.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot_to_table.m
new file mode 100644
index 00000000..bd2d3d98
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/dpot_to_table.m
@@ -0,0 +1,3 @@
+function T = dpot_to_table(pot)
+
+T = pot.T;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/find_most_prob_entry.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/find_most_prob_entry.m
new file mode 100644
index 00000000..d30561a8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/find_most_prob_entry.m
@@ -0,0 +1,10 @@
+function [indices, pot] = find_most_prob_entry(pot)
+% function [indices, pot] = find_most_prob_entry(pot)
+% function [indices, pot] = find_most_prob_entry(pot)
+% Find the indices of the argmax, and set all other enties to 0.
+
+%indices = argmax(pot.T);
+[m i] = max(pot.T(:));
+indices = ind2subv(pot.sizes, i);
+pot.T = 0*myones(pot.sizes);
+pot.T(i) = m;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/get_fields.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/get_fields.m
new file mode 100644
index 00000000..2400bc99
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/get_fields.m
@@ -0,0 +1,13 @@
+function val = get_params(pot, name)
+% GET_PARAMS Accessor function for a field (dpot)
+% val = get_params(pot, name)
+%
+% e.g., get_params(pot, 'table') or 'domain'
+
+switch name
+ case 'table', val = pot.T;
+ case 'domain', val = pot.domain;
+ otherwise,
+  error(['invalid field name ' name]);
+end
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/marginalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/marginalize_pot.m
new file mode 100644
index 00000000..d38c5c82
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/marginalize_pot.m
@@ -0,0 +1,17 @@
+function smallpot = marginalize_pot(bigpot, onto, maximize)
+% MARGINALIZE_POT Marginalize a dpot onto a smaller domain.
+% smallpot = marginalize_pot(bigpot, onto, maximize)
+%
+% 'onto' must be in ascending order.
+
+if nargin < 3, maximize = 0; end
+
+ns = zeros(1, max(bigpot.domain));
+ns(bigpot.domain) = bigpot.sizes;
+%assert(isequal(bigpot.sizes, mysize(bigpot.T))); % may fail if there are trailing dimensions of size 1
+if issparse(bigpot.T)
+   smallT = marg_sparse_table(bigpot.T, bigpot.domain, bigpot.sizes, onto, maximize);
+else 
+   smallT = marg_table(bigpot.T, bigpot.domain, bigpot.sizes, onto, maximize);
+end
+smallpot = dpot(onto, ns(onto), smallT);
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_by_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_by_pot.m
new file mode 100644
index 00000000..ad7caaa7
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_by_pot.m
@@ -0,0 +1,13 @@
+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.
+
+%process sparse dpot, we do not consider only one of the two pots is sparse
+if issparse(Tbig.T) && issparse(Tsmall.T)
+   Tbig.T = mult_by_sparse_table(Tbig.T, Tbig.domain, Tbig.sizes, Tsmall.T, Tsmall.domain, Tsmall.sizes);
+else 
+   Tbig.T = mult_by_table(Tbig.T, Tbig.domain, Tbig.sizes, Tsmall.T, Tsmall.domain, Tsmall.sizes);
+end
+
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_pots.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_pots.m
new file mode 100644
index 00000000..0188f01b
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/multiply_pots.m
@@ -0,0 +1,12 @@
+function T = multiply_pots(T1, T2)
+% MULTIPLY_POTS Multiply a pair of dpots together pointwise.
+% T = multiply_pots(pots)
+
+dom = myunion(T1.domain, T2.domain);
+%ns = sparse(1, max(dom)); % causes problems in myreshape on NT
+ns = zeros(1, max(dom));
+ns(T1.domain) = T1.sizes;
+ns(T2.domain) = T2.sizes;
+T = dpot(dom, ns(dom));
+T = multiply_by_pot(T, T1);
+T = multiply_by_pot(T, T2);   
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/normalize_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/normalize_pot.m
new file mode 100644
index 00000000..1bc43cdb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/normalize_pot.m
@@ -0,0 +1,12 @@
+function [pot, loglik] = normalize_pot(pot)
+% NORMALIZE_POT Convert the discrete potential Pr(X,E) into Pr(X|E) and return log Pr(E).
+% [pot, loglik] = normalize_pot(pot)
+
+if isempty(pot.T)  %add to process sparse
+   loglik = 0;
+   return;
+end
+[pot.T, lik] = normalise(pot.T);
+loglik = log(lik + (lik==0)*eps);
+
+      
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/pot_to_marginal.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/pot_to_marginal.m
new file mode 100644
index 00000000..36ed70ea
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/pot_to_marginal.m
@@ -0,0 +1,12 @@
+function m = pot_to_marginal(pot)
+% POT_TO_MARGINAL Convert a dpot to a marginal structure.
+% m = pot_to_marginal(pot)
+
+m.domain = pot.domain;
+m.T = pot.T;
+m.mu = [];
+m.Sigma = [];  
+
+%if isvector(m.T)
+%  m.T = m.T(:);
+%end
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/set_domain_pot.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/set_domain_pot.m
new file mode 100644
index 00000000..2178c51d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/set_domain_pot.m
@@ -0,0 +1,5 @@
+function pot = set_domain_pot(pot, domain)
+% SET_DOMAIN_POT Change the domain of a potential (dpot)
+% pot = set_domain_pot(pot, domain)
+
+pot.domain = domain;
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/subsasgn.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/subsasgn.m
new file mode 100644
index 00000000..90d43d70
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/subsasgn.m
@@ -0,0 +1,3 @@
+function B = subsasgn(A, S, B)
+
+B = builtin('subsasgn', A, S, B);
diff --git a/sourcecodes/bnt-master/BNT/potentials/@dpot/subsref.m b/sourcecodes/bnt-master/BNT/potentials/@dpot/subsref.m
new file mode 100644
index 00000000..4a48bffe
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/potentials/@dpot/subsref.m
@@ -0,0 +1,3 @@
+function B = subsref(A, S)
+
+B = builtin('subsref', A, S);