This notebook shows how to solve a minimum-length least squares problem, which finds a minimum-length vector $x \in \mathbf{R}^n$ achieving small mean-square error (MSE) for a particular least squares problem:
\begin{equation*} \begin{array}{ll} \mbox{minimize} & \mathrm{len}(x) \\ \mbox{subject to} & \frac{1}{n}\|Ax - b\|_2^2 \leq \epsilon, \end{array} \end{equation*}where the variable is $x$ and the problem data are $n$, $A$, $b$, and $\epsilon$.
This is a quasiconvex program (QCP). It can be specified using disciplined quasiconvex programming (DQCP), and it can therefore be solved using CVXPY.
In [0]:
!pip install --upgrade cvxpy
In [0]:
import cvxpy as cp
import numpy as np
The below cell constructs the problem data.
In [0]:
n = 10
np.random.seed(1)
A = np.random.randn(n, n)
x_star = np.random.randn(n)
b = A @ x_star
epsilon = 1e-2
And the next cell constructs and solves the QCP.
In [24]:
x = cp.Variable(n)
mse = cp.sum_squares(A @ x - b)/n
problem = cp.Problem(cp.Minimize(cp.length(x)), [mse <= epsilon])
print("Is problem DQCP?: ", problem.is_dqcp())
problem.solve(qcp=True)
print("Found a solution, with length: ", problem.value)
In [15]:
print("MSE: ", mse.value)
In [17]:
print("x: ", x.value)
In [18]:
print("x_star: ", x_star)