简体   繁体   中英

How to invert a matrix of variables in cvxpy?

How do I invert a matrix of variables in cvxpy?

I have a matrix of problem variables defined as follows:

import cvxpy as cp
A = cp.Variable(2,2)

and I want to solve a program with an objective function involving the inverse of this matrix. I have tried almost every method I could possibly think of (including manually defining the inverse matrix), but nothing seems to work.

The full code for my problem is:

A = cp.Variable((2,2)) # matrix A is 2X2
c = cp.Variable(2) # center of 2d ellipsoid

constraints = [A >> 0]
constraints += [cp.pnorm(cp.matmul(A, v[i] - cp.matmul(A,c)), p=2) <= np.array([1,1]) for i in range(10)]

# this is where I'm stuck. Using np.linalg.inv doesn't work.
# I also can't seem to calculate this inverse manually 
obj_fn = cp.log_det(np.linalg.inv(A))

prob = cp.Problem(cp.Minimize(obj_fn), constraints)
prob.solve(solver='CVXOPT')

I don't know how to invert a matrix in cvxpy, but for the specific code you have, you can use the fact that:

log det A^{-1} = - log det A

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM