-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmm.m
121 lines (95 loc) · 2.79 KB
/
admm.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
function [z, history] = admm(A, b, mu, rho, alpha)
% logreg Solve L1 regularized logistic regression via ADMM
%
% solves the following problem via ADMM:%
% minimize E_D(d(k);f_f,f_m)+lamada*eta*||Z||_2,1
% s.t. D(k)=Z;
% where A is a feature matrix and b is a response vector. The scalar m is
% the number of examples in the matrix A.
t_start = tic;
%% Global constants and defaults
QUIET = 0;
M_iter = 1000;
M_lbfgs=
ABSTOL = 1e-4;
RELTOL = 1e-2;
%% Data preprocessing
[m, n] = size(A);
%% ADMM solver
x = zeros(n+1,1);
z = zeros(n+1,1);
u = zeros(n+1,1);
if ~QUIET
fprintf('%3s\t%10s\t%10s\t%10s\t%10s\t%10s\n', 'iter', ...
'r norm', 'eps pri', 's norm', 'eps dual', 'objective');
end
for k = 1:M_iter
% x-update
x = update_x(A, b, u, z, rho);
% z-update with relaxation
zold = z;
x_hat = alpha*x + (1-alpha)*zold;
z = x_hat + u;
z(2:end) = shrinkage(z(2:end), (m*mu)/rho);
u = u + (x_hat - z);
% diagnostics, reporting, termination checks
history.objval(k) = objective(A, b, mu, x, z);
history.r_norm(k) = norm(x - z);
history.s_norm(k) = norm(rho*(z - zold));
history.eps_pri(k) = sqrt(n)*ABSTOL + RELTOL*max(norm(x), norm(z));
history.eps_dual(k)= sqrt(n)*ABSTOL + RELTOL*norm(rho*u);
if ~QUIET
fprintf('%3d\t%10.4f\t%10.4f\t%10.4f\t%10.4f\t%10.2f\n', k, ...
history.r_norm(k), history.eps_pri(k), ...
history.s_norm(k), history.eps_dual(k), history.objval(k));
end
if history.r_norm(k) < history.eps_pri(k) && ...
history.s_norm(k) < history.eps_dual(k)
break;
end
end
if ~QUIET
toc(t_start);
end
end
function obj = objective(A, b, mu, x, z)
m = size(A,1);
obj = sum(log(1 + exp(-A*x(2:end) - b*x(1)))) + m*mu*norm(z,1);
end
function x = update_x(A, b, u, z, rho, x0)
% solve the x update
% minimize [ -logistic(x_i) + (rho/2)||x_i - z^k + u^k||^2 ]
% via Newton's method; for a single subsystem only.
alpha = 0.1;
BETA = 0.5;
TOLERANCE = 1e-5;
MAX_ITER = 50;
[m n] = size(A);
I = eye(n+1);
if exist('x0', 'var')
x = x0;
else
x = zeros(n+1,1);
end
C = [-b -A];
f = @(w) (sum(log(1 + exp(C*w))) + (rho/2)*norm(w - z + u).^2);
for iter = 1:MAX_ITER
fx = f(x);
g = C'*(exp(C*x)./(1 + exp(C*x))) + rho*(x - z + u);
H = C' * diag(exp(C*x)./(1 + exp(C*x)).^2) * C + rho*I;
dx = -H\g; % Newton step
dfx = g'*dx; % Newton decrement
if abs(dfx) < TOLERANCE
break;
end
% backtracking
t = 1;
while f(x + t*dx) > fx + alpha*t*dfx
t = BETA*t;
end
x = x + t*dx;
end
end
function z = shrinkage(a, kappa)
z = max(0, a-kappa) - max(0, -a-kappa);
end