-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathNormL1.m
More file actions
31 lines (27 loc) · 715 Bytes
/
NormL1.m
File metadata and controls
31 lines (27 loc) · 715 Bytes
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
classdef NormL1 < NormObj
methods
function obj = NormL1(weights)
obj = obj@NormObj();
if (nargin == 1)
obj.weights = weights;
end
end
function p = primal(obj, x)
p = norm(x.*obj.weights,1);
end
function d = dual(obj, y)
d = norm(y./obj.weights,inf);
end
function p = project(obj, x, tau)
if isreal(x)
p = oneProjector(x,obj.weights,tau);
else
xa = abs(x);
idx = xa < eps;
xc = oneProjector(xa,obj.weights,tau);
xc = xc ./ xa; xc(idx) = 0;
p = x .* xc;
end
end
end
end