cvxr / CVX

A MATLAB system for disciplined convex programming
Other
226 stars 83 forks source link

What is a good way to adjust both parameters of a convex optimization problem? #26

Closed KarryMa closed 3 months ago

KarryMa commented 3 months ago

Here is my matlab code, cvx objective function has two regularization parameters tau1 and tau2. I need to set appropriate tau1 and tau2 values to make re1 and re2 small enough (minimum would be best). I have tried many, many values, including using the for loop, but still can't get the best re1 and re2 results. Is there another way (e.g. intelligent algorithms) to find the right parameters? Thank you very much!

clc;clear
n = 128;
m = 64;
i_s = floor(m*0.05);
i_c = i_s;
x0 = zeros(n,1);
x10_spt = randperm(n);
x0(x10_spt(1:i_c)) = randn(i_c,1);
v0 = zeros(m,1);
v0_spt = randperm(m);
v0(v0_spt(1:i_c)) = randn(i_c,1);
Phi = 1/sqrt(m) * randn(m,n);
data = real(Phi * x0);
N = 200;
p = (1+data)/2;
s0 = rand(numel(data),N);
P = repmat(p,1,N);
s = P > s0;
s1 = sum(s,2);
s2 = s1/N;
edata = 2*s2-1;
y = edata + v0 ;
% these two parameters I need to tune, I have tried for loop, but can't get
% good results of re1 and re2
tau1=0.01; 
tau2=0.01;
% Recovery via CVX
cvx_begin quiet

variable x(n) ;
variable v(m);
minimize 0.5*pow_pos(norm(y - Phi * x - v),2) + tau1 * norm(x,1) + tau2 * norm(v,1);

cvx_end
re1 = norm(x - x0, 2)/ norm(x0, 2)
re2 = norm(v - v0, 2)/ norm(v0, 2)
% how to find the optimal tau1 and tau2,then re1 and re2 are minimum respectively 
aszekMosek commented 3 months ago

This is not an issue/bug in CVX but a general modeling question for which a better venue would be https://or.stackexchange.com/search?tab=newest&q=mosek or https://math.stackexchange.com/search?tab=newest&q=mosek or some forum corresponding to the real-world domain your model is representing.