How to express an expression as a valid CVX-compatible function

Hi everyone,

I’m trying to optimize a function using CVX . My goal is to convexify a non-convex function by adding a strongly convex regularization . Here’s what I’m working with:

I define a function

f_nonconvex = @(x) sum((x(1) - samples) ./ x(2)) ...
               - 2 * sum(log(1 + exp((x(1) - samples) ./ x(2)))) ...
             ;

The variable samples is a vector of scalar values (data samples). Then, I define a regularization term:

g = @(x) 0.5 * lambda * sum_square(x);

I set the total objective as:

f = @(x) f_nonconvex(x) + g(x);

However, when I attempt to run this function in CVX using:

cvx_begin
    variable x(2) x(1)
    minimize(f(x))
cvx_end

I get the following error:

Error using cvxprob/newobj (line 57)
Disciplined convex programming error:
   Cannot minimize a(n) invalid expression.

I understand that f_nonconvex is non-convex—it comes from a logistic-type expression—and the regularizer g(x) is strongly convex. I use a large enough lambda, hoping the sum becomes convex overall. But CVX still raises a DCP error.

Is there any workaround or recommendation on how to formulate this properly in CVX?

Thanks in advance!

First of all, you shouldn’t just hope your optimization problem is convex, you must prove it. Even if you do, it’s not necessarily the case that it can be expressed using CVX"s rules.

Even if you accomplished that, it may be that the needed value of lambda depends on the input data, sample. And would the solution of this regularized problem with a giant value of lambda be meaningful relative to your original purpose in trying to solve this optimization problem?

Thanks for your response. I verified that the function
f(x) is convex — the regularizer ( g(x) ) is strongly convex and dominates the nonconvexity in f_nonconvex (x), so the sum is convex overall.

However, CVX still throws a DCP error when I try to solve it.
Do you think there’s a way to rewrite the problem — maybe using a change of variables or a different formulation — to make it DCP-compliant? I’d really appreciate any suggestions or guidance.

Perhaps you can show us your detailed proof, with clear statement of all assumptions and relevant input data.

To succeed in CVX, you will need to make the convexity proof constructive, i.e., by using building blocks allowed in CVX.