qcml icon indicating copy to clipboard operation
qcml copied to clipboard

How to represent the frobenius norm in QCML?

Open dgrnbrg opened this issue 8 years ago • 2 comments

I'd like to represent this CVX model in QCML:

n = size(A,1);
cvx_begin sdp
    variable B(n,n)
    minimize(norm(A-B,'Fro'))
    subject to
        B+B' >= 0
cvx_end

But I'm not sure what the best way to express the norm(A-B,'Fro') component is.

dgrnbrg avatar May 22 '17 19:05 dgrnbrg

I believe I ported the model to QCML correctly, however, I am getting an error in the generated code. The QCML model I'm using is:

dimensions n
variable B(n,n)
parameter A(n,n)
minimize norm2(A - B)
subject to
  B + B' >= 0

but when I try to compile the generated C code, I get this error:

psd.c:81:81: error: assigning to 'double' from incompatible type 'qc_matrix' (aka 'struct coo')
    for(i = 0; i < dims->n * dims->n; ++i) data->h[i + (1 + dims->n * dims->n)] = params->A[i];
                                                                                ^ ~~~~~~~~~~~~
psd.c:119:13: warning: incompatible pointer types assigning to 'qc_matrix *' (aka 'struct coo *') from 'const double *' [-Wincompatible-pointer-types]
    vars->B = x + 0;  /* length dims->n * dims->n */
            ^ ~~~~~
1 warning and 1 error generated.
make: *** [psd.o] Error 1

It looks like the issue is that the A and B matrices are of type qc_matrix * in the generated code, but the way I've declared them is making the system think that they're scalar, possibly? Could you let me know if I'm expressing something in an obviously incorrect way?

dgrnbrg avatar May 31 '17 00:05 dgrnbrg

You can try sum(sum(square(A-B))).

IIRC, this might not work, since I wasn't planning on supporting matrix variables.

In this case, you can (possibly) work around it by vectorizing the matrix externally. Let me know... On Tue, May 30, 2017 at 5:17 PM David Greenberg [email protected] wrote:

I believe I ported the model to QCML correctly, however, I am getting an error in the generated code. The QCML model I'm using is:

dimensions n variable B(n,n) parameter A(n,n) minimize norm2(A - B) subject to B + B' >= 0

but when I try to compile the generated C code, I get this error:

psd.c:81:81: error: assigning to 'double' from incompatible type 'qc_matrix' (aka 'struct coo') for(i = 0; i < dims->n * dims->n; ++i) data->h[i + (1 + dims->n * dims->n)] = params->A[i]; ^ ~~~~~~~~~~~~ psd.c:119:13: warning: incompatible pointer types assigning to 'qc_matrix *' (aka 'struct coo *') from 'const double ' [-Wincompatible-pointer-types] vars->B = x + 0; / length dims->n * dims->n */ ^ ~~~~~ 1 warning and 1 error generated. make: *** [psd.o] Error 1

It looks like the issue is that the A and B matrices are of type qc_matrix

  • in the generated code, but the way I've declared them is making the system think that they're scalar, possibly? Could you let me know if I'm expressing something in an obviously incorrect way?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/cvxgrp/qcml/issues/55#issuecomment-305045268, or mute the thread https://github.com/notifications/unsubscribe-auth/AADN0dWv4VA9Jn4GXQbjw41MhvdwrbTpks5r_LGagaJpZM4NiyZX .

echu avatar May 31 '17 02:05 echu