Finding it hard to model this objective function in CVX

\frac{1}{2}\sum_{t=2}^{T}\sum_{i=1}^{N}\sum_{j=1}^{m(i)}\sum_{k=1,k \neq j}^{m(i)} [(\Delta y_{t}-\Delta\mu_{k,j}^{(i)})^{T}\Sigma ^{-1}(\Delta y_{t}-\Delta \mu_{k,j}^{(i)})]Q(x_{t-1}^{(i)},x_{t}^{(i)})_{j,k}

with respect to Q(x_{t-1}^{(i)},x_{t}^{(i)}) \forall i.

This is not the full objective function I’m trying to minimize. For brevity, I have only shown this term, which I have trouble expressing in CVX.

Q(x_{t-1}^{i},x_{t}^{(i)}) is a square matrix with dimensions m(i) by m(i). I have N such matrices, each being indexed by i. And, in each matrix i, the subscript {j,k} in Q(x_{t-1}^{(i)},x_{t}^{(i)})_{j,k} merely refers to the element of the $j$th row and $k$th column.

As follows is what I thought the problem, when expressed in CVX, should look like:


    variable Q1 (m(1),m(1),T);
    variable Q2 (m(2),m(2),T);
    variable QN (m(N),m(N),T);

    expression e;
    for t=2:T
        for i=1:N
            for j=1:m(i)
                for k=1:m(i)
                        e = e + [(delta_y(t) - delta_mu{i}(j,k))'*sigma_inv*(delta_y(t) - delta_mu{i}(j,k))]*Q (I got stuck here. How do i reference Q1 to QN?)



As you can see, it’s very inelegant. I’m aware that if a given problem could be expressed using norm(), it should be done so. However, due to the k\neq j criterion for the innermost summation and the multiple layers of summation, I thought the only way of expressing this problem in CVX is to incrementally add terms using the “expression” key word and multiple FOR loops.

Also, I have encountered a problem, in that I do not know how to reference all the Q variables (e.g Q1 to QN) unless i manually type them. This means I would need to unroll the loop and it gets really messy. Does CVX support cell variables (e.g “variable Q{1} (m(1),m(1),T)”)? I have browsed through the documentation and it doesn’t seem to support that. Hence, I’m really lost as to what to do.

I apologize for this awfully long post as I would like to make things as clear as possible. Any suggestions on how to approach this problem will be greatly appreciated.

This is very interesting! Here is what I would suggest: compute maxm = max(m), and then declare Q to be a multidimensional array like this:

variable Q(maxm,maxm,T,N)

If you ever want to reference the entire matrix Qi, just do this:


Yes, you will end up creating a lot of unused variables when you do this. But the solver will not ever see them! CVX will just prune them away from the final model, and set them to zero.

Interesting mcg. I thought of that idea, but thought it might lead to extraneous variables which made the problem more difficult to solve.

Even though I know we shouldn’t, let’s say an extraneous variable were introduced and explicitly constrained to zero, but not otherwise used, would CVX pass it on to the solver? If a variable is explicitly constrained to a (specific) numerical value, and appears elsewhere in objective function or constraints, would CVX ever not pass it on to the solver as an optimization variable?

For the most part, CVX will eliminate a lot of variables whose values are explicitly set via equality constraint to a specific value. I can’t say it will always get them all, but the simple cases it will certainly get.

One exception is if the variable has been assigned to a cone via the nonnegative or semidefinite keywords. For instance, in this example,

variable x nonnegative
x == 3

x will probably not be eliminated, but I’m not sure it should be.