The following expression arises in the objective function for logistic regression and I was told the function is convex:
log(1 / (1+exp(z)).
Is it possible to write this function in a way that CVX will recognize its convexity?
Log of sigmoid function
Convex constraint on the restricted domain of a non DCP compliant function
Convex/nonconvex approximation to F1
log(1/(1+exp(z))) is actually concave, and CVX recognizes and accepts it as such, so for instance, you can maximize it as an objective function in CVX. It will require use of CVXâs successive approximation method (which will be invoked automatically), as described in the CVX userâs guide. Of course, log(1+exp(z)) being log(1/(1+exp(z))) is convex and can be minimized, which will accomplish the same thing.
See http://cvxr.com/cvx/examples/cvxbook/Ch07_statistical_estim/html/logistics.html for an example of logistic regression performed in CVX, and also http://matlabcodebywayne.googlecode.com/svn/branches/cvx/examples/cvxbook/Ch07_statistical_estim/html/logistics_gp.html , which additionally shows reformulation of logistic regression as a Geometric Program and solution in CVX by use of CVXâs Geometric Programming mode, which, as stated in the CVX userâs guide, also uses CVXâs successive approximation method.
It might be a bit surprising to CVX power users that log(1/(1+exp(z)))
is accepted by CVX. After all, it does not seem to obey the disciplined convex programming ruleset!
But in fact, in order to support geometric programming, CVX has a lesser known set of rules governing log convexity as well. The definition of log convexity is this: if a function is positive and its logarithm is convex, then it is logconvex. There are equivalent definitions of logaffine and logconcave functions as well.
We donât publish the logconvexity rules explicitly. But if youâre a power user you might be interested in them. First, we have the following rules that take you back and forth between the âstandardâ convexity world and the logconvexity world:

exp(*affine*)
is logaffine;exp(*convex*)
is logconvex;exp(*concave*)
is logconcave. 
log(*logaffine*)
is affine;log(*logconvex*)
is convex;log(*logconcave*)
is concave.  Logaffine expressions are also logconcave and logconvex.
 Positive constants are logaffine, logconcave, and logconvex.
Given those basics, you can actually take most of the basic DCP rules and map them to logconvexity:
 Products: products of {logaffine,logconvex,logconcave} expressions are {logaffine,logconvex,logconcave}. This is the logconvexity equivalent of DCPâs sum rules.
 Positive exponents: A {logaffine,logconvex,logconcave} expression raised to a positive constant power is {logaffine,logconvex,logconcave}. This is the logconvexity equivalent of DCPâs positive scaling rules.
 Negative exponents: A {logaffine,logconvex,logconcave} expression raised to a negative constant power is {logaffine,logconcave,logconvex}. This is the logconvexity equivalent of DCPâs negative scaling rules.
 Ratios: The ratio of a {logconvex,logconcave,logaffine} and a {logconcave,logconvex,logaffine} expression is {logconvex,logconcave,logaffine}. This is the equivalent of differences in DCP. So, not surprisingly, taking the ratio of two logconvex expressions is invalid, because this would be equivalent to subtracting one convex expression from another.
There is one rule for logconvexity, however, that does not have a DCP analog. It is this:
 Sums of logaffine and/or logconvex expressions are logconvex. Sums of logconcave expressions are not permitted. Note that even if every term of the sum is logaffine, the resulting sum is logconvex.
Confusing? Well, yeah, it is. But letâs go through log(1/(1+exp(z)))
to see why CVX accepts it:
 Both
1
andexp(z)
are logaffine.  The sum
1+exp(z)
is therefore logconvex.  The ratio
1/(1+exp(z))
is logconcave. Alternatively, it is equivalent to(1+exp(z))^(1)
, which is logconcave by the negative exponent rule.  Therefore,
log(1/(1+exp(z)))
is concave.
Nonnegative object came to the result unbounded
Why does CVX accept log(2^exp(x)) but don't accept log(2^exp(x)1)
How can formulate difference between to variable
Suggestion to mcg: Please add the CVX logconvexity and logconcavity rules to the next version of the CVX userâs guide. Thanks.
Frankly this is the first time Iâve written them all out! They kind of fell out by accident when I was implementing the geometric programming support. I probably should include them, in at least an advanced section.
My one hesitation is that it still relies on the successive approximation system. I really donât want to encourage its use any more than necessary But in fact, GPs seem reasonably reliable compared to log/exp in general, so maybe this will be kind of harmless.
Mark, I have indeed added a section to the advanced chapter of the CVX manual. It will come out with the next major release (weâve got a new capability coming so itâs a semimajor release, not my normal rapid release style).
my objective function minimize (Mn  mu_n (1+exp(convex))
where mu_n is nonnegative parameter
Mn is constant value
error is real (affine.*log convex)
How to solve this
Per my answer to you at If dual variables are non negative, Is there need to initialized?
If mu_n
does not appear in any constraints other than being nonnegative, mu_n = 0
is optimal, together with any feasible values of the other variables.
Thank you, Sir
Can i formulate lagrangian dual function like this
cvx_begin quiet
cvx_solver mosek
variable Pi %optimization variables
variable Pj
dual variables nu rho eta phi
minimize (Mnmu_n.*(1+exp(an.*(gnx(1,i).*(Pi+Pj)bn)))+nu.*(Pi.*hix(1,1)Omega_i.* (Pj.*hix(1,1)+Ni))+ rho.*(Pj.*hjx(1,1)Omega_j.*Nj)+ eta.*(Pi.*hjx(1,1)Omega_t.*(Pj.*hjx(1,1)+Nj))+sum(phi.*(Gamma_mqmx.*(Pi+Pj)))) % optimizing Pi and Pj (optimal allocated power)
subject to
nu >= 0;
rho >= 0;
eta >= 0;
phi >= 0;
mu_n >= 0;
cvx_end
Warning like this,
Warning: A nonempty cvx problem already exists in this scope.
It is being overwritten.
In cvxprob.cvxprob at 28
In cvx_begin at 41
In feb19 at 43
Error using evalin
Undefined function âtimesâ for input arguments of type âcvxdualâ.
Error in minimize (line 14)
x = evalin( âcallerâ, sprintf( '%s ', varargin{:} ) );
Error in feb19 (line 48)
minimize (Mnmu_n.(1+exp(an.(gnx(1,i).(Pi+Pj)bn)))+nu.(Pi.hix(1,1)Omega_i.(Pj.hix(1,1)+Ni))+ rho.(Pj.hjx(1,1)Omega_j.Nj)+
eta.(Pi.hjx(1,1)Omega_t.(Pj.hjx(1,1)+Nj))+sum(phi.(Gamma_mqmx.(Pi+Pj)))) % optimizing Pi and Pj (optimal allocated power)
You will not find anywhere in the CVX Usersâ Guide which allows you to use declared dual variables in any manner other than as described at http://cvxr.com/cvx/doc/basics.html#dualvariables . Hence the error message. Declared dual variables can be associated with constraints as described in that section, and their values will be populated by CVX after it completes, but that is their only usage. i
f you want to do something more with a variable, it needs to be declared as a (CVX) variable, not as a dual variable. And of course CVXâs DCP rules must be followed.
Undefined function 'times' for input arguments of type 'cvxdual'