如何在cvxpy中反转变量矩阵?

时间:2019-03-31 02:31:19

标签: python cvxpy cvxopt

如何反转cvxpy中的变量矩阵?

我有一个问题变量矩阵,定义如下:

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

,我想解决一个目标函数涉及该矩阵 inverse 的程序。我尝试了几乎所有可能想到的方法(包括手动定义逆矩阵),但似乎没有任何效果。

我的问题的完整代码是:

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')

1 个答案:

答案 0 :(得分:1)

我不知道如何在cvxpy中转换矩阵,但是对于您拥有的特定代码,您可以使用以下事实:

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