Why does cvx output a nan result for an unconstrained problem?

Hi every one. I have a problem as

\mathop {\min }\limits_{\mathbf{w}} \;\operatorname{tr} \left[ {{{\left( {{{\mathbf{H}}^{\text{T}}}\left[ {\left( {{\mathbf{w}}{{\mathbf{y}}^{\text{T}}} \otimes {\mathbf{E}}} \right) \circ {\mathbf{J}}} \right]{\mathbf{H}}} \right)}^{ - 1}}} \right] + {{\mathbf{u}}^T}\left( {{\mathbf{w}} - {\mathbf{y}}} \right) + z\left( {{{\mathbf{w}}^{\text{T}}}{\mathbf{y}} - N} \right) + \frac{{{\rho _1}}}{2}\left\| {{\mathbf{w}} - {\mathbf{y}}} \right\|_2^2 + \frac{{{\rho _2}}}{2}{\left( {{{\mathbf{w}}^{\text{T}}}{\mathbf{y}} - N} \right)^2}
,

which is an inner optimization of a outer loop. I realize the problem by cvx as

cvx_begin
variable w(n,1)
temp = kron(y’,I0);
JS = H*(kron(w,E) * temp .* J) *H’;
JS = 0.5 * (JS + JS’);
Obj1 = trace_inv(JS);
Obj2 = u’ * (w - y) + z * (y’ * w - N);
Obj3 = rau1/2 * square_pos(norm(w - y,2)) + rau2/2 * square((y’ * w - N));
minimize Obj1 + Obj2 + Obj3
cvx_end

Since the problem is unconstrained, a minimum can be found. However, when I execute the code, sometimes, cvx_status is ‘Failed’ and the output is ‘NAN’. How does it happen. Is there something wrong with my code? Thank you very much.

You haven’t provided a reproducible problem. So forum readers can’t try for themselves.

If you show the solver and CVX output, perhaps a forum reader will be able to help you.

Does the solver report that it ran into numerical problems? In such a case, a poorly scaled problem (input data) might be a contributing factor. If the solver ran into numerical problems, the CVX variable values might be NaN.

Does CVX status show the problem was determined to be infeasible? If so, the CVX variable values would be NaN.

Have you tried another solver? Gurobi and Mosek are more robust and reliable than SeDuMi. SDPT3, and ECOS.

Thank you for your reply! I’ve tried cvx with Mosek. However, Gurobi still seems unavailable with academic license. I notice that whether the optimization ends up with succeed or failure depends on the specific values of H, J and y. On account that the problem looks convex and bounded, the optimization should always find a minimum. Is there something important that I missed ? Thank you!

Here is the full CVX status of one failed trial. I don’t really understand what “MOSEK warning 710: #2 (nearly) zero elements are specified in sparse col ‘’ (9) of matrix ‘A’.” means, since all the matrices are actually not very sparse.

Calling Mosek 8.0.0.60: 166 variables, 30 equality constraints

MOSEK Version 8.0.0.60 (Build date: 2017-3-1 13:09:33)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

MOSEK warning 710: #2 (nearly) zero elements are specified in sparse col ‘’ (9) of matrix ‘A’.
MOSEK warning 710: #1 (nearly) zero elements are specified in sparse col ‘’ (10) of matrix ‘A’.
MOSEK warning 710: #3 (nearly) zero elements are specified in sparse col ‘’ (11) of matrix ‘A’.
MOSEK warning 710: #1 (nearly) zero elements are specified in sparse col ‘’ (22) of matrix ‘A’.
MOSEK warning 710: #2 (nearly) zero elements are specified in sparse col ‘’ (23) of matrix ‘A’.
MOSEK warning 710: #2 (nearly) zero elements are specified in sparse col ‘’ (35) of matrix ‘A’.
MOSEK warning 710: #3 (nearly) zero elements are specified in sparse col ‘’ (46) of matrix ‘A’.
MOSEK warning 710: #1 (nearly) zero elements are specified in sparse col ‘’ (65) of matrix ‘A’.
MOSEK warning 710: #2 (nearly) zero elements are specified in sparse col ‘’ (70) of matrix ‘A’.
MOSEK warning 710: #1 (nearly) zero elements are specified in sparse col ‘’ (71) of matrix ‘A’.
Warning number 710 is disabled.
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 30
Cones : 3
Scalar variables : 130
Matrix variables : 1
Integer variables : 0

Optimizer started.
Conic interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator - tries : 0 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Optimizer - threads : 4
Optimizer - solved problem : the primal
Optimizer - Constraints : 28
Optimizer - Cones : 3
Optimizer - Scalar variables : 128 conic : 127
Optimizer - Semi-definite variables: 1 scalarized : 36
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 374 after factor : 374
Factor - dense dim. : 0 flops : 2.52e+004
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 1.0e+000 4.3e+001 6.4e+001 0.00e+000 1.606400000e+004 0.000000000e+000 1.0e+000 0.05
1 2.5e-001 1.1e+001 8.1e+000 -9.67e-001 1.435270491e+004 -4.566146947e+001 2.5e-001 0.09
2 4.1e-002 1.8e+000 7.2e-001 -8.33e-001 7.621737010e+003 3.754733745e+002 4.1e-002 0.09
3 2.2e-002 9.7e-001 3.8e-001 -2.32e-001 1.008588247e+004 5.216642299e+003 2.2e-002 0.11
4 6.9e-003 3.0e-001 1.5e-001 1.09e-001 1.145078388e+004 9.859987956e+003 6.9e-003 0.11
5 3.5e-003 1.5e-001 6.4e-002 2.82e-001 1.737741905e+004 1.705861052e+004 3.5e-003 0.11
6 1.4e-003 6.0e-002 3.7e-002 6.07e-001 2.191438244e+004 2.181622849e+004 1.4e-003 0.11
7 5.9e-004 2.5e-002 1.1e-002 -3.75e-002 3.191689530e+004 3.331171505e+004 5.9e-004 0.13
8 1.7e-004 7.2e-003 5.6e-003 7.41e-001 3.829529524e+004 3.872144761e+004 1.7e-004 0.13
9 5.5e-005 2.4e-003 1.8e-003 2.98e-001 4.560988833e+004 4.627966020e+004 5.5e-005 0.13
10 1.3e-005 5.4e-004 8.0e-004 9.16e-001 4.848015435e+004 4.867054255e+004 1.3e-005 0.13
11 2.8e-006 1.2e-004 2.8e-004 7.05e-001 4.990039866e+004 4.998859351e+004 2.8e-006 0.14
12 5.4e-007 2.4e-005 5.9e-005 4.44e-001 5.067988011e+004 5.076014356e+004 5.4e-007 0.14
13 7.1e-008 3.1e-006 4.9e-006 -2.39e-001 5.206786215e+004 5.228562592e+004 7.1e-008 0.14
14 2.1e-008 9.3e-007 1.6e-006 1.09e-001 5.300518759e+004 5.319759686e+004 2.1e-008 0.16
15 7.3e-009 3.2e-007 3.4e-007 -3.69e-001 5.466387813e+004 5.515861186e+004 7.3e-009 0.16
16 1.3e-009 5.6e-008 5.5e-008 -1.85e-001 5.809007216e+004 5.867653631e+004 1.3e-009 0.16
17 2.6e-010 1.1e-008 8.8e-009 -1.73e-001 6.334811078e+004 6.428345562e+004 2.6e-010 0.17
18 9.2e-011 4.0e-009 2.3e-009 -2.93e-001 6.922078688e+004 7.096251482e+004 9.2e-011 0.17
19 2.2e-011 9.8e-010 5.4e-010 -1.10e-001 7.872399188e+004 8.053046432e+004 2.2e-011 0.17
20 7.5e-012 3.3e-010 1.4e-010 -2.61e-001 9.142956064e+004 9.464345238e+004 7.5e-012 0.17
21 1.9e-012 8.3e-011 3.3e-011 -1.23e-001 1.103981153e+005 1.139069233e+005 1.9e-012 0.19
22 6.7e-013 2.9e-011 8.7e-012 -2.69e-001 1.355518866e+005 1.417601894e+005 6.7e-013 0.19
23 1.8e-013 7.9e-012 2.4e-012 -6.97e-002 1.703689436e+005 1.763929330e+005 1.8e-013 0.19
24 6.5e-014 2.8e-012 6.2e-013 -2.97e-001 2.200211163e+005 2.315300945e+005 6.5e-014 0.20
25 1.6e-014 7.0e-013 1.5e-013 -1.21e-001 2.982888998e+005 3.104941998e+005 1.6e-014 0.20
26 5.5e-015 2.3e-013 3.7e-014 -2.85e-001 4.037415188e+005 4.257540162e+005 5.4e-015 0.20
27 1.3e-015 5.6e-014 8.0e-015 -1.88e-001 5.820626185e+005 6.094276246e+005 1.3e-015 0.22
28 5.3e-016 2.2e-014 2.4e-015 -3.36e-001 7.866302568e+005 8.340192065e+005 5.1e-016 0.22
Interior-point optimizer terminated. Time: 0.22.

Optimizer terminated. Time: 0.28

Interior-point solution summary
Problem status : ILL_POSED
Solution status : PRIMAL_ILLPOSED_CER
Dual. obj: 1.4486224135e-003 nrm: 1e+002 Viol. con: 0e+000 var: 1e-006 barvar: 2e-009 cones: 0e+000
Optimizer summary
Optimizer - time: 0.28
Interior-point - iterations : 28 time: 0.22
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Failed
Optimal value (cvx_optval): NaN

MOSEK is complaining about model coefficient values which are too close to zero without being exactly zero. In the run shown, such coefficients are apparently causing such great numerical difficulty that MOSEK is unable to solve the problem (in double precision), even though there might exist an exact solution which could be found if high enough precision arithmetic were used. You should try to get numerical coefficients in your model to be either exactly zero or within a small number of orders of magnitude of one.