comparison toolboxes/FullBNT-1.0.7/bnt/inference/static/@belprop_mrf2_inf_engine/belprop_mrf2_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_mrf2_inf_engine(mrf2, varargin)
2 % BELPROP_MRF2_INF_ENGINE Belief propagation for MRFs with discrete pairwise potentials
3 % engine = belprop_mrf2_inf_engine(mrf2, ...)
4 %
5 % This is like belprop_inf_engine, except it is designed for mrf2, so is much faster.
6 %
7 % [ ... ] = belprop_mrf2_inf_engine(..., 'param1',val1, 'param2',val2, ...)
8 % allows you to specify optional parameters as name/value pairs.
9 % Parameters modifying behavior of enter_evidence are below [default value in brackets]
10 %
11 % max_iter - max. num. iterations [ 5*nnodes]
12 % momentum - weight assigned to old message in convex combination
13 % (useful for damping oscillations) [0]
14 % tol - tolerance used to assess convergence [1e-3]
15 % verbose - 1 means print error at every iteration [0]
16 %
17 % Parameters can be changed later using set_params
18
19
20 % The advantages of pairwise potentials are
21 % (1) we can compute messages using vector-matrix multiplication
22 % (2) we can easily specify the parameters: one potential per edge
23 % In contrast, potentials on larger cliques are more complicated to deal with.
24
25
26 nnodes = length(mrf2.adj_mat);
27
28 [engine.max_iter, engine.momentum, engine.tol, engine.verbose] = ...
29 process_options(varargin, 'max_iter', [], 'momentum', 0, 'tol', 1e-3, ...
30 'verbose', 0);
31
32 if isempty(engine.max_iter) % no user supplied value, so compute default
33 engine.max_iter = 5*nnodes;
34 %if acyclic(mrf2.adj_mat, 0) --- can be very slow!
35 % engine.max_iter = nnodes;
36 %else
37 % engine.max_iter = 5*nnodes;
38 %end
39 end
40
41 engine.bel = cell(1, nnodes); % store results of enter_evidence here
42 engine.mrf2 = mrf2;
43
44 engine = class(engine, 'belprop_mrf2_inf_engine');
45
46