Daniel@0: function K = tabular_kernel(fg, self) Daniel@0: % TABULAR_KERNEL Make a table-based local kernel (discrete potential) Daniel@0: % K = tabular_kernel(fg, self) Daniel@0: % Daniel@0: % fg is a factor graph Daniel@0: % self is the number of a representative domain Daniel@0: % Daniel@0: % Use 'set_params_kernel' to adjust the following fields Daniel@0: % table - a q[1]xq[2]x... array, where q[i] is the number of values for i'th node Daniel@0: % in this domain [default: random values from [0,1], which need not sum to 1] Daniel@0: Daniel@0: Daniel@0: if nargin==0 Daniel@0: % This occurs if we are trying to load an object from a file. Daniel@0: K = init_fields; Daniel@0: K = class(K, 'tabular_kernel'); Daniel@0: return; Daniel@0: elseif isa(fg, 'tabular_kernel') Daniel@0: % This might occur if we are copying an object. Daniel@0: K = fg; Daniel@0: return; Daniel@0: end Daniel@0: K = init_fields; Daniel@0: Daniel@0: ns = fg.node_sizes; Daniel@0: dom = fg.doms{self}; Daniel@0: % we don't store the actual domain since it may vary due to parameter tieing Daniel@0: K.sz = ns(dom); Daniel@0: K.table = myrand(K.sz); Daniel@0: Daniel@0: K = class(K, 'tabular_kernel'); Daniel@0: Daniel@0: Daniel@0: %%%%%%% Daniel@0: Daniel@0: Daniel@0: function K = init_fields() Daniel@0: % This ensures we define the fields in the same order Daniel@0: % no matter whether we load an object from a file, Daniel@0: % or create it from scratch. (Matlab requires this.) Daniel@0: Daniel@0: K.table = []; Daniel@0: K.sz = []; Daniel@0: Daniel@0: