Daniel@0: function CPD = tabular_utility_node(bnet, node, T) Daniel@0: % TABULAR_UTILITY_NODE Represent a utility function as a table Daniel@0: % CPD = tabular_utility_node(bnet, node, T) Daniel@0: % Daniel@0: % node is the number of a node in this equivalence class. Daniel@0: % T is an optional argument (same shape as the CPT in tabular_CPD, but missing the last (child) Daniel@0: % dimension). By default, entries in T are chosen u.a.r. from 0:1 (using 'rand'). Daniel@0: Daniel@0: if nargin==0 Daniel@0: % This occurs if we are trying to load an object from a file. Daniel@0: CPD = init_fields; Daniel@0: clamp = 0; Daniel@0: CPD = class(CPD, 'tabular_utility_node'); Daniel@0: return; Daniel@0: elseif isa(bnet, 'tabular_utility_node') Daniel@0: % This might occur if we are copying an object. Daniel@0: CPD = bnet; Daniel@0: return; Daniel@0: end Daniel@0: CPD = init_fields; Daniel@0: Daniel@0: Daniel@0: ns = bnet.node_sizes; Daniel@0: ps = parents(bnet.dag, node); Daniel@0: sz = ns(ps); Daniel@0: Daniel@0: if nargin < 3 Daniel@0: T = myrand(sz); Daniel@0: else Daniel@0: T = myreshape(T, sz); Daniel@0: end Daniel@0: Daniel@0: CPD.T = T; Daniel@0: CPD.sizes = sz; Daniel@0: Daniel@0: CPD = class(CPD, 'tabular_utility_node'); Daniel@0: Daniel@0: %%%%%%%%%%% Daniel@0: Daniel@0: function CPD = 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: CPD.T = []; Daniel@0: CPD.sizes = [];