CVX Objective function


(Bilal Majeed) #1

How can I write the following CVX objcetive function in a similar way i write in GAMS.

image


(Michael C. Grant) #2

Are d_i and d_j scalars, or vectors? The use of the transpose d_i^T suggests a vector, but the use of d_i^2 and d_j^2 suggest scalars. I’m guessing the former, in which case isn’t this just \sum_{i,j} S_{ij} \|d_i-d_j\|_2^2?


(Bilal Majeed) #3

My original objective function is image


(Bilal Majeed) #4

Am not sure if this formulation represents the same thing image


(Michael C. Grant) #5

The expression (d_i-d_j)^2 is ill-posed if d_i,d_j are vectors. What does that even mean? I think you mean \|d_i-d_j\|_2^2, (and no, not \|d_i-d_j\|_2.)


(Bilal Majeed) #6

Yeah that’s what I meant.

So how do i write this in cvx image


(Bilal Majeed) #7

Also, I was formulating the problem with image, image scalar values.


(Michael C. Grant) #8

Suppose you have a matrix D whose columns represent the vectors d_i, and a matrix S whose values correspond to S_{ij}. Here’s one way to do it:

obj = 0
for i = 1:size(S,1)
    for j = 1:size(S,2)
        obj = obj + sum_square(D(:i)-D(:,j)) * S(i,j)
    end
end
minimize(obj)

This is certainly the easiest way, but depending on the number of vectors, it might be a little slow. There are some vectorization tricks to play here once you confirm this is the right general idea.