about summary refs log tree commit diff
path: root/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel
diff options
context:
space:
mode:
Diffstat (limited to 'sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel')
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries6
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries.Log1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Entries2
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Repository1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Root1
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/tabular_kernel.m45
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_pot.m37
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_table.m13
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/get_field.m11
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/set_fields.m13
-rw-r--r--sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/tabular_kernel.m40
13 files changed, 172 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries
new file mode 100644
index 00000000..45d8ee0d
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries
@@ -0,0 +1,6 @@
+/convert_to_pot.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/convert_to_table.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/get_field.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/set_fields.m/1.1.1.1/Wed May 29 15:59:54 2002//
+/tabular_kernel.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries.Log b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries.Log
new file mode 100644
index 00000000..24f16336
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Entries.Log
@@ -0,0 +1 @@
+A D/Old////
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Repository
new file mode 100644
index 00000000..61f9dcd8
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/CPDs/@tabular_kernel
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Entries b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Entries
new file mode 100644
index 00000000..b6c6e11c
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Entries
@@ -0,0 +1,2 @@
+/tabular_kernel.m/1.1.1.1/Wed May 29 15:59:54 2002//
+D
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Repository b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Repository
new file mode 100644
index 00000000..d2036843
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Repository
@@ -0,0 +1 @@
+FullBNT/BNT/CPDs/@tabular_kernel/Old
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Root b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Root
new file mode 100644
index 00000000..f3bd14a6
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/CVS/Root
@@ -0,0 +1 @@
+:ext:nsaunier@bnt.cvs.sourceforge.net:/cvsroot/bnt
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/tabular_kernel.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/tabular_kernel.m
new file mode 100644
index 00000000..99f74450
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/Old/tabular_kernel.m
@@ -0,0 +1,45 @@
+function K = tabular_kernel(fg, self)
+% TABULAR_KERNEL Make a table-based local kernel (discrete potential)
+% K = tabular_kernel(fg, self)
+%
+% fg is a factor graph
+% self is the number of a representative domain
+%
+% Use 'set_params_kernel' to adjust the following fields
+%   table - a q[1]xq[2]x... array, where q[i] is the number of values for i'th node
+%       in this domain [default: random values from [0,1], which need not sum to 1]
+
+
+if nargin==0
+  % This occurs if we are trying to load an object from a file.
+  K = init_fields;
+  K = class(K, 'tabular_kernel');
+  return;
+elseif isa(fg, 'tabular_kernel')
+  % This might occur if we are copying an object.
+  K = fg;
+  return;
+end
+K = init_fields;
+
+ns = fg.node_sizes;
+dom = fg.doms{self};
+% we don't store the actual domain since it may vary due to parameter tieing
+K.sz = ns(dom);
+K.table = myrand(K.sz);
+
+K = class(K, 'tabular_kernel');
+
+
+%%%%%%%
+
+
+function K = 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.)
+
+K.table = [];
+K.sz = [];
+
+
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_pot.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_pot.m
new file mode 100644
index 00000000..8f9adff1
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_pot.m
@@ -0,0 +1,37 @@
+function pot = convert_to_pot(CPD, pot_type, domain, evidence)
+% CONVERT_TO_POT Convert a tabular CPD to one or more potentials
+% pot = convert_to_pot(CPD, pot_type, domain, evidence)
+
+% This is the same as discrete_CPD/convert_to_pot,
+% except we didn't want to the kernel to inherit methods like sample_node etc.
+
+sz = CPD.sz;
+ns = zeros(1, max(domain));
+ns(domain) = sz;
+
+odom = domain(~isemptycell(evidence(domain)));
+T = convert_to_table(CPD, domain, evidence);
+
+switch pot_type
+ case 'u',
+  pot = upot(domain, sz, T, 0*myones(sz));  
+ case 'd',
+  ns(odom) = 1;
+  pot = dpot(domain, ns(domain), T);          
+ case 'c',
+  % Since we want the output to be a Gaussian, the whole family must be observed.
+  % In other words, the potential is really just a constant.
+  p = T.p;
+  %p = prob_node(CPD, evidence(domain(end)), evidence(domain(1:end-1)));
+  ns(domain) = 0;
+  pot = cpot(domain, ns(domain), log(p));       
+ case 'cg',
+  T = T(:);
+  ns(odom) = 1;
+  can = cell(1, length(T));
+  for i=1:length(T)
+    can{i} = cpot([], [], log(T(i)));
+  end
+  pot = cgpot(domain, [], ns, can);   
+end
+
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_table.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_table.m
new file mode 100644
index 00000000..30703f3a
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/convert_to_table.m
@@ -0,0 +1,13 @@
+function T = convert_to_table(CPD, domain, evidence)
+% CONVERT_TO_TABLE Convert a discrete CPD to a table
+% T = convert_to_table(CPD, domain, evidence)
+%
+% We convert the CPD to a CPT, and then lookup the evidence on the discrete parents.
+% The resulting table can easily be converted to a potential.
+
+CPT = CPD.table;
+odom = domain(~isemptycell(evidence(domain)));
+vals = cat(1, evidence{odom});
+map = find_equiv_posns(odom, domain);
+index = mk_multi_index(length(domain), map, vals);
+T = CPT(index{:});               
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/get_field.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/get_field.m
new file mode 100644
index 00000000..3319eadb
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/get_field.m
@@ -0,0 +1,11 @@
+function val = get_params_kernel(K, name)
+% GET_PARAMS_KERNEL Accessor function for a field (tabular_kernel)
+% val = get_params_kernel(K, name)
+%
+% e.g., get_params_kernel(K, 'table')
+
+switch name
+ case 'table', val = K.table;
+ otherwise,
+  error(['invalid field name ' name]);
+end
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/set_fields.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/set_fields.m
new file mode 100644
index 00000000..2f7ac435
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/set_fields.m
@@ -0,0 +1,13 @@
+function K = set_params_kernel(K, name, val)
+% SET_PARAMS_KERNEL Accessor function for a field (table_kernel)
+% K = set_params_kernel(K, name, val)
+%
+% e.g., K = set_params_kernel(K, 'table', rand(2,3,2)) for a kernel on 3 nodes with 2,3,2 values each
+
+% We should check if the arguments are valid...
+
+switch name
+ case 'table', K.table = val;
+ otherwise,
+  error(['invalid field name ' name]);
+end
diff --git a/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/tabular_kernel.m b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/tabular_kernel.m
new file mode 100644
index 00000000..74a64450
--- /dev/null
+++ b/sourcecodes/bnt-master/BNT/CPDs/@tabular_kernel/tabular_kernel.m
@@ -0,0 +1,40 @@
+function K = tabular_kernel(sz, table)
+% TABULAR_KERNEL Make a table-based local kernel (discrete potential)
+% K = tabular_kernel(sz, table)
+%
+% sz(i) is the number of values the i'th member of this kernel can have
+% table is an optional array of size sz[1] x sz[2] x... [default: random]
+
+if nargin==0
+  % This occurs if we are trying to load an object from a file.
+  K = init_fields;
+  K = class(K, 'tabular_kernel');
+  return;
+elseif isa(sz, 'tabular_kernel')
+  % This might occur if we are copying an object.
+  K = sz;
+  return;
+end
+K = init_fields;
+
+if nargin < 2, table = myrand(sz); end
+
+K.sz = sz;
+K.table = table;
+
+K = class(K, 'tabular_kernel');
+
+
+%%%%%%%
+
+
+function K = 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.)
+
+K.sz = [];
+K.table = [];
+
+
+