To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / CPDs / @tabular_kernel / Old / tabular_kernel.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.1 KB)
| 1 |
function K = tabular_kernel(fg, self) |
|---|---|
| 2 |
% TABULAR_KERNEL Make a table-based local kernel (discrete potential) |
| 3 |
% K = tabular_kernel(fg, self) |
| 4 |
% |
| 5 |
% fg is a factor graph |
| 6 |
% self is the number of a representative domain |
| 7 |
% |
| 8 |
% Use 'set_params_kernel' to adjust the following fields |
| 9 |
% table - a q[1]xq[2]x... array, where q[i] is the number of values for i'th node |
| 10 |
% in this domain [default: random values from [0,1], which need not sum to 1] |
| 11 |
|
| 12 |
|
| 13 |
if nargin==0 |
| 14 |
% This occurs if we are trying to load an object from a file. |
| 15 |
K = init_fields; |
| 16 |
K = class(K, 'tabular_kernel'); |
| 17 |
return; |
| 18 |
elseif isa(fg, 'tabular_kernel') |
| 19 |
% This might occur if we are copying an object. |
| 20 |
K = fg; |
| 21 |
return; |
| 22 |
end |
| 23 |
K = init_fields; |
| 24 |
|
| 25 |
ns = fg.node_sizes; |
| 26 |
dom = fg.doms{self};
|
| 27 |
% we don't store the actual domain since it may vary due to parameter tieing |
| 28 |
K.sz = ns(dom); |
| 29 |
K.table = myrand(K.sz); |
| 30 |
|
| 31 |
K = class(K, 'tabular_kernel'); |
| 32 |
|
| 33 |
|
| 34 |
%%%%%%% |
| 35 |
|
| 36 |
|
| 37 |
function K = init_fields() |
| 38 |
% This ensures we define the fields in the same order |
| 39 |
% no matter whether we load an object from a file, |
| 40 |
% or create it from scratch. (Matlab requires this.) |
| 41 |
|
| 42 |
K.table = []; |
| 43 |
K.sz = []; |
| 44 |
|
| 45 |
|