Error running fmincon

Dear Octave users:

I’m calling fmincon with options set as:

options = optimset('Algorithm','active-set','Display','off', 'TolFun', 0.1);

with the following constraints:

Aeq, beq, lb, ub, x0.

Inputs are like this:

|rA|rB|rC|
|1.02|-1.12|-0.37|
|NaN|-0.14|2.73|
|1.04|-1.42|-0.67|
|0.05|-0.62|-0.18|
|-0.31|0.46|0.45|
|-1.03|-1.43|-2.17|
|2.08|-1.13|-1.29|
|-1.48|-0.72|-2.20|
|2.80|3.19|1.10|
|2.37|0.32|-0.28|
|-1.53|-0.51|-1.52|
|-3.10|-0.29|0.10|
|-0.98|0.51|1.30|
|5.21|0.59|0.24|

As you see, inputs are column series of real values, and it works perfectly when I don’t have any NaN field. However, with a single NaN field in any of the columns, I get the following errors:

error: qp: failed to compute eigenvalues of H
error: called from
    qp at line 422 column 29
    sqp at line 425 column 31
    __octave_sqp_wrapper__ at line 76 column 60
    fmincon at line 451 column 24 

qp at line 422 column 29 reads:

 if (info == 0)
    ## The initial (or computed) guess is feasible.  Call the solver.
    [x, lambda, info, iter] = __qp__ (x0, H, q, A, b, Ain, bin, maxit, rtol); %(LINE 422)
  else
    iter = 0;
    x = x0;
    lambda = [];
  endif

sqp at line 425 column 31 reads:

## Compute search direction p by solving QP.
g = -ce;
d = -ci;

old_lambda = lambda;
[p, obj_qp, INFO, lambda] = qp (x, B, c, F, g, [], [], d, C,
                                Inf (size (d)), struct ("TolX", tol)); % LINE 425

info = INFO.info;

octave_sqp_wrapper at line 76 column 60 reads:

## call sqp
[p_res, objf, info, outp.niter, outp.nobjf, outp.lambda] = ...
      sqp (pin, passed_f, {equc, dequc}, {inequc, dinequc}, -Inf, Inf,
           niter, tolerance);

My code works perfectly using Matlab’s fmincon.

Any help would be appreciated.
Thank you.

My system

  • Ubuntu 14.04 LTS
  • Octave version: 6.3.0 (2021-07-11)
  • Installation method: snap installation.

Please show us relevant portions of your code also. Particularly the variable which has the single NaN in it, and where that variable is used in connection with fmincon.

As a general comment, having NaN values is going to be a problem. If you are using NaN to substitute for data that you don’t have (for example, a sensor was faulty or someone simply forgot to record a data point at a particular time) then you would be better off choosing a value that is numerical but outside of any normal bounds.

The problem is that when NaN is used in any mathematical operation the result is also NaN so even one instance can slowly poison all future calculations.

NaN + 1 -> NaN
NaN - 1 -> NaN
NaN * 2 -> NaN
NaN / 2 -> NaN

In this case, trying to compute the eigenvalues of a matrix requires lots of multiplication and summation operations which inevitably get corrupted.

Thank you.

Thank you, rik. I am using nanmean (and others to ignore or treat NaN) function, and all works fine in Matlab.
I will check all your suggestions, though! Thanks!