CVXPY 中的范数约束

计算科学 优化 Python 凸优化 简历
2021-12-05 15:07:05

我正在尝试小规模实现https://arxiv.org/abs/1211.5608中概述的算法。我有一个线性运算符A定义为

trace(Al(hm))
在哪里
Al=b^lc^l
, 在哪里b^lc^l是不同矩阵的列和向量。

我用它作为解决问题的约束

minX
服从
y^=A(X)

在 CVXPY 中,我做了约束:

constraints = [cp.trace(np.transpose((B_hat_star[:,col][:,np.newaxis]*np.sqrt(L)*C_hat[col,:])) @ X) == y_hat[col] for col in range(L)]

这有效。但是,现在我试图做出约束:我不确定如何对使用 for 循环(如上)定义的矩阵强制执行范数约束。我试过做y^A(X)2δ

constraints = [cp.norm([y_hat[col] - cp.trace(np.transpose((B_hat_star[:,col][:,np.newaxis]*np.sqrt(L)*C_hat[col,:])) @ X) for col in range(L)], 2) <= delta],但我收到一条错误消息ValueError: setting an array element with a sequence.

1个回答

CVXPY 的标准原子不接受原始 Python 列表作为参数;你需要给它传递一个 CVXPY 表达式。使用hstack atom将标量列表堆叠成一个向量,如下所示:

constraints = [cp.norm(
    cp.hstack([
        y_hat[col] - cp.trace(
            np.transpose((B_hat_star[:,col][:,np.newaxis]*np.sqrt(L)*C_hat[col,:])) @ X)
        for col in range(L)
    ]), 2) <= delta]