Robust approximate fitting
Section 6.4.2 Boyd & Vandenberghe "Convex Optimization" Original by Lieven Vandenberghe Adapted for Convex by Joelle Skaf - 10/03/05
Adapted for Convex.jl by Karanveer Mohan and David Zeng - 26/05/14 Original CVX code and plots here: http://web.cvxr.com/cvx/examples/cvxbook/Ch06_approx_fitting/html/fig6_15.html
Consider the least-squares problem: minimize $\|(A + tB)x - b\|_2$ where $t$ is an uncertain parameter in [-1,1] Three approximate solutions are found:
- nominal optimal (that is, letting t=0)
- stochastic robust approximation: minimize $\mathbb{E}\|(A+tB)x - b\|_2$ assuming $u$ is uniformly distributed on [-1,1]. (reduces to minimizing $\mathbb{E} \|(A+tB)x-b\|^2 = \|A*x-b\|^2 + x^TPx$ where $P = \mathbb{E}(t^2) B^TB = (1/3) B^TB$ )
- worst-case robust approximation: minimize $\mathrm{sup}_{-1\leq u\leq 1} \|(A+tB)x - b\|_2$ (reduces to minimizing $\max\{\|(A-B)x - b\|_2, \|(A+B)x - b\|_2\}$ ).
using Convex, LinearAlgebra, SCSInput Data
m = 20;
n = 10;
A = randn(m, n);
(U, S, V) = svd(A);
S = diagm(exp10.(range(-1, stop = 1, length = n)));
A = U[:, 1:n] * S * V';
B = randn(m, n);
B = B / norm(B);
b = randn(m, 1);
x = Variable(n)Variable
size: (10, 1)
sign: real
vexity: affine
id: 111…567Case 1: nominal optimal solution
p = minimize(norm(A * x - b, 2))
solve!(p, SCS.Optimizer; silent = true)Problem statistics
problem is DCP : true
number of variables : 1 (10 scalar elements)
number of constraints : 0 (0 scalar elements)
number of coefficients : 220
number of atoms : 3
Solution summary
termination status : OPTIMAL
primal status : FEASIBLE_POINT
dual status : FEASIBLE_POINT
objective value : 2.7707
Expression graph
minimize
└─ norm2 (convex; positive)
└─ + (affine; real)
├─ * (affine; real)
│ ├─ …
│ └─ …
└─ 20×1 Matrix{Float64}
x_nom = evaluate(x)10-element Vector{Float64}:
-6.147557441717799
-3.9251780682835444
1.8241081203845761
0.13368478091692487
1.9598446027251681
3.1776981438786915
0.14195277666517614
2.7995641000406226
3.510522146308264
-3.6294504775787058Case 2: stochastic robust approximation
P = 1 / 3 * B' * B;
p = minimize(square(pos(norm(A * x - b))) + quadform(x, Symmetric(P)))
solve!(p, SCS.Optimizer; silent = true)Problem statistics
problem is DCP : true
number of variables : 1 (10 scalar elements)
number of constraints : 0 (0 scalar elements)
number of coefficients : 324
number of atoms : 10
Solution summary
termination status : OPTIMAL
primal status : FEASIBLE_POINT
dual status : FEASIBLE_POINT
objective value : 8.9964
Expression graph
minimize
└─ + (convex; positive)
├─ qol_elem (convex; positive)
│ ├─ max (convex; positive)
│ │ ├─ …
│ │ └─ …
│ └─ [1.0;;]
└─ * (convex; positive)
├─ [1;;]
└─ qol_elem (convex; positive)
├─ …
└─ …
x_stoch = evaluate(x)10-element Vector{Float64}:
-2.1390351990171497
-1.58190181469166
1.260624644668938
1.4681316168337408
0.3594838777305754
1.044968292393877
0.13343142311809167
1.245500389220033
0.972695479388866
-0.9467836305269092Case 3: worst-case robust approximation
p = minimize(max(norm((A - B) * x - b), norm((A + B) * x - b)))
solve!(p, SCS.Optimizer; silent = true)Problem statistics
problem is DCP : true
number of variables : 1 (10 scalar elements)
number of constraints : 0 (0 scalar elements)
number of coefficients : 440
number of atoms : 7
Solution summary
termination status : OPTIMAL
primal status : FEASIBLE_POINT
dual status : FEASIBLE_POINT
objective value : 3.1074
Expression graph
minimize
└─ max (convex; positive)
├─ norm2 (convex; positive)
│ └─ + (affine; real)
│ ├─ …
│ └─ …
└─ norm2 (convex; positive)
└─ + (affine; real)
├─ …
└─ …
x_wc = evaluate(x)10-element Vector{Float64}:
-1.4077935065589733
-0.7708528545924024
0.4340986064887942
0.7150650375789294
0.3549832867546775
0.5765731953566027
-0.1493404886952227
0.5790725012045536
0.38827430529998863
-0.30233119908541867Plots
Here we plot the residuals.
parvals = range(-2, stop = 2, length = 100);
errvals(x) = [norm((A + parvals[k] * B) * x - b) for k in eachindex(parvals)]
errvals_ls = errvals(x_nom)
errvals_stoch = errvals(x_stoch)
errvals_wc = errvals(x_wc)
using Plots
plot(parvals, errvals_ls, label = "Nominal problem")
plot!(parvals, errvals_stoch, label = "Stochastic Robust Approximation")
plot!(parvals, errvals_wc, label = "Worst-Case Robust Approximation")
plot!(
title = "Residual r(u) vs a parameter u for three approximate solutions",
xlabel = "u",
ylabel = "r(u) = ||A(u)x-b||_2",
)This page was generated using Literate.jl.