comparison toolboxes/FullBNT-1.0.7/bnt/general/Old/mk_gdl_graph.m @ 0:e9a9cd732c1e tip

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