-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubgradientDescent.m
26 lines (25 loc) · 967 Bytes
/
subgradientDescent.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
function [x, history] = subgradientDescent(parameters, nIter, gamma, ck, u, dstar_init)
%SUBGRADIENTDESCENT
objValues = zeros(nIter, 1);
augObjValues = zeros(nIter, 1);
x = dstar_init;
for i = 1:nIter
direction = subgradAL(parameters, ck, u, x);
%usersOld = sum(x);
x = x - stepSize(gamma, i) * direction;
%usersNew = sum(x);
%fprintf("adding %0.2f incentivized users.\n", usersNew - usersOld);
x = max(0, x);
objValues(i) = objective(parameters, x);
augObjValues(i) = augmentedLagrangian(parameters, ck, u, x);
%fprintf("Inner iteration %d of %d. objective value = %02.f. augmented objective value = %04f\n", ...
% i, nIter, objValues(i), augObjValues(i));
end
history = struct();
history.objectiveValues = objValues;
history.augmentedLagrangianValues = augObjValues;
end
function [t] = stepSize(gamma, k)
t = 1/(k*gamma);
%t = 10^-3;
end