Skip to content

Commit c4a0824

Browse files
committed
updated constraints names & explicit verbose
1 parent 69434c9 commit c4a0824

17 files changed

+89
-46
lines changed

Examples/01_Methods for unconstrained convex minimization/C_SubgradientMethod.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@
4040
for i=1:N
4141
[g,f] = F.oracle(x);
4242
f_saved{i} = f;
43-
P.PerformanceMetric(f-fs);
43+
P.PerformanceMetric(f-fs,'min');
4444
x = x - h(i) * g;
4545
end
4646

4747
[g,f] = F.oracle(x);
4848
f_saved{N+1} = f;
49-
P.PerformanceMetric(f-fs);
49+
P.PerformanceMetric(f-fs,'min');
5050

5151
% (5) Solve the PEP
52-
P.solve()
52+
P.solve(3)
5353

5454
% (6) Evaluate the output
5555
for i=1:N+1

Examples/01_Methods for unconstrained convex minimization/D_SubgradientMethod_ExactLineSearch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
P.PerformanceMetric(f{N+1}-fs);
4646

4747
% (5) Solve the PEP
48-
P.solve()
48+
out=P.solve()
4949

5050
% (6) Evaluate the output
5151
double(f{N+1}-fs)

Examples/01_Methods for unconstrained convex minimization/F_GradientExactLineSearch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
P.PerformanceMetric(f-fs); % Worst-case evaluated as F(x)-F(xs)
5151

5252
% (5) Solve the PEP
53-
P.solve()
53+
out=P.solve()
5454

5555
% (6) Evaluate the output
5656
double(f-fs) % worst-case objective function accuracy

Examples/01_Methods for unconstrained convex minimization/I_ConjugateGradientMethod.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
P.PerformanceMetric(f{N+1}-fs); % Worst-case evaluated as F(x)-F(xs)
4747

4848
% (5) Solve the PEP
49-
P.solve()
49+
out=P.solve()
5050

5151
% (6) Evaluate the output
5252
double(f{N+1}-fs) % worst-case objective function accuracy

Examples/01_Methods for unconstrained convex minimization/M_StronglyConvexFastGradientMethod.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
P.PerformanceMetric(fN-fs); % Worst-case evaluated as F(x)-F(xs)
4545

4646
% (5) Solve the PEP
47-
P.solve()
47+
out=P.solve()
4848

4949
% (6) Evaluate the output
5050
double(fN-fs) % worst-case objective function accuracy

Examples/01_Methods for unconstrained convex minimization/P_InexactFastGradientMethod.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
P.PerformanceMetric(f - fs); % Worst-case evaluated as F(x)-F(xs)
4747

4848
% (5) Solve the PEP
49-
P.solve()
49+
out=P.solve()
5050

5151
% (6) Evaluate the output
5252
double(f - fs) % worst-case objective function accuracy

Examples/01_Methods for unconstrained convex minimization/Q_InexactGradientExactLineSearch.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
P.PerformanceMetric( fN-fs ); % Worst-case evaluated as ||g||^2
5454

5555
% (5) Solve the PEP
56-
P.solve()
56+
out=P.solve()
5757

5858
% (6) Evaluate the output
5959
double(fN-fs) % worst-case objective function accuracy

PESTO_files/CompositeFunction.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
obj.func1.AddComponent(x,g1,f1,spec);
2222
obj.func2.AddComponent(x,g2,f2,spec);
2323
end
24-
function obj=AddConstraint(obj,expr)
25-
assert(isa(expr,'Constraint'),'Invalid initial condition');
26-
obj.func1.AddConstraint(expr);
24+
function obj=AddConstraint(obj,expr,name)
25+
if nargin < 3
26+
obj.func1.AddConstraint(expr);
27+
elseif nargin == 3
28+
obj.func1.AddConstraint(expr,name);
29+
end
2730
end
2831
function cons=GetInterp(obj)
2932
cons=[];
@@ -66,7 +69,7 @@
6669
end
6770
function [f1, f2] = getFunctions(obj)
6871
f1 = obj.func1;
69-
f2 = obj.func2;
72+
f2 = obj.func2;
7073
end
7174
function disp(obj)
7275
fprintf('Composite function\n');

PESTO_files/Scaled_Function.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
end
1919
obj.func.AddComponent(x,g1,f1,spec);
2020
end
21-
function obj=AddConstraint(obj,expr)
22-
assert(isa(expr,'Constraint'),'Invalid initial condition');
23-
obj.func.AddConstraint(expr);
21+
function obj=AddConstraint(obj,expr,name)
22+
if nargin < 3
23+
obj.func.AddConstraint(expr);
24+
elseif nargin == 3
25+
obj.func.AddConstraint(expr,name);
26+
end
2427
end
2528
function cons=GetInterp(obj)
2629
cons=[];

PESTO_files/functionHandler.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33

44
expr_list_others;
55
list_size_others;
6+
names_list_others;
67
end
78
methods
89
function obj=functionHandler()
910
obj.list_size_others=0;
1011
obj.expr_list_others=cell(0,1);
12+
obj.names_list_others=cell(0,1);
1113
functionHandler.CountActive(1);
1214
end
1315
function delete(obj)
1416
functionHandler.CountActive(-1);
1517
end
16-
function obj=AddConstraint(obj,expr)
17-
assert(isa(expr,'Constraint'),'Invalid initial condition');
18-
obj.list_size_others=obj.list_size_others+1;
19-
obj.expr_list_others{obj.list_size_others,1}=expr;
18+
function obj=AddConstraint(obj,expr,name)
19+
assert(isa(expr,'Constraint'),'Invalid constraint');
20+
if nargin < 3
21+
obj.list_size_others=obj.list_size_others+1;
22+
obj.expr_list_others{obj.list_size_others,1}=expr;
23+
obj.names_list_others{obj.list_size_others,1}='Unnamed constraint';
24+
elseif nargin == 3
25+
assert(ischar(name),'Invalid name in constraint (must be array of characters; use single quotes)');
26+
obj.list_size_others=obj.list_size_others+1;
27+
obj.expr_list_others{obj.list_size_others,1}=expr;
28+
obj.names_list_others{obj.list_size_others,1}=name;
29+
end
2030
end
2131
function g=evaluate(obj,expr,tag) % SAME AS GRADIENT
2232
if nargin>=3
@@ -54,12 +64,13 @@ function delete(obj)
5464
end
5565
[~,f]=obj.oracle(expr,spec);
5666
end
57-
function cons=collect(obj)
67+
function [cons,names]=collect(obj)
5868
cons=[];
5969
for i=1:obj.list_size_others
6070
lexpr=obj.expr_list_others{i,1}.Eval();
6171
cons=cons+lexpr;
6272
end
73+
names=obj.names_list_others;
6374
end
6475
function obj3=plus(obj1,obj2)
6576
assert(isa(obj1,'functionHandler') && isa(obj2,'functionHandler'));

PESTO_files/pep.m

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,31 @@ function disp(obj)
9090
obj.expr_list_others{obj.list_size_others,1}=expr;
9191
end
9292
function obj=AddLMIConstraint(obj,expr)
93-
% AddLMIConstraint allows to add an arbitrary Linear Matrix Inequality (LMI) constraint to the PEP problem.
94-
% Input: expr is a cell array of PEP expressions that represents the matrix
95-
% that should be positive semi-definite.
93+
% AddLMIConstraint allows to add an arbitrary Linear Matrix Inequality (LMI) constraint to the PEP problem.
94+
% Input: expr is a cell array of PEP expressions that represents the matrix
95+
% that should be positive semi-definite.
9696
assert(iscell(expr),'LMI constraint should be given as a cell of expressions');
9797
obj.list_size_tab_LMIs=obj.list_size_tab_LMIs+1;
9898
obj.expr_list_tab_LMIs{obj.list_size_tab_LMIs,1} = expr;
9999
end
100-
function obj=PerformanceMetric(obj,expr)
100+
function obj=PerformanceMetric(obj,expr,status)
101101
assert(isa(expr,'Evaluable'),'Perfomance measures should be scalar values');
102102
assert(strcmp(expr.getType(),'Function value'),'Perfomance measures should be scalar values');
103-
obj.list_size_perf=obj.list_size_perf+1;
104-
obj.expr_list_perf{obj.list_size_perf,1}=expr;
103+
if nargin == 2 % default is 'min'
104+
obj.list_size_perf=obj.list_size_perf+1;
105+
obj.expr_list_perf{obj.list_size_perf,1}=expr;
106+
elseif nargin == 3
107+
assert(strcmp(status,'min')||strcmp(status,'replace'),'Error in PerformanceMetric(): third input must be ''min'' or ''replace''');
108+
switch status
109+
case 'min'
110+
obj.list_size_perf=obj.list_size_perf+1;
111+
obj.expr_list_perf{obj.list_size_perf,1}=expr;
112+
case 'replace'
113+
obj.list_size_perf=1;
114+
obj.expr_list_perf=cell(0,1);
115+
obj.expr_list_perf{obj.list_size_perf,1}=expr;
116+
end
117+
end
105118
end
106119
function obj=AddPerformanceConstraint(obj,expr)
107120
fprintf('AddPerformanceConstraint is deprecated, consider using PerformanceMetric instead\n');
@@ -229,7 +242,7 @@ function AddInitialCondition(obj,expr)
229242
names{end+1} = sprintf('Perf%d',i);
230243
end
231244
perf_size=length(cons);
232-
if verbose_pet>1, fprintf(' (done, %d constraint(s) added) \n',perf_size), end;
245+
if verbose_pet>1, fprintf(' (done, performance measure is minimum of %d element(s)) \n',perf_size), end;
233246
end
234247
count=length(cons);
235248
if obj.list_size_init>0
@@ -269,9 +282,12 @@ function AddInitialCondition(obj,expr)
269282
names{end+1} = sprintf('Other%d',i);
270283
end
271284
end
272-
285+
273286
for i=1:obj.list_size_func
274-
cons=cons+obj.list_func{i,1}.collect();
287+
[cons_t,names_t] = obj.list_func{i,1}.collect();
288+
cons = cons+cons_t;
289+
names = [names names_t'];
290+
clear cons_t names_t;
275291
end
276292
others_size=length(cons)-count;
277293
if verbose_pet>1, fprintf(' (done, %d constraint(s) added) \n',others_size), end;
@@ -283,7 +299,7 @@ function AddInitialCondition(obj,expr)
283299
verbose_solver=0;
284300
solver_opt = sdpsettings('verbose',verbose_solver);
285301
if nargin < 2
286-
verbose_pet = 1;
302+
verbose_pet = 2;
287303
end
288304
end
289305

@@ -294,7 +310,7 @@ function AddInitialCondition(obj,expr)
294310
F=sdpvar(dim2,1);
295311
tau=sdpvar(1,1);
296312
obj_func=tau;
297-
cons=(G>=0);
313+
cons=(G>=0);
298314
names = {'Gram Matrix PSD'};
299315
Evaluable.SetGetFunc(F);Evaluable.SetGetGram(G);
300316
msg = sprintf(' PESTO: Setting up the problem: interpolation constraints (component %d out of %d done)\n', 0,obj.list_size_func);
@@ -336,12 +352,12 @@ function AddInitialCondition(obj,expr)
336352
k1 = k1 + 1;
337353
else % LMI
338354
out.dualvalues_LMIs{k2} = dual_i;
339-
out.dualnames_LMIs{k2} = name_i;
355+
out.dualnames_LMIs{k2} = name_i;
340356
k2 = k2 + 1;
341357
end
342-
end
358+
end
343359

344-
if verbose_pet, fprintf(' PESTO: Solver output: %7.5e, solution status: %s\n',out.WCperformance,out.solverDetails.info), end;
360+
if verbose_pet, fprintf(' PESTO: Solver output: %7.5e, solution status: %s\n',out.WCperformance,out.solverDetails.info), end;
345361

346362
if verbose_pet>1, fprintf(' PESTO: Post-processing\n'), end;
347363

Primitive_oracles/inexactsubgradient.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242
end
4343

4444
if abs==1 % absolute accuracy
45-
f.AddConstraint((g-d)^2-eps^2<=0);
45+
f.AddConstraint((g-d)^2-eps^2<=0,'Approximate gradient (absolute accuracy)');
4646
else
47-
f.AddConstraint((g-d)^2-eps^2*g^2<=0);
47+
f.AddConstraint((g-d)^2-eps^2*g^2<=0,'Approximate gradient (relative accuracy)');
4848
end
4949

5050

Primitive_steps/exactlinesearch_step.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
[gx,fx]=f.oracle(x);
2828
end
2929
nb_orth=max(size(dirs));
30-
f.AddConstraint((x-x0)*gx==0);
30+
f.AddConstraint((x-x0)*gx==0,'Orthogonality condition (exact linesearch)');
3131
if isa(dirs,'cell')
3232
for i=1:nb_orth
33-
f.AddConstraint(dirs{i}*gx==0);
33+
f.AddConstraint(dirs{i}*gx==0,'Orthogonality condition (exact linesearch)');
3434
end
3535
else
36-
f.AddConstraint(dirs*gx==0);
36+
f.AddConstraint(dirs*gx==0,'Orthogonality condition (exact linesearch)');
3737
end
3838
end
3939

Primitive_steps/inexact_proximal_step.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
eps_sub = fx - fw - v*(x-w);
7777
gap = 1/2*e^2 + gamma*eps_sub;
7878

79-
func.AddConstraint(gap<=epsVar);
79+
func.AddConstraint(gap<=epsVar,'Approximate proximal step');
8080
case 'PD_gapII'
8181
% Approximate proximal operator outputs x such that
8282
% ||e|| <= epsVar
@@ -89,7 +89,7 @@
8989
func.AddComponent(x,gx,fx);
9090
epsVar = Point('Function value');
9191

92-
func.AddConstraint(e^2<= epsVar);
92+
func.AddConstraint(e^2<= epsVar,'Approximate proximal step');
9393
case 'PD_gapIII'
9494
% Approximate proximal operator outputs x such that
9595
% gamma * (fx - fw - v*(x-w)) <= epsVar
@@ -107,7 +107,7 @@
107107

108108
eps_sub = fx - fw - v*(x-w);
109109

110-
func.AddConstraint(gamma*eps_sub<=epsVar);
110+
func.AddConstraint(gamma*eps_sub<=epsVar,'Approximate proximal step');
111111

112112
case 'Orip-style'
113113
% Approximate proximal operator outputs x such that
@@ -130,7 +130,7 @@
130130
eps_sub = fx - fw - v*(x-w);
131131
gap = e*v + eps_sub/gamma;
132132

133-
func.AddConstraint(gap<=epsVar);
133+
func.AddConstraint(gap<=epsVar,'Approximate proximal step');
134134
otherwise
135135
fprintf('No criterion chosen for inexact prox\n');
136136
end

UserGuide.pdf

1.74 KB
Binary file not shown.

UserGuide_sources/UserGuide.pdf

1.74 KB
Binary file not shown.

UserGuide_sources/UserGuide.tex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113

114114
\section*{Recent updates}
115115
\begin{itemize}
116+
\item[05/2021] {\bf{}[Update]} Default verbose setting is medium (``2''): PESTO in verbose mode, but solver not.
117+
\item[05/2021] {\bf{}[Update]} Update in the \verb|PerformanceMetric| command, which allows replacing previous performance measure (instead of taking the $\min$, which it still does by default, see example in Section~\ref{sec:basicuse}).
118+
\item[05/2021] {\bf{}[Update]} We can add names to additional (custom) constraints, which now appear in the corresponding list of dual variables (along with their names).
116119
\item[05/2021] {\bf{}[New]} Possibility of using additional linear matrix inequalities (LMIs) using the new command \verb?AddLMIConstraint?.
117120
\item[05/2021] {\bf{}[New]} Decentralized Gradient Descent (DGD) added to the examples.
118121
\item[05/2020] {\bf{}[New]} New primitives and examples: inexact proximal operations.
@@ -418,9 +421,16 @@
418421
In PESTO, the performance measure is assumed to be of the form $\min_k \{m_k(G,\{f_i\}_i)\}$, where each $m_k(.)$ is a performance measure (e.g., in the previous subgradient example, we used $\min_{0\leq k \leq N} f_k-f_\star$). The command \verb?PerformanceMetric? allows to create new $m_k(.)$'s.\\[-1cm]
419422
\begin{lstlisting}
420423
P.PerformanceMetric((x-xs)^2); % Add a performance measure ||x-xs||^2
421-
P.PerformanceMetric(F.value(x)-Fs); % Add a performance measure F0-Fs
424+
P.PerformanceMetric(F.value(x)-Fs); % Add a performance measure F(x)-Fs
425+
\end{lstlisting}
426+
Note that as in the example~\eqref{Intro:PEP3}, the performance metrics are encoded as new constraints involving the objective function $\tau$. The default behavior of \verb?PerformanceMetric? can also be changed to replace the previous objectives, as follows.
427+
\begin{lstlisting}
428+
P.PerformanceMetric((x-xs)^2); % Add a performance measure ||x-xs||^2
429+
P.PerformanceMetric((F.gradient(x))^2,'min'); % Add a performance measure ||F'(x)||^2, same behavior as P.PerformanceMetric((F.gradient(x))^2)
430+
% At this point, the performance measure is min{ ||x-xs||^2, ||F'(x)||^2}.
431+
% Let's change that to F(x)-Fs.
432+
P.PerformanceMetric(F.value(x)-Fs,'replace'); % Replace all previously defined performance measures by F(x)-Fs
422433
\end{lstlisting}
423-
Note that as in the example~\eqref{Intro:PEP3}, the performance metrics are encoded as new constraints involving the objective function $\tau$.
424434
\end{enumerate}
425435
\newpage
426436
\subsection{Functional classes} \label{sec:functions}

0 commit comments

Comments
 (0)