# Convex optimization of a least squares regularized objective function [closed]

Given, a vector of observations $$\mathbf{y}=(y_1, y_2,\ldots,y_n)$$ I am trying to find the soltuion to the following optimization problem: $$\min{ (1/2) \|\mathbf{y-x}\|_2^2 + \lambda \|\mathbf{Dx}\|_1}$$

where $$\mathbf{D}$$ is a Toeplitz matrix withe first row given by $$(1, -2, 1, 0, \ldots,0)$$ or

$$\mathbf{D}=\left[\begin{matrix} 1 & -2 & 1 &0 &\cdots &0 &0\\ 0 &1 & -2 & 1 &0 &\cdots &0\\ \vdots & \vdots &\vdots &\vdots &\vdots &&\vdots \\ 0 &0 &\cdots &0 &1 & -2 & 1\\ \end{matrix}\right]$$

The objective function given is convex and coercive and has a unique global minimizer $$x^*$$. However trying to code the probelm in Mathematica using ConvexOptimization[] gives an error. Here is what I am trying:

winlen = 10;
lambda = 10;
MatD = ToeplitzMatrix[Join[{1.}, ConstantArray[0, {winlen - 3}] ],
Join[{1., -2., 1.}, ConstantArray[0, winlen - 3]]];


and

ConvexOptimization[
1/2 Norm[Range[10] - x]^2 + lambda Norm[MatD . x, 1], True,    x \[Element] Vectors[10, Reals]];


which gives the error:

ConvexOptimization::scobj: The objective function 1/2 (Abs[1-x]^2+Abs[2-x]^2+Abs[3-x]^2+Abs[4-x]^2+Abs[5-x]^2+Abs[6-x]^2+Abs[7-x]^2+Abs[8-x]^2+Abs[9-x]^2+Abs[10-x]^2)
+Norm[{{1.,-2.,1.,0.,0.,0.,0.,0.,0.,0.},<<6>>,{<<1>>}}.x,1] should be scalar valued.


Any work around for this? (using subscripts does not work).

• There are several syntax error in the above, e.g. MatD and matD, lambda and lamdba. Apr 21 at 10:49
• It is pretty sad to see that since administrators do not understand or have experience in a certain area of specialization they chose to close the question. I think the question is pretty clearly state as it is. There is no ambiguity in it. You cannot expect me to give the whole background of where this optimization problem arises. Thanks anyways. The question has already been answered. Apr 23 at 16:43

Using an explicit vector

Clear["Global*"]

winlen = 10;
lambda = 10;
MatD = ToeplitzMatrix[

X = Array[x, winlen];

Format[x[n_]] := Subscript[x, n]

sol = ConvexOptimization[
1/2 Norm[Range[winlen] - X]^2 + lambda Norm[MatD . X, 1], True, X]


1/2 Norm[Range[winlen] - X]^2 + lambda Norm[MatD . X, 1] /. sol

(* 3.33067*10^-14 *)

Y = Array[y, winlen];

Format[y[n_]] := Subscript[y, n]

sol2 = ConvexOptimization[1/2 Norm[Y - X]^2 + lambda Norm[MatD . X, 1],
True, Flatten@{X, Y}]


1/2 Norm[Y - X]^2 + lambda Norm[MatD . X, 1] /. sol2

(* 8.88178*10^-14 *)
`