-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathL0_cut_pursuit.m
53 lines (52 loc) · 1.87 KB
/
L0_cut_pursuit.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function p_regularized = L0_cut_pursuit(initial_p, graph, lambda, fidelity)
%L0-Cut Pursuit to solkve penalization by the boundary length
%INPUT
%inital_labeling = classification to regularize
%graph = the adjacency structure
%fidelity = which fidelity fucntion to use (default = 0)
% 0 : linear
% 1 : quadratic
% 2 : KL with 0.05 uniform smoothing
% 3 : loglinear with 0.05 uniform smoothing
%lambda : regularization strength (default = 1)
%maxIte : maximum number of alpha expansion cycle (default = 5)
%benchMarking: if true will return the energy and time for the algorithm
% : stopped after 1 ... maxIte iteration, starting from zero
% each time
%OUTPUT
%p_regularized = the regularized probability
%loic landrieu 2016
%
%When using this method you must cite:
%
%Cut Pursuit: fast algorithms to learn piecewise constant functions on
%general weighted graphs,
%Landrieu, Loic and Obozinski, Guillaume,2016.
smoothing = single(0.05);
if (nargin < 3)
lambda = 1;
end
if (nargin < 4)
fidelity = 1;
end
nClasses = size(initial_p,2);
node_weight = single(ones(size(initial_p,1),1));
switch fidelity
case 0
p_regularized = L0_cut_pursuit_mex(initial_p', graph.source...
,graph.target, lambda, graph.edge_weight, node_weight...
, 0, 2, 0);
case 1
p_regularized = L0_cut_pursuit_mex(initial_p', graph.source...
,graph.target, lambda, graph.edge_weight, node_weight...
, 1, 2, 0);
case 2
p_regularized = L0_cut_pursuit_mex(initial_p', graph.source...
,graph.target, lambda, graph.edge_weight, node_weight...
, smoothing, 2, 0);
case 3
p_regularized = L0_cut_pursuit_mex(log(initial_p' ...
* (1-smoothing + smoothing/nClasses)), graph.source...
,graph.target, lambda, graph.edge_weight, node_weight...
, 0, 2, 0);
end