-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpenalty_function.m
More file actions
51 lines (40 loc) · 1.09 KB
/
penalty_function.m
File metadata and controls
51 lines (40 loc) · 1.09 KB
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
function theta = penalty_function(u, sigma, method, p)
% penalty_function implements different forms of objective functions.
% C = penalty_function(u, sigma, method, p)
% defaults:
% method = 'logbarrier'
% p = 2
% method = 'norm' for norm with parameter p
% method = 'deadzone for Deadzone-linear penalty function
% method = 'logbarrier' for Log barrier penalty function
%
% p is the norm number and is only used if method=0
if nargin <= 2
method = 'logbarrier';
end
if nargin <= 3
p = 2;
end
switch method
case 'norm'
theta = norm(u, p);
case 'deadzone'
theta = deadzone(u, sigma);
case 'logbarrier'
theta = log_barrier(u, sigma);
otherwise
error('method type not understood')
end
return
end
function theta = deadzone(u, sigma)
theta = abs(u);
idx = abs(u) < sigma;
theta(idx) = 0;
end
function theta = log_barrier(u, sigma)
theta = ones(size(u)) * inf;
tmp = -sigma^2 * log(1-(u/sigma).^2);
idx = abs(u) < sigma;
theta(idx) = tmp(idx);
end