Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/general/mk_fgraph.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 fg = mk_fgraph(G, node_sizes, factors, varargin) | |
2 % MK_FGRAPH Make a factor graph | |
3 % fg = mk_fgraph(G, node_sizes, factors, ...) | |
4 % | |
5 % A factor graph is a bipartite graph, with one side containing variables, | |
6 % and the other containing functions of (subsets of) these variables. | |
7 % For details, see "Factor Graphs and the Sum-Product Algorithm", | |
8 % F. Kschischang and B. Frey and H-A. Loeliger, | |
9 % IEEE Trans. Info. Theory, 2001 | |
10 % | |
11 % G(i,j) = 1 if there is an arc from variable i to factor j | |
12 % | |
13 % node_sizes(i) is the number of values node i can take on, | |
14 % or the length of node i if i is a continuous-valued vector. | |
15 % | |
16 % 'factors' is the list of factors (kernel functions) | |
17 % | |
18 % The list below gives optional arguments [default value in brackets]. | |
19 % | |
20 % equiv_class - equiv_class(i)=j means factor node i gets its params from factors{j} [1:F] | |
21 % discrete - the list of nodes which are discrete random variables [1:N] | |
22 % | |
23 % e.g., fg = mk_fgraph(G, [2 2], {bnet.CPD{1},bnet.CPD{2}}, 'discrete', [1 2]) | |
24 | |
25 fg.G = G; | |
26 fg.node_sizes = node_sizes; | |
27 fg.factors = factors; | |
28 [fg.nvars fg.nfactors] = size(G); | |
29 | |
30 % default values for parameters | |
31 fg.equiv_class = 1:fg.nfactors; | |
32 fg.dnodes = 1:fg.nvars; | |
33 | |
34 if nargin >= 4 | |
35 args = varargin; | |
36 nargs = length(args); | |
37 for i=1:2:nargs | |
38 switch args{i}, | |
39 case 'equiv_class', fg.equiv_class = args{i+1}; | |
40 case 'discrete', fg.dnodes = args{i+1}; | |
41 otherwise, | |
42 error(['invalid argument name ' args{i}]); | |
43 end | |
44 end | |
45 end | |
46 | |
47 % so that determine_pot_type will work... | |
48 fg.utility_nodes = []; | |
49 %fg.decision_nodes = []; | |
50 %fg.chance_nodes = fg.nvars; | |
51 | |
52 fg.dom = cell(1, fg.nfactors); | |
53 for f=1:fg.nfactors | |
54 fg.dom{f} = find(G(:,f)); | |
55 end | |
56 fg.dep = cell(1, fg.nvars); | |
57 for x=1:fg.nvars | |
58 fg.dep{x} = find(G(x,:)); | |
59 end | |
60 fg.cnodes = mysetdiff(1:fg.nvars, fg.dnodes); |