annotate toolboxes/FullBNT-1.0.7/bnt/general/Old/mk_gdl_graph.m @ 0:cc4b1211e677 tip

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