After assigning a value to N, I executed your function and calling sequence EXACTLY as written, where I put in the lines
minimize(norm(w))
w >= 0
in place of your placeholder
minimize "some function that involves w"
It worked correctly, and on each function exit, w contained the argmin from the optimization. That being said, the MATLAB editor did display some warnings (for instance, the variable declaration), presumably because it doesn’t “understand” what CVX is doing.
@Mark L. Stone: Thanks for checking. I don’t always get the error, but oddly enough it runs fine if I just paste the loop directly into the Matlab window. I’m not doing anything funny before the CVX call, only running cvx_clear and cvx_solver_settings('MSK_IPAR_NUM_THREADS',2).
@mcg: The function I’m optimizing is defined inside call_cvx as minimize norm(w) + (C/M)*sum(log_sum_exp(tmp')) where tmp = [zeros(M,1) -Y.*(S'*HAm*w+w0)] (i.e., just standard logistic regression).
No, my question is: is that the only thing inside the file, or is there something else? CVX is known not to work inside nested functions, for instance.
@mcg: Got ya. I have a main script that calls call_cvx, which is it’s own file and not nested within another function. So is there something simple I’m missing? In my main script, I call cvx_clear to reset things before I iterate, and I also make sure CVX is in my path.
I am a new user, also wondering if cvx could be made compatible with nested functions. If you have any nested functions in your code, then your workspace is static and cvx’s calls to assignin() and evalin() cause a series of errors.
To hopefully overcome this, one by one I initialized variables in my nested code:
% problem setup
m = 16; n = 8;
A = complex(randn(m,n),randn(m,n));
b = complex(randn(m,1),randn(m,1));
% local initializations
x = []; % decision variable
cvx_problem = [];
cvx_status = [];
cvx_optval = [];
cvx_optbnd = [];
cvx_slvitr = [];
cvx_slvtol = [];
cvx_cputime = [];
Aeq = [];
pop = @() 0;
% cvx
cvx_begin
variable x(n) complex
minimize( norm(A*x-b) )
cvx_end
Actually, this got me pretty far. The problem is entered and solved. But… pop() throws a curveball. pop() is a method found in cvx/lib/@cvxprob. It’s called by cvx_end.m as evalin(‘caller’,‘pop(…)’). So, I tried two things:
copied pop.m to the local dir
added assignin(‘caller’,‘pop’,@pop) to cvx_end.m before the evalin().
For some reason, doing either of these caused matlab to crash instantly (segmentation violation).
So, I gave up. Maybe it’s just my machine and it will work for others, or perhaps someone could solve the problem with pop()?
Peter
PS As a new user I have to say wow, CVX is really nice!