Mercurial > hg > camir-aes2014
comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@belprop_inf_engine/Old/belprop_gdl_inf_engine.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 engine = belprop_gdl_inf_engine(gdl, varargin) | |
2 % BELPROP_GDL_INF_ENGINE Make a belief propagation inference engine for a GDL graph | |
3 % engine = belprop_gdl_inf_engine(gdl_graph, ...) | |
4 % | |
5 % If the GDL graph is a tree, this will give exact results. | |
6 % | |
7 % The following optional arguments can be specified in the form of name/value pairs: | |
8 % [default in brackets] | |
9 % e.g., engine = belprop_inf_engine(gdl, 'tol', 1e-2, 'max_iter', 10) | |
10 % | |
11 % protocol - 'tree' means send messages up then down the tree, | |
12 % 'parallel' means use synchronous updates ['parallel'] | |
13 % max_iter - max. num. iterations [ 2*num_nodes ] | |
14 % momentum - weight assigned to old message in convex combination (useful for damping oscillations) [0] | |
15 % tol - tolerance used to assess convergence [1e-3] | |
16 % maximize - 1 means use max-product, 0 means use sum-product [0] | |
17 | |
18 | |
19 engine = init_fields; | |
20 engine = class(engine, 'belprop_gdl_inf_engine'); | |
21 | |
22 % set default params | |
23 N = length(gdl.G); | |
24 engine.protocol = 'parallel'; | |
25 engine.max_iter = 2*N; | |
26 engine.momentum = 0; | |
27 engine.tol = 1e-3; | |
28 engine.maximize = 0; | |
29 | |
30 engine = set_params(engine, varargin); | |
31 | |
32 engine.gdl = gdl; | |
33 | |
34 if strcmp(engine.protocol, 'tree') | |
35 % Make a rooted tree, so there is a fixed message passing order. | |
36 root = N; | |
37 [engine.tree, engine.preorder, engine.postorder, height, cyclic] = mk_rooted_tree(gdl.G, root); | |
38 assert(~cyclic); | |
39 end | |
40 | |
41 % store results computed by enter_evidence here | |
42 ndoms = length(gdl.doms); | |
43 nvars = length(gdl.vars); | |
44 engine.marginal_domains = cell(1, ndoms); | |
45 | |
46 % to compute the marginal on each variable, we need to know which domain to marginalize | |
47 % and we want to choose the lightest. We compute the weight once we have seen the evidence. | |
48 engine.dom_weight = []; | |
49 engine.evidence = []; | |
50 | |
51 | |
52 %%%%%%%%% | |
53 | |
54 function engine = init_fields() | |
55 | |
56 engine.protocol = []; | |
57 engine.gdl = []; | |
58 engine.max_iter = []; | |
59 engine.momentum = []; | |
60 engine.tol = []; | |
61 engine.maximize = []; | |
62 engine.marginal_domains = []; | |
63 engine.evidence = []; | |
64 engine.tree = []; | |
65 engine.preorder = []; | |
66 engine.postorder = []; | |
67 engine.dom_weight = []; |