Skip to content

Commit 40028c5

Browse files
committed
Small optimizations.
1 parent 551a016 commit 40028c5

File tree

7 files changed

+62
-56
lines changed

7 files changed

+62
-56
lines changed

src/frameworks/IAIPAL.m

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -191,29 +191,13 @@
191191
params_acg.t_start = t_start;
192192

193193
% Set the correct stepsizes.
194-
if strcmp(params.acg_steptype, 'constant')
195-
params_acg.L_est = M_s;
196-
elseif strcmp(params.acg_steptype, 'variable')
197-
if (i_first_acg_run)
198-
o_z0 = copy(oracle);
199-
o_z0.eval(z0);
200-
iter = iter + 1;
201-
o_z1 = copy(oracle);
202-
o_z1.eval(z0 - o_z0.grad_f_s() / M);
203-
iter = iter + 1;
204-
z1 = o_z1.prox_f_n(1 / M);
205-
o_z1.eval(z1);
206-
iter = iter + 1;
207-
if (norm_fn(z0 - z1) <= 1e-6)
208-
params_acg.L_est = lambda * M + 1;
209-
else
210-
M_est = norm_fn(o_z0.grad_f_s() - o_z1.grad_f_s()) / norm_fn(z0 - z1);
211-
params_acg.L_est = lambda * M_est + 1;
212-
end
213-
else
214-
% Use the previous estimate.
215-
params_acg.L_est = model_acg.L_est;
216-
end
194+
if ( strcmp(params.acg_steptype, 'constant'))
195+
params_acg.L_est = M_s;
196+
elseif (i_first_acg_run && strcmp(params.acg_steptype, 'variable'))
197+
params_acg.L_est = lambda * M + 1;
198+
elseif (~i_first_acg_run && strcmp(params.acg_steptype, 'variable'))
199+
% Use the previous estimate.
200+
params_acg.L_est = model_acg.L_est;
217201
else
218202
error('Unknown ACG steptype!');
219203
end
@@ -270,7 +254,7 @@
270254
history.norm_p_hat = [history.norm_p_hat; norm_fn(p_hat)];
271255
history.norm_v = [history.norm_v; norm_fn(w_hat)];
272256
end
273-
257+
274258
% Check for termination.
275259
if (isempty(params.termination_fn) || params.check_all_terminations)
276260
if (norm_fn(w_hat) <= opt_tol && norm_fn(q_hat) <= feas_tol)

src/frameworks/penalty.m

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
% A pair of structs containing model and history related outputs of the solved problem associated with the oracle and input
2626
% parameters.
2727

28-
% Global constants.
29-
MIN_PENALTY_CONST = 1;
30-
3128
% Timer start.
3229
t_start = tic;
3330

@@ -89,7 +86,7 @@
8986
stage = 1;
9087
solver_params = params;
9188
i_reset_prox_center = params.i_reset_prox_center;
92-
c = max([MIN_PENALTY_CONST, params.M / params.K_constr ^ 2]);
89+
c = params.c0;
9390

9491
%% MAIN ALGORITHM
9592
while true
@@ -146,9 +143,16 @@
146143
end
147144

148145
% Check for termination.
149-
feas = feas_fn(solver_model.x);
150-
if (feas <= feas_tol)
151-
break;
146+
feas = feas_fn(solver_model.x);
147+
if (~isempty(params.termination_fn) || params.check_all_terminations)
148+
if (feas <= feas_tol)
149+
break;
150+
end
151+
end
152+
if (~isempty(params.termination_fn) || params.check_all_terminations)
153+
if wrap_termination(params, solver_model.x, c)
154+
break;
155+
end
152156
end
153157

154158
% Apply warm-start onto the initial point fed into the next iteration.
@@ -164,12 +168,11 @@
164168

165169
% Prepare to output
166170
model = solver_model;
167-
if (isempty(params.termination_fn) || params.check_all_terminations)
171+
if (isempty(params.termination_fn))
168172
[~, feas_vec] = feas_fn(solver_model.x);
169173
model.w = feas_vec;
170-
end
171-
if (~isempty(params.termination_fn) || params.check_all_terminations)
172-
[~, model.v, model.w] = wrap_termination(params, solver_model.x, c);
174+
else
175+
[~, model.v, model.w] = wrap_termination(params, solver_model.x, c);
173176
end
174177
history.iter = iter;
175178
history.stage = stage;
@@ -187,6 +190,10 @@
187190

188191
% Fills in parameters that were not set as input.
189192
function params = set_default_params(params)
193+
194+
% Global constants.
195+
MIN_PENALTY_CONST = 1;
196+
190197
% Overwrite if necessary.
191198
if (~isfield(params, 'i_logging'))
192199
params.i_logging = false;
@@ -206,4 +213,7 @@
206213
if (~isfield(params, 'check_all_terminations'))
207214
params.check_all_terminations = false;
208215
end
216+
if (~isfield(params, 'c0'))
217+
params.c0 = max([MIN_PENALTY_CONST, params.M / params.K_constr ^ 2]);
218+
end
209219
end

tests/papers/nl_iapial/extra/nl_iapial_qsdp_debug.m

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
n = 100;
66
r = 1;
7-
m = 1e4;
8-
M = 1e6;
9-
global_tol = 1e-2;
7+
m = 1e0;
8+
M = 1e4;
9+
global_tol = 1e-4;
1010

1111
% Run an instance via the command line.
1212
print_tbls(n, r, m, M, global_tol);
@@ -71,20 +71,24 @@ function run_experiment(N, r, M, m, dimM, dimN, density, seed, global_tol)
7171
base_hparam.check_all_terminations = true;
7272

7373
% Create the IAPIAL hparams.
74-
qp_hparam = base_hparam;
75-
qp_hparam.acg_steptype = 'constant';
76-
qp_hparam.aipp_type = 'aipp';
74+
qpa_hparam = base_hparam;
75+
qpa_hparam.acg_steptype = 'variable';
76+
qpa_hparam.aipp_type = 'aipp';
7777
ipl_hparam = base_hparam;
7878
ipl_hparam.acg_steptype = 'constant';
79+
ipl_hparam.sigma_min = sqrt(0.3);
80+
ipla_hparam = base_hparam;
81+
ipla_hparam.acg_steptype = 'variable';
82+
ipla_hparam.sigma_min = sqrt(0.3);
7983

8084
% Run a benchmark test and print the summary.
81-
hparam_arr = {qp_hparam, ipl_hparam};
82-
name_arr = {'QP','IPL'};
85+
hparam_arr = {qpa_hparam, ipla_hparam};
86+
name_arr = {'QP_A', 'IPL_A'};
8387
framework_arr = {@penalty, @IAIPAL};
8488
solver_arr = {@AIPP, @ECG};
8589

8690
% Run the test.
87-
[~, summary_mdls] = run_CCM_benchmark(ncvx_qsdp, framework_arr, solver_arr, hparam_arr, name_arr);
91+
[summary_tbls, summary_mdls] = run_CCM_benchmark(ncvx_qsdp, framework_arr, solver_arr, hparam_arr, name_arr);
8892
for s=name_arr
8993
disp(['Algorithm = ', s{1}]);
9094
disp(table(dimN, m, M, r));
@@ -93,5 +97,6 @@ function run_experiment(N, r, M, m, dimM, dimN, density, seed, global_tol)
9397
tbl.Properties.VariableNames = {'inner_iter', 'L_est', 'norm_v'};
9498
disp(tbl);
9599
end
100+
disp(summary_tbls.all);
96101

97102
end

tests/papers/nl_iapial/nl_iapial_qcqp.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function print_tbls(dimN)
101101
% Set the tolerances
102102
ncvx_qc_qp.opt_tol = global_tol;
103103
ncvx_qc_qp.feas_tol = global_tol;
104-
ncvx_qc_qp.time_limit = 6000;
104+
ncvx_qc_qp.time_limit = 3000;
105105
ncvx_qc_qp.iter_limit = 1000000;
106106

107107
% Add linear constraints
@@ -122,11 +122,10 @@ function print_tbls(dimN)
122122
% Create the IAPIAL hparams.
123123
ipl_hparam = base_hparam;
124124
ipl_hparam.acg_steptype = 'constant';
125-
ipl_hparam.sigma_min = 1/sqrt(2);
125+
ipl_hparam.sigma_min = sqrt(0.3);
126126
ipla_hparam = base_hparam;
127127
ipla_hparam.acg_steptype = 'variable';
128-
ipla_hparam.init_mult_L = 0.5;
129-
ipla_hparam.sigma_min = 1/sqrt(2);
128+
ipla_hparam.sigma_min = sqrt(0.3);
130129

131130
% Run a benchmark test and print the summary.
132131
hparam_arr = {ipl_hparam, ipla_hparam};

tests/papers/nl_iapial/nl_iapial_qcqsdp.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function print_tbls(dimN)
6464
disp(o_tbl);
6565

6666
end
67-
function o_tbl = run_experiment(N, r, M, m, dimM, dimN, density, seed, global_tol)
67+
function o_tbl = run_experiment(N, r, M, m, dimM, dimN, density, seed, global_tol)
6868

6969
[oracle, hparams] = test_fn_quad_cone_constr_02r(N, r, M, m, seed, dimM, dimN, density);
7070

@@ -118,8 +118,10 @@ function print_tbls(dimN)
118118
% Create the IAPIAL hparams.
119119
ipl_hparam = base_hparam;
120120
ipl_hparam.acg_steptype = 'constant';
121+
ipl_hparam.sigma_min = sqrt(0.3);
121122
ipla_hparam = base_hparam;
122123
ipla_hparam.acg_steptype = 'variable';
124+
ipla_hparam.sigma_min = sqrt(0.3);
123125

124126
% Create the complicated iALM hparams.
125127
ialm_hparam = base_hparam;
@@ -129,7 +131,6 @@ function print_tbls(dimN)
129131
ialm_hparam.L0 = max([hparams.m, hparams.M]);
130132
ialm_hparam.rho_vec = hparams.m_constr_vec;
131133
ialm_hparam.L_vec = hparams.L_constr_vec;
132-
% Note that we are using the fact that |X|_F <= 1 over the eigenbox.
133134
ialm_hparam.B_vec = hparams.K_constr_vec;
134135

135136
% Run a benchmark test and print the summary.

tests/papers/nl_iapial/nl_iapial_qp.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ function print_tbls(dimN)
152152
% Set the tolerances
153153
ncvx_qsdp.opt_tol = global_tol;
154154
ncvx_qsdp.feas_tol = global_tol;
155-
ncvx_qsdp.time_limit = 6000;
155+
ncvx_qsdp.time_limit = 3000;
156156

157157
% Add linear constraints
158158
ncvx_qsdp.constr_fn = hparams.constr_fn;
@@ -171,6 +171,9 @@ function print_tbls(dimN)
171171
% Create the IAPIAL hparams.
172172
ipla_hparam = base_hparam;
173173
ipla_hparam.acg_steptype = 'variable';
174+
ipla_hparam.sigma_min = sqrt(0.3);
175+
176+
% Create the QP-AIPP hparams.
174177
qpa_hparam = base_hparam;
175178
qpa_hparam.acg_steptype = 'variable';
176179
qpa_hparam.aipp_type = 'aipp';

tests/papers/nl_iapial/nl_iapial_qsdp.m

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function print_tbls(dimN)
1515
dimM = 25;
1616
N = 1000;
1717
density = 0.05;
18-
global_tol = 1e-3;
18+
global_tol = 5 * 1e-4;
1919
m_vec = [1e2, 1e3, 1e4];
2020
M_vec = [1e4, 1e5, 1e6];
2121
r_vec = [5, 10, 20];
@@ -83,7 +83,8 @@ function print_tbls(dimN)
8383
rho = global_tol * (1 + hparams.norm_fn(o_at_x0.grad_f_s()));
8484
eta = global_tol * (1 + hparams.norm_fn(g0 - hparams.set_projector(g0)));
8585
alt_grad_constr_fn = @(x, p) tsr_mult(hparams.grad_constr_fn(x), p, 'dual');
86-
term_wrap = @(x,p) termination_check(x, p, o_at_x0, hparams.constr_fn, alt_grad_constr_fn, @proj_dh, @proj_NKt, hparams.norm_fn, rho, eta);
86+
term_wrap = @(x,p) ...
87+
termination_check(x, p, o_at_x0, hparams.constr_fn, alt_grad_constr_fn, @proj_dh, @proj_NKt, hparams.norm_fn, rho, eta);
8788

8889
% Create the Model object and specify the solver.
8990
ncvx_qsdp = ConstrCompModel(oracle);
@@ -94,10 +95,10 @@ function print_tbls(dimN)
9495
ncvx_qsdp.m = hparams.m;
9596
ncvx_qsdp.K_constr = hparams.K_constr;
9697

97-
% Set the tolerances
98+
% Set the tolerances.
9899
ncvx_qsdp.opt_tol = global_tol;
99100
ncvx_qsdp.feas_tol = global_tol;
100-
ncvx_qsdp.time_limit = 12000;
101+
ncvx_qsdp.time_limit = 6000;
101102

102103
% Add linear constraints
103104
ncvx_qsdp.constr_fn = hparams.constr_fn;
@@ -116,8 +117,12 @@ function print_tbls(dimN)
116117
% Create the IAPIAL hparams.
117118
ipl_hparam = base_hparam;
118119
ipl_hparam.acg_steptype = 'constant';
120+
ipl_hparam.sigma_min = sqrt(0.3);
119121
ipla_hparam = base_hparam;
120122
ipla_hparam.acg_steptype = 'variable';
123+
ipla_hparam.sigma_min = sqrt(0.3);
124+
125+
% Create the QP-AIPP hparams.
121126
qp_hparam = base_hparam;
122127
qp_hparam.acg_steptype = 'constant';
123128
qp_hparam.aipp_type = 'aipp';
@@ -133,7 +138,6 @@ function print_tbls(dimN)
133138
ialm_hparam.L0 = max([hparams.m, hparams.M]);
134139
ialm_hparam.rho_vec = hparams.m_constr_vec;
135140
ialm_hparam.L_vec = hparams.L_constr_vec;
136-
% Note that we are using the fact that |X|_F <= 1 over the eigenbox.
137141
ialm_hparam.B_vec = hparams.K_constr_vec;
138142

139143
% Run a benchmark test and print the summary.

0 commit comments

Comments
 (0)