wolffd@0: function engine = belprop_fg_inf_engine(fg, varargin) wolffd@0: % BELPROP_FG_INF_ENGINE Make a belief propagation inference engine for factor graphs wolffd@0: % engine = belprop_fg_inf_engine(factor_graph, ...) wolffd@0: % wolffd@0: % The following optional arguments can be specified in the form of name/value pairs: wolffd@0: % [default in brackets] wolffd@0: % e.g., engine = belprop_inf_engine(fg, 'tol', 1e-2, 'max_iter', 10) wolffd@0: % wolffd@0: % max_iter - max. num. iterations [ 2*num_nodes ] wolffd@0: % momentum - weight assigned to old message in convex combination (useful for damping oscillations) [0] wolffd@0: % tol - tolerance used to assess convergence [1e-3] wolffd@0: % maximize - 1 means use max-product, 0 means use sum-product [0] wolffd@0: % wolffd@0: % This uses potential objects, like belprop_inf_engine, and hence is quite slow. wolffd@0: wolffd@0: engine = init_fields; wolffd@0: engine = class(engine, 'belprop_fg_inf_engine'); wolffd@0: wolffd@0: % set params to default values wolffd@0: N = length(fg.G); wolffd@0: engine.max_iter = 2*N; wolffd@0: engine.momentum = 0; wolffd@0: engine.tol = 1e-3; wolffd@0: engine.maximize = 0; wolffd@0: wolffd@0: % parse optional arguments wolffd@0: engine = set_params(engine, varargin); wolffd@0: wolffd@0: engine.fgraph = fg; wolffd@0: wolffd@0: % store results computed by enter_evidence here wolffd@0: engine.marginal_nodes = cell(1, fg.nvars); wolffd@0: engine.evidence = []; wolffd@0: wolffd@0: wolffd@0: %%%%%%%%%%%% wolffd@0: wolffd@0: function engine = init_fields() wolffd@0: wolffd@0: engine.fgraph = []; wolffd@0: engine.max_iter = []; wolffd@0: engine.momentum = []; wolffd@0: engine.tol = []; wolffd@0: engine.maximize = []; wolffd@0: engine.marginal_nodes = []; wolffd@0: engine.evidence = []; wolffd@0: engine.niter = [];