To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _FullBNT / BNT / CPDs / @tabular_utility_node / tabular_utility_node.m @ 8:b5b38998ef3b

History | View | Annotate | Download (1.11 KB)

1
function CPD = tabular_utility_node(bnet, node, T)
2
% TABULAR_UTILITY_NODE Represent a utility function as a table
3
% CPD = tabular_utility_node(bnet, node, T)
4
%
5
% node is the number of a node in this equivalence class.
6
% T is an optional argument (same shape as the CPT in tabular_CPD, but missing the last (child)
7
% dimension). By default, entries in T are chosen u.a.r. from 0:1 (using 'rand').
8

    
9
if nargin==0
10
  % This occurs if we are trying to load an object from a file.
11
  CPD = init_fields;
12
  clamp = 0;
13
  CPD = class(CPD, 'tabular_utility_node');
14
  return;
15
elseif isa(bnet, 'tabular_utility_node')
16
  % This might occur if we are copying an object.
17
  CPD = bnet;
18
  return;
19
end
20
CPD = init_fields;
21

    
22

    
23
ns = bnet.node_sizes;
24
ps = parents(bnet.dag, node);
25
sz = ns(ps);
26

    
27
if nargin < 3
28
  T = myrand(sz);
29
else
30
  T = myreshape(T, sz);
31
end
32

    
33
CPD.T = T;
34
CPD.sizes = sz;
35

    
36
CPD = class(CPD, 'tabular_utility_node');
37

    
38
%%%%%%%%%%%
39

    
40
function CPD = init_fields()
41
% This ensures we define the fields in the same order 
42
% no matter whether we load an object from a file,
43
% or create it from scratch. (Matlab requires this.)
44

    
45
CPD.T = [];
46
CPD.sizes = [];