Crash with max() function

Hi all!

I am trying to run the following optimization loop between two matrices s_rx1 and s_rx2 of size [33x72]. So in the code t_size = 72 and f_size = 33.

% Cost matrix 
C = pdist2(t_range(:), t_range(:), 'euclidean').^2;
 
% Optimization loop 
cvx_begin 

    variable M(t_size, t_size, f_size) 
    obj = 0; 
    final_objective = 0;
    expression sum_diag(2*T-1,F)
    penalty = 0; 

    for f = 1:f_size
          Mf= M(:, :, f);
          obj = obj + sum(C(:) .* Mf(:));

        for k = 1:(2*T -1 ) 
            sum_diag(k,f) = sum(diag(Mf, k - T));   
        end 
    end

    max_diag = max(sum_diag,[],2);
    penalty = sum(max_diag);

    final_objective = obj + penalty; 

    minimize(final_objective)
    subject to 

    M >= 0 ; 
    for f = 1:f_size
        sum(M(:, :, f), 2)'  == s_rx1(f, :);
        sum(M(:, :, f), 1)  == s_rx2(f, :);
    end

cvx_end 

This problem runs fine and is solved in less than a minute (using Mosek). However, when I try to use the max() function instead of sum() in the inner loop segment:

          for k = 1:(2*T -1 ) 
              sum_diag(k,f) = max(diag(Mf, k - T));   % instead of sum(diag(Mf, k - T));
          end 

cvx starts and the Matlab application crashes.

Do you have any suggestions on how to implement this problem more efficiently or have an alternative for a cvx-friendly function?

A way to avoid looping over the diagonals in the second loop would be to use the matlab function spdiags(), but that is not cvx-friendly either.

Thank you !

LF

Please show the output of
cvx_version

and show all details of the crash.

Despite the statement “A later version of CVX will eliminate the need for this by allowing the use of the SPDIAGS function in side models.” in Minimal phase spectral factorization , which perhaps was made ca. 2020, spdiags is not supported by CVX 2.2.2 (nor previous versions).

This is the output of cvx_version:

cvx_version 

---------------------------------------------------------------------------
CVX: Software for Disciplined Convex Programming       (c)2014 CVX Research
Version 2.2, Build   9 (a0a77590)                  Tue Apr 23 19:28:09 2024
---------------------------------------------------------------------------
Installation info:
    Path: /Users/fabianl1/MATLAB/cvx
    MATLAB version: 24.2 (R2024b)
    OS: Mac OS X aarch64 version 15.2
    Java version: 11.0.25
Verfying CVX directory contents:
    No missing files.
Preferences: 
    Path: /Users/fabianl1/Library/Application Support/MathWorks/MATLAB/cvx_prefs.mat
---------------------------------------------------------------------------

Before crashing this is what cvx outputs:

Calling SDPT3 4.0: 351549 variables, 175868 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 175868
 dim. of linear var  = 346797
 dim. of free   var  = 4752 *** convert ublk to lblk>> 

then matlab stops working.

For comparison, this is what cvx outputs with the sum() function, before printing the solvers steps.

Calling SDPT3 4.0: 175934 variables, 9471 equality constraints
------------------------------------------------------------

 num. of constraints = 9471
 dim. of linear var  = 175791
 dim. of free   var  = 143 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
    NT      1      0.000   1        0    

You could try another solver, such as Mosek or SeDuMi. You could also try CXV 2.2 (even though, perhaps 2.2.2 should be better, especially for Mac M1 native).

Have you tried a smaller problem size to see what happens?

Hi,

the process works quite fast using Mosek.

Thanks!