Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Negative Objective Function reported by CPLEX

    Posted Thu August 21, 2014 09:25 AM

    Originally posted by: ChristophHeidelberg


    Similar to this question (https://www.ibm.com/developerworks/community/forums/html/topic?id=3fdbaa8a-f76b-49f1-a41b-f2df4e9b2f33&ps=100 ) I would like to do Least Squared optimisation (with a quadratic constraint in my case). In each iteration but the first I get a negative value for the objective function.

    Can some one tell me why that is? I assume I've done something wrong in setting up my problem, but surely the objective function should not be negative in a least squares problem.

     

    Here is the code.

     

    n = 26625; % Or try smaller values n=100, dim=5, dictsize=20
    dim = 31;
    dictsize = 500;
    A = rand(dictsize,n);
    D = rand(dim, dictsize);
    D = bsxfun(@rdivide, D, sqrt(sum(D .^2))); % Normalise D.
    X = D * A;


    d = D';
    d = d(:)';

    x = X';
    x = x(:)';

    A_aug = [];
    for i=1:dim
        A_aug = blkdiag(sparse(A), A_aug);
    end

    disp(norm(x - d*A_aug, 2));

    % Setup constraints
    % Q = sparse(eye(dim*dictsize));
    % r = 1* dictsize;
    % l = zeros(dim*dictsize,1);
    Q = cell(1, dictsize);
    r = zeros(1, dictsize);
    l = zeros(dim*dictsize, dictsize);
    for i=1:dictsize
        r(i) = 1;
        Q{i} = sparse(zeros(dim*dictsize));
        il = (i-1)*dim + 1;
        iu = i*dim;
        Q{i}((il:iu),(il:iu)) = sparse(eye(dim));
        l(:,i) = zeros(dim* dictsize, 1);
    end


    options = cplexoptimset('MaxIter', 30, 'Display', 'on');
    % Optimise
    tic;
    [d_est, resnorm, ~, exitflag, output] = cplexlsqqcp(A_aug',x',zeros(1, dim*dictsize),ones(1,1),...
                              zeros(1,dim*dictsize),zeros(1,1),...
                              l,Q, r,...
                              [], [], [],...
                               options);
    toc;

    if exitflag > 0
        fprintf('Valid solution found\n');
        fprintf('Time taken %f, %d\n', output.time, output.iterations);
        fprintf('Error: %f\n', resnorm);
    end
    disp(norm(d - d_est') / norm(d));
    Dest = reshape(d_est, [dim dictsize]);
     

    The code works but prints negative values for the objective function...


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Negative Objective Function reported by CPLEX

    Posted Thu August 21, 2014 10:31 AM

    What is the value of exitflag? Does it indicate that CPLEX found an optimal solution? What is the value of resnorm? Is it only barely negative or is it significantly smaller than 0?

    Could you post the log output here as well, please?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Negative Objective Function reported by CPLEX

    Posted Thu August 21, 2014 10:54 AM

    Originally posted by: ChristophHeidelberg


    Hi Daniel,

    here are the outputs you requested. (I ran this with the indicated smaller dimensionalities.)

    Note that the column "Primal Obj" is negative for every iteration except the first. The same for the "Dual Obj".

     

    Tried aggregator 1 time.
    QCP Presolve eliminated 2 rows and 0 columns.
    Aggregator did 1 substitutions.
    Reduced QCP has 122 rows, 222 columns, and 1173 nonzeros.
    Reduced QCP has 21 quadratic constraints.
    Presolve time = 0.00 sec. (1.18 ticks)
    Parallel mode: using up to 24 threads for barrier.

    ***NOTE: Found 1 dense columns.

    Number of nonzeros in lower triangle of A*A' = 1215
    Using Approximate Minimum Degree ordering
    Total time for automatic ordering = 0.00 sec. (0.08 ticks)
    Summary statistics for Cholesky factor:
      Threads                   = 24
      Rows in Factor            = 122
      Integer space required    = 152
      Total non-zeros in factor = 1417
      Total FP ops to factor    = 21867
     Itn      Primal Obj        Dual Obj  Prim Inf Upper Inf  Dual Inf Inf Ratio
       0   1.8284271e+00  -1.0000000e+00  2.88e+01  0.00e+00  2.03e+04  1.00e+00
       1  -1.0996434e+03  -1.0609553e+03  2.88e+01  0.00e+00  2.03e+04  2.37e-02
       2  -1.3267594e+03  -1.2855588e+03  2.70e+01  0.00e+00  1.90e+04  2.25e-02
       3  -3.6610576e+03  -3.5510541e+03  2.47e+01  0.00e+00  1.75e+04  8.85e-03
       4  -3.2860749e+03  -3.2045073e+03  2.27e+01  0.00e+00  1.60e+04  1.19e-02
       5  -3.6108033e+03  -3.5908843e+03  1.99e+01  0.00e+00  1.40e+04  4.79e-02
       6  -4.0855344e+03  -4.0720422e+03  7.07e+00  0.00e+00  4.99e+03  7.08e-02
       7  -3.5870533e+03  -3.5789832e+03  4.76e+00  0.00e+00  3.36e+03  1.19e-01
       8  -3.9678688e+03  -3.9657011e+03  2.56e+00  0.00e+00  1.81e+03  4.51e-01
       9  -4.0475876e+03  -4.0473012e+03  3.63e-01  0.00e+00  2.56e+02  3.40e+00
      10  -4.0496137e+03  -4.0495334e+03  5.82e-02  0.00e+00  4.11e+01  1.21e+01
      11  -4.0524217e+03  -4.0524160e+03  1.61e-02  0.00e+00  1.14e+01  1.71e+02
      12  -4.0525941e+03  -4.0525938e+03  1.07e-03  0.00e+00  7.58e-01  3.60e+03
    Elapsed time is 0.035335 seconds.
    Valid solution found
    Time taken 0.030159, 0
    Error: 6.767423
     


    #CPLEXOptimizers
    #DecisionOptimization