Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/bnt/inference/static/@belprop_fg_inf_engine/belprop_fg_inf_engine.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function engine = belprop_fg_inf_engine(fg, varargin) |
wolffd@0 | 2 % BELPROP_FG_INF_ENGINE Make a belief propagation inference engine for factor graphs |
wolffd@0 | 3 % engine = belprop_fg_inf_engine(factor_graph, ...) |
wolffd@0 | 4 % |
wolffd@0 | 5 % The following optional arguments can be specified in the form of name/value pairs: |
wolffd@0 | 6 % [default in brackets] |
wolffd@0 | 7 % e.g., engine = belprop_inf_engine(fg, 'tol', 1e-2, 'max_iter', 10) |
wolffd@0 | 8 % |
wolffd@0 | 9 % max_iter - max. num. iterations [ 2*num_nodes ] |
wolffd@0 | 10 % momentum - weight assigned to old message in convex combination (useful for damping oscillations) [0] |
wolffd@0 | 11 % tol - tolerance used to assess convergence [1e-3] |
wolffd@0 | 12 % maximize - 1 means use max-product, 0 means use sum-product [0] |
wolffd@0 | 13 % |
wolffd@0 | 14 % This uses potential objects, like belprop_inf_engine, and hence is quite slow. |
wolffd@0 | 15 |
wolffd@0 | 16 engine = init_fields; |
wolffd@0 | 17 engine = class(engine, 'belprop_fg_inf_engine'); |
wolffd@0 | 18 |
wolffd@0 | 19 % set params to default values |
wolffd@0 | 20 N = length(fg.G); |
wolffd@0 | 21 engine.max_iter = 2*N; |
wolffd@0 | 22 engine.momentum = 0; |
wolffd@0 | 23 engine.tol = 1e-3; |
wolffd@0 | 24 engine.maximize = 0; |
wolffd@0 | 25 |
wolffd@0 | 26 % parse optional arguments |
wolffd@0 | 27 engine = set_params(engine, varargin); |
wolffd@0 | 28 |
wolffd@0 | 29 engine.fgraph = fg; |
wolffd@0 | 30 |
wolffd@0 | 31 % store results computed by enter_evidence here |
wolffd@0 | 32 engine.marginal_nodes = cell(1, fg.nvars); |
wolffd@0 | 33 engine.evidence = []; |
wolffd@0 | 34 |
wolffd@0 | 35 |
wolffd@0 | 36 %%%%%%%%%%%% |
wolffd@0 | 37 |
wolffd@0 | 38 function engine = init_fields() |
wolffd@0 | 39 |
wolffd@0 | 40 engine.fgraph = []; |
wolffd@0 | 41 engine.max_iter = []; |
wolffd@0 | 42 engine.momentum = []; |
wolffd@0 | 43 engine.tol = []; |
wolffd@0 | 44 engine.maximize = []; |
wolffd@0 | 45 engine.marginal_nodes = []; |
wolffd@0 | 46 engine.evidence = []; |
wolffd@0 | 47 engine.niter = []; |