0

I'm trying to solve the problem

d = 0.5 * ||X - \Sigma||_{Frobenius Norm} + 0.01 * ||XX||_{1}, 

where X is a symmetric positive definite matrix, and all the diagnoal element should be 1. XX is same with X except the diagonal matrix is 0. \Sigma is known, I want minimum d with X.

My code is as following:

using Convex
m = 5;
A = randn(m, m); 
x = Semidefinite(5);
xx=x;
xx[diagind(xx)].=0;
obj=vecnorm(A-x,2)+sumabs(xx)*0.01;
pro= minimize(obj, [x >= 0]);
pro.constraints+=[x[diagind(x)].=1];
solve!(pro)

MethodError: no method matching diagind(::Convex.Variable)

I just solve the optimal problem by constrain the diagonal elements in matrix, but it seems diagind function could not work here, How can I solve the problem.

phipsgabler
  • 20,535
  • 4
  • 40
  • 60
Xia.Song
  • 416
  • 3
  • 15
  • Can you add the optimization problem you're trying to solve in mathematical form? – phipsgabler Apr 23 '18 at 06:39
  • d=0.5*||X-\Sigma||_{Frobenius Norm}+0.01*||XX||_{1}, X is a symmetric positive definite matrix, and all the diagnoal element should be 1. XX is same with X except the diagonal matrix is 0. \Sigma is known, I want minimum d with X. – Xia.Song Apr 23 '18 at 07:54
  • Ok, I added that to the question, please check whether that is accurate. – phipsgabler Apr 23 '18 at 08:06
  • Yes, you understand it exactly. – Xia.Song Apr 23 '18 at 08:18
  • Out of interest, what kind of 1-norm is `||XX||_1` if you define it as `sum(abs(XX))`? As far as I remember, the operator (1,1)-norm would be the maximum of column sums, and the Schatten 1-norm the sum of singular values. Am I overlooking something? – phipsgabler Apr 23 '18 at 08:32

1 Answers1

1

I think the following does what you want:

m = 5
Σ = randn(m, m)
X = Semidefinite(m)
XX = X - diagm(diag(X))
obj = 0.5 * vecnorm(X - Σ, 2) + 0.01 * sum(abs(XX))
constraints = [X >= 0, diag(X) == 1]
pro = minimize(obj, constraints)
solve!(pro)

For the types of operations:

  • diag extracts the diagonal of a matrix, as a vector
  • diagm constructs a diagonal matrix out of a vector

So, to have XX be X with zero diagonal, we subtract the diagonal of X from it. And to constrain X having diagonal 1, we compare its diagonal with 1, using ==.

It is a good idea to keep immutable values as far as possible, instead of trying to modify things. I don't know whether Convex even supports that.

phipsgabler
  • 20,535
  • 4
  • 40
  • 60
  • I see that there's also a way to [fix variables](https://convexjl.readthedocs.io/en/latest/advanced.html#fixing-and-freeing-variables), maybe you could use that for ensuring your diagonals' values. But I don't really have any experience with optimization packages. – phipsgabler Apr 23 '18 at 09:09