-
Notifications
You must be signed in to change notification settings - Fork 15
/
LBP_sum_product.m
32 lines (32 loc) · 1.24 KB
/
LBP_sum_product.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function [assignment, T] = LBP_sum_product(initial_labeling, graph, lambda, maxIte)
%implement the loopy belief propagation sum product algorithm
%the transition matrix is defined as follow:
%1 on the diagonal and exp(lambda) outside
%INPUT
%inital_labeling = classification to regularize
%graph = the adjacency structure
%lambda = the regularization strength (>0)
%maxIte = maximum number of iteration (default = 30)
%
%When using this method you must cite:
%M. Schmidt. UGM: A Matlab toolbox for probabilistic undirected graphical
%models. http://www.cs.ubc.ca/~schmidtm/Software/UGM.html, 2007.
if (nargin < 4)
maxIte = 30;
end
nClasses = size(initial_labeling,2);
%it is necessary to have a symetric structure for this algorithm
adjacency = sparse(double(graph.source)+1,double(graph.target)+1 ...
, double(graph.edge_weight));
edgeStruct = UGM_makeEdgeStruct(adjacency,nClasses,1);
unary = initial_labeling;
transition = single(ones(nClasses));
transition(logical(eye(nClasses))) = single(exp(lambda));
binary = repmat(transition, [1 1 edgeStruct.nEdges]);
edgeStruct.useMex = 1;
edgeStruct.maxIter = int32(maxIte);
tic;
clear('V','adj')
[nodeBelLBP] = UGM_Infer_LBP(unary,binary,edgeStruct);
assignment = nodeBelLBP;
T = toc;