# Why the following code is not working properly?

I am trying to implement the convex optimization problem in the link:

http://cvxopt.org/examples/mlbook/mcsvm.html#equation-multiclass_svm

As I understand the last condition 1m means identity matrix. May I ask if the following code in CVX (matlab is fine)

``````E=zeros(NumClasses*TrainSample,NumClasses);
vecOnes=ones(L,1);
E(1:L,1)=vecOnes;
E(L+1:2*L,2)=vecOnes;
E(2*L+1:3*L,3)=vecOnes;
E(3*L+1:4*L,4)=vecOnes;
Q=TrainFeat'*TrainFeat;
gamma=.5
cvx_begin
variable U(NumClasses*TrainSample,NumClasses)
maximize(-1/2*(U(:,1)'*Q*U(:,1)+U(:,2)'*Q*U(:,2)+U(:,3)'*Q*U(:,3)+U(:,4)'*Q*U(:,4))+(E(:,1)'*U(:,1)+E(:,2)'*U(:,2)+E(:,3)'*U(:,3)+E(:,4)'*U(:,4)))
subject to
U-gamma*E<=0
U*eye(4)==0
cvx_end
``````

In the above Q is kernel defined as X’X where X is the data matrix. Is the last condition Ueye(4)==0 necessary?
I shall truly appreciate few words form you.
Best Regards

I haven’t checked your code, and don’t know whether what you’ve done with E is correct.

But I believe 1_m should be a vector of ones. So `U*1_m == 0` is constraining each row of U to sum to zero. You can accomplish the same thing using sum instead of 1_m.

For the objective, you should just write it as it’s written out in matrix form
`maximize(-1/2*trace(U'*Q*U)+trace(E'*U))`

It looks like you’re writing everything, including filling in E, manually, based on particular dimensions, which would require modification if those dimensions change. You already initialize E based on particular dimensions, so you should fill in the ones in a way which is in terms of those dimensions (and L), and will not require modification when the dimensions change.