# Solving a Weighted Basis Pursuit Denoising Problem (BPDN) with MATLAB / CVX

Following up from an answer by @Royi on adding weights to BPDN problem , I would like to use CVX to test this approach. How can we formulate in CVX the regularized LS L1 norm with weights given by a vector $$c$$, as follows:
$$\arg \min_{\boldsymbol{x}} \frac{1}{2} {\left\| A \boldsymbol{x} - \boldsymbol{y} \right\|}_{ {C}^{-1} }^{2} + \lambda {\left\| \boldsymbol{x} \right\|}_{1}$$

Where $$C$$ is the covariance matrix $$\operatorname{diag} \left( \boldsymbol{c} \right)$$ ?

Here's a minimal example using Matlab:

% problem data
A  = [1    0    0   0.5;...
0    1  0.2   0.3;...
0  0.1    1   0.2];
x0 = [1 0 1 0]';    % original signal
y  = A*x0;          % measurements with no noise
w  = randi(1e3,1,numel(y))'; % random weights vector
y  = y +  1./(sqrt(w)).*randn(numel(y),1); % measurements with weighted noise


CVX that does not include the weights info would be:

lambda = 0.01;      % regularization parameter
cvx_precision high
cvx_solver  SeDuMi
cvx_begin quiet
variable x(size(A,2),1);
minimize(norm(A*x-y)+lambda*norm(x1,1))
cvx_end

x =
0.9864
-0.0281
1.0108
0

• Could you share the data you have or an example of the data? Or a MATLAB script to generate it?
– Royi
Nov 12, 2021 at 9:04
• I added a minimal example...
– bla
Nov 12, 2021 at 9:38

A MATLAB code which implements the problem as defined and solve it using CVX is given by:

%% General Parameters
close('all');
clear('all');

%% Simulation Parameters
numRows = 6;
numCols = 10;

varianceFctr    = 3;
paramLambda     = 2.75;

%% Generate Data
mA  = randn(numRows, numCols);
vX0 = rand(numCols, 1) >= 0.65;
vC  = varianceFctr * rand(numRows, 1);

mCInv = diag(1 ./ vC);

vY = (mA * vX0) + (sqrt(vC) .* randn(numRows, 1));

%% Solving by CVX
cvx_begin('quiet')
% cvx_precision('best');
variable vX(numCols);
minimize( 0.5 * quad_form(mA * vX - vY, mCInv) + (paramLambda * norm(vX, 1)) );
cvx_end
$$$$

• I dont have InitScript.m is that important? is mCInv similar to 1./(sqrt(w)) in my example?
– bla
Nov 14, 2021 at 5:35
• I removed the need for InitScript.m. vC is the vector of variances. Hence the noise added is by it. In order to create the inverse of the matrix $C$ I just used the inverse of each value (As it is a diagonal matrix).
– Royi
Nov 14, 2021 at 6:10
• maybe I dont understand from your code, the noiseless signal mA * vX0 and the noisy signal vY , but you solve for vX so should I compare vX to vX0 ? (because the values there are not close)
– bla
Nov 14, 2021 at 6:18
• Yes, vX0 is the reference and vX is the solution. They are not close even in the case vC = 1` as the issue is with the sparse reconstruction. But the question is about solving the problem, not if the sparse model solution is perfect.
– Royi
Nov 14, 2021 at 6:52