I am using cvx to solve a logistic regression model with constraints. There is always an error because the data matrix (log_mat) is sparse. So how should I solve this problem. The code and the error are attached. Any hints or suggestions will be good. Thanks very much in advance.

cvx_begin
variables a(n,1) b;
minimize(sum(log(1+exp(-ylabel.*(log_mat’*a+b)))));
subject to
ones(1,n)*a == 1;
a >= min_weight;
a <= max_weight;
sum_largest(a,sum_max_num) <= sum_max_weight;
sum_smallest(a,sum_min_num) >= sum_min_weight;
cvx_end

Undefined function ‘sparse’ for input arguments of type ‘single’.

Error in cvx (line 28)
v = class( struct( ‘size_’, size( s ), ‘basis_’, sparse( s(:).’ ), ‘dual_’, ‘’,
‘dof_’, [], ‘slow_’, nnz( isinf( s ) | isnan( s ) ) ~= 0 ), ‘cvx’, cvxobj );

Error in cvx/times (line 141)
y = cvx( y );

Error in cvx/mtimes (line 36)
z = feval( oper, x, y );

Thanks very much for your solution. Now, my program can start running. But may I ask you another question about the memory?

I am solving a problem with a big sparse data matrix (log_mat) with about 1 million observations and 500 variables. This is a real world financial problem. I have tried my best to reduced the size of the problem to this level, my computer still runs out of memory (64GB) for this problem in cvx. So, I want to know if there is an efficient way to model this problem for cvx to solve it considering the sparse data matrix.

I can fit a logistic model with L1 penalty using the matlab built-in function “lassoglm” with this amount of memory. I know this is not exactly what I am doing in CVX because I am adding more constraints in CVX. However, I am thinking it might also be possible for cvx to solve this problem somehow if I can use the memory efficiently.