wolffd@0: function engine = belprop_inf_engine(fg, max_iter, momentum, tol, maximize) wolffd@0: wolffd@0: if nargin < 2, max_iter = length(fg.G); end wolffd@0: if nargin < 3, momentum = 0; end wolffd@0: if nargin < 4, tol = 1e-3; end wolffd@0: if nargin < 5, maximize = 0; end wolffd@0: wolffd@0: engine.fgraph = fg; wolffd@0: engine.max_iter = max_iter; wolffd@0: engine.momentum = momentum; wolffd@0: engine.tol = tol; wolffd@0: engine.maximize = maximize; wolffd@0: wolffd@0: % store results computed by enter_evidence here wolffd@0: ndoms = length(fg.doms); wolffd@0: nvars = length(fg.vars); wolffd@0: engine.marginal_domains = cell(1, ndoms); wolffd@0: wolffd@0: % to compute the marginal on each variable, we need to know which domain to marginalize wolffd@0: % so we represent each domain as a bit vector, and compute its (pre-evidence) weight wolffd@0: engine.dom_weight = []; wolffd@0: wolffd@0: % engine.dom_bitv = sparse(ndoms, nvars); wolffd@0: % ns = fg.node_sizes; wolffd@0: % for i=1:ndoms wolffd@0: % engine.dom_bitv(i, fg.doms{i}) = 1; wolffd@0: % engine.dom_weight(i) = prod(ns(fg.doms{i})); wolffd@0: % end wolffd@0: wolffd@0: wolffd@0: engine = class(engine, 'belprop_inf_engine');