wolffd@0
|
1 function gdl = mk_gdl_graph(G, domains, node_sizes, kernels, varargin)
|
wolffd@0
|
2 % MK_GDL_GRAPH Make a GDL (generalized distributed law) graph
|
wolffd@0
|
3 % gdl = mk_gdl_graph(G, domains, node_sizes, kernels, ...)
|
wolffd@0
|
4 %
|
wolffd@0
|
5 % A GDL graph is like a moralized, but untriangulated, Bayes net:
|
wolffd@0
|
6 % each "node" represents a domain with a corresponding kernel function.
|
wolffd@0
|
7 % For details, see "The Generalized Distributive Law", Aji and McEliece,
|
wolffd@0
|
8 % IEEE Trans. Info. Theory, 46(2): 325--343, 2000
|
wolffd@0
|
9 %
|
wolffd@0
|
10 % G(i,j) = 1 if there is an (undirected) edge between domains i,j
|
wolffd@0
|
11 %
|
wolffd@0
|
12 % domains{i} is the domain of node i
|
wolffd@0
|
13 %
|
wolffd@0
|
14 % node_sizes(i) is the number of values node i can take on,
|
wolffd@0
|
15 % or the length of node i if i is a continuous-valued vector.
|
wolffd@0
|
16 % node_sizes(i) = 1 if i is a utility node.
|
wolffd@0
|
17 %
|
wolffd@0
|
18 % kernels is the list of kernel functions
|
wolffd@0
|
19 %
|
wolffd@0
|
20 % The list below gives optional arguments [default value in brackets].
|
wolffd@0
|
21 %
|
wolffd@0
|
22 % equiv_class - equiv_class(i)=j means factor node i gets its params from factors{j} [1:F]
|
wolffd@0
|
23 % discrete - the list of nodes which are discrete random variables [1:N]
|
wolffd@0
|
24 % chance - the list of nodes which are random variables [1:N]
|
wolffd@0
|
25 % decision - the list of nodes which are decision nodes [ [] ]
|
wolffd@0
|
26 % utility - the list of nodes which are utility nodes [ [] ]
|
wolffd@0
|
27
|
wolffd@0
|
28
|
wolffd@0
|
29 ns = node_sizes;
|
wolffd@0
|
30 N = length(domains);
|
wolffd@0
|
31 vars = [];
|
wolffd@0
|
32 for i=1:N
|
wolffd@0
|
33 vars = myunion(vars, domains{i});
|
wolffd@0
|
34 end
|
wolffd@0
|
35 Nvars = length(vars);
|
wolffd@0
|
36
|
wolffd@0
|
37 gdl.equiv_class = 1:length(kernels);
|
wolffd@0
|
38 gdl.chance_nodes = 1:Nvars;
|
wolffd@0
|
39 gdl.utility_nodes = [];
|
wolffd@0
|
40 gdl.decision_nodes = [];
|
wolffd@0
|
41 gdl.dnodes = 1:Nvars;
|
wolffd@0
|
42
|
wolffd@0
|
43 if nargin >= 5
|
wolffd@0
|
44 args = varargin;
|
wolffd@0
|
45 nargs = length(args);
|
wolffd@0
|
46 for i=1:2:nargs
|
wolffd@0
|
47 switch args{i},
|
wolffd@0
|
48 case 'equiv_class', bnet.equiv_class = args{i+1};
|
wolffd@0
|
49 case 'chance', bnet.chance_nodes = args{i+1};
|
wolffd@0
|
50 case 'utility', bnet.utility_nodes = args{i+1};
|
wolffd@0
|
51 case 'decision', bnet.decision_nodes = args{i+1};
|
wolffd@0
|
52 case 'discrete', bnet.dnodes = args{i+1};
|
wolffd@0
|
53 otherwise,
|
wolffd@0
|
54 error(['invalid argument name ' args{i}]);
|
wolffd@0
|
55 end
|
wolffd@0
|
56 end
|
wolffd@0
|
57 end
|
wolffd@0
|
58
|
wolffd@0
|
59
|
wolffd@0
|
60 gdl.G = G;
|
wolffd@0
|
61 gdl.vars = vars;
|
wolffd@0
|
62 gdl.doms = domains;
|
wolffd@0
|
63 gdl.node_sizes = node_sizes;
|
wolffd@0
|
64 gdl.cnodes = mysetdiff(vars, gdl.dnodes);
|
wolffd@0
|
65 gdl.kernels = kernels;
|
wolffd@0
|
66 gdl.type = 'gdl';
|
wolffd@0
|
67
|
wolffd@0
|
68 % Compute a bit vector representation of the set of domains
|
wolffd@0
|
69 % dom_bitv(i,j) = 1 iff variable j occurs in domain i
|
wolffd@0
|
70 gdl.dom_bitv = zeros(N, length(vars));
|
wolffd@0
|
71 for i=1:N
|
wolffd@0
|
72 gdl.dom_bitv(i, domains{i}) = 1;
|
wolffd@0
|
73 end
|
wolffd@0
|
74
|
wolffd@0
|
75 % compute the interesection of the domains on either side of each edge (separating set)
|
wolffd@0
|
76 gdl.sepset = cell(N, N);
|
wolffd@0
|
77 gdl.nbrs = cell(1,N);
|
wolffd@0
|
78 for i=1:N
|
wolffd@0
|
79 nbrs = neighbors(G, i);
|
wolffd@0
|
80 gdl.nbrs{i} = nbrs;
|
wolffd@0
|
81 for j = nbrs(:)'
|
wolffd@0
|
82 gdl.sepset{i,j} = myintersect(domains{i}, domains{j});
|
wolffd@0
|
83 end
|
wolffd@0
|
84 end
|
wolffd@0
|
85
|
wolffd@0
|
86
|