wolffd@0: function CPD = tabular_utility_node(bnet, node, T) wolffd@0: % TABULAR_UTILITY_NODE Represent a utility function as a table wolffd@0: % CPD = tabular_utility_node(bnet, node, T) wolffd@0: % wolffd@0: % node is the number of a node in this equivalence class. wolffd@0: % T is an optional argument (same shape as the CPT in tabular_CPD, but missing the last (child) wolffd@0: % dimension). By default, entries in T are chosen u.a.r. from 0:1 (using 'rand'). wolffd@0: wolffd@0: if nargin==0 wolffd@0: % This occurs if we are trying to load an object from a file. wolffd@0: CPD = init_fields; wolffd@0: clamp = 0; wolffd@0: CPD = class(CPD, 'tabular_utility_node'); wolffd@0: return; wolffd@0: elseif isa(bnet, 'tabular_utility_node') wolffd@0: % This might occur if we are copying an object. wolffd@0: CPD = bnet; wolffd@0: return; wolffd@0: end wolffd@0: CPD = init_fields; wolffd@0: wolffd@0: wolffd@0: ns = bnet.node_sizes; wolffd@0: ps = parents(bnet.dag, node); wolffd@0: sz = ns(ps); wolffd@0: wolffd@0: if nargin < 3 wolffd@0: T = myrand(sz); wolffd@0: else wolffd@0: T = myreshape(T, sz); wolffd@0: end wolffd@0: wolffd@0: CPD.T = T; wolffd@0: CPD.sizes = sz; wolffd@0: wolffd@0: CPD = class(CPD, 'tabular_utility_node'); wolffd@0: wolffd@0: %%%%%%%%%%% wolffd@0: wolffd@0: function CPD = init_fields() wolffd@0: % This ensures we define the fields in the same order wolffd@0: % no matter whether we load an object from a file, wolffd@0: % or create it from scratch. (Matlab requires this.) wolffd@0: wolffd@0: CPD.T = []; wolffd@0: CPD.sizes = [];