About optimizing parameter settings and the reasons for solution failure
AnsweredI have just started to learn optimization knowledge and sincerely request help.
If there is a complex matrix A,2 * 2 dimensions. I want to find two matrix, B1 and B2, to satisfy the object function, the Minimize the frobenius norm of A and B1 * B2 .
How to set optimization variables?
I have set the optimization variables 16 * 1 dimensions X. And then assign X to the corresponding matrix B1, B2. B1 = [x0 + x1*i, x2 + x3 * i;....]
Is the above setting method correct?
Sincerely request your help.

-
Hi Cheng Chi,
We may need clarification on what your question is.
This seems to be a programming question, if you were using gurobipy I suspect you would have an answer by now, but the tag suggests you are using AMPL.
Are you asking us how to write the code using AMPL?
- Riley
0 -
Hi, Riley
Thank you for your reply.
If I want to solve this nonlinear optimization problem:
If there is a complex matrix A,2 * 2 dimensions. I want to find two matrix, B1 and B2, to satisfy the object function, the Minimize the frobenius norm of A and B1 * B2.
How to set the optimize variables.
And could the gurobi solve this type of problem?
0 -
Hi Cheng Chi,
Gurobi can solve this problem, and if using our gurobipy matrix API then the formulation is relatively concise. However, since variables in solver must be real numbers we need to separate these complex matrices into real and imaginary parts, i.e.
\[\begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} = \begin{bmatrix} Re(b_{11}) & Re(b_{12}) \\ Re(b_{21}) & Re(b_{22}) \end{bmatrix} + \begin{bmatrix} Im(b_{11}) & Im(b_{12}) \\ Im(b_{21}) & Im(b_{22}) \end{bmatrix}i\]
Then, a multiplication between two complex matrices would look like this, with the end result being factored into real and imaginary parts:
\[\begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} \cdot \begin{bmatrix} c_{11} & c_{12} \\ c_{21} & c_{22} \end{bmatrix} = \left( \begin{bmatrix} Re(b_{11}) & Re(b_{12}) \\ Re(b_{21}) & Re(b_{22}) \end{bmatrix} + \begin{bmatrix} Im(b_{11}) & Im(b_{12}) \\ Im(b_{21}) & Im(b_{22}) \end{bmatrix}i \right) \cdot \left( \begin{bmatrix} Re(c_{11}) & Re(c_{12}) \\ Re(c_{21}) & Re(c_{22}) \end{bmatrix} + \begin{bmatrix} Im(c_{11}) & Im(c_{12}) \\ Im(c_{21}) & Im(c_{22}) \end{bmatrix}i \right) \\\]
\[= \left( \begin{bmatrix} Re(b_{11}) & Re(b_{12}) \\ Re(b_{21}) & Re(b_{22}) \end{bmatrix} \cdot \begin{bmatrix} Re(c_{11}) & Re(c_{12}) \\ Re(c_{21}) & Re(c_{22}) \end{bmatrix} - \begin{bmatrix} Im(b_{11}) & Im(b_{12}) \\ Im(b_{21}) & Im(b_{22}) \end{bmatrix} \cdot \begin{bmatrix} Im(c_{11}) & Im(c_{12}) \\ Im(c_{21}) & Im(c_{22}) \end{bmatrix}\right) \\
+ \left( \begin{bmatrix} Re(b_{11}) & Re(b_{12}) \\ Re(b_{21}) & Re(b_{22}) \end{bmatrix} \cdot \begin{bmatrix} Im(c_{11}) & Im(c_{12}) \\ Im(c_{21}) & Im(c_{22}) \end{bmatrix} + \begin{bmatrix} Im(b_{11}) & Im(b_{12}) \\ Im(b_{21}) & Im(b_{22}) \end{bmatrix} \cdot \begin{bmatrix} Re(c_{11}) & Re(c_{12}) \\ Re(c_{21}) & Re(c_{22}) \end{bmatrix}\right)i\]You can use this formula to create the expression you are taking the norm of (and introduce some auxiliary variables to simplify). Note that it is enough to use the square of the norm as the objective, since any values that minimize the square, must also minimize the norm.
The code in gurobipy would look like this:
import gurobipy as gp
import numpy as np
ReA = np.array([[1,4],[5,2]])
ImA = np.array([[0,3],[-4,0]])
m = gp.Model()
ReB1 = m.addMVar((2,2), lb=-float("inf"))
ImB1 = m.addMVar((2,2), lb=-float("inf"))
ReB2 = m.addMVar((2,2), lb=-float("inf"))
ImB2 = m.addMVar((2,2), lb=-float("inf"))
# define auxiliary matrix variables for expression inside norm operator
ReAux = m.addMVar((2,2), lb=-float("inf"))
ImAux = m.addMVar((2,2), lb=-float("inf"))
m.addConstr(ReAux == ReA - ReB1@ReB2 + ImB1@ImB2)
m.addConstr(ImAux == ImA - ReB1@ImB2 - ImB1@ReB2)
# set objective to square of norm (the solution will be valid for original objective)
m.setObjective(gp.quicksum(ReAux[i][j]**2 + ImAux[i][j]**2 for i in (0,1) for j in (0,1)))
m.optimize()- Riley
0 -
Hi, Riley
Thank you for your reply.
Your reply gives me great inspiration. I will have a test later.
0
Please sign in to leave a comment.
Comments
4 comments