-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprox_overlap.m
50 lines (43 loc) · 1.07 KB
/
prox_overlap.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
% copyright 2012 Andreas Argyriou
% GPL License http://www.gnu.org/copyleft/gpl.html
function [ q , p, r, l] = prox_overlap( v, k, L)
% Compute prox_f(v) for f = 1/(2L) ||.||^2
% and ||.|| the k overlap norm
d = length(v);
[beta, order] = sort(abs(v), 'descend');
beta = beta * L;
beta(d+1) = -inf;
found = false;
for l=k:d
temp = sum(beta(k:l));
for r=0:k-2
if ( (temp >= (l-k+(L+1)*r+L+1)*beta(k-r)/(L+1)) && ...
(temp < (l-k+(L+1)*r+L+1)*beta(k-r-1)/(L+1)) && ...
(temp >= (l-k+(L+1)*r+L+1)*beta(l+1)) && ...
(temp < (l-k+(L+1)*r+L+1)*beta(l)) )
found = true;
break;
else
temp = temp + beta(k-r-1);
end
end
if (~found)
r = k-1;
if ( (temp >= (l-k+(L+1)*r+L+1)*beta(k-r)/(L+1)) && ...
(temp >= (l-k+(L+1)*r+L+1)*beta(l+1)) && ...
(temp < (l-k+(L+1)*r+L+1)*beta(l)) )
found = true;
break;
end
else
break;
end
end
p(1:k-r-1) = beta(1:k-r-1)/(L+1);
p(k-r:l) = temp / (l-k+(L+1)*r+L+1);
p(l+1:d) = beta(l+1:d);
p = p';
[dummy, rev]=sort(order,'ascend');
p = sign(v) .* p(rev);
q = v - 1/L*p;
end