CVXPY:设置参数为0进行最小化与不设置参数的最小化结果不同

0 投票
0 回答
21 浏览
提问于 2025-04-12 02:12

在使用CVXPY进行目标最小化时,我遇到了两个不同的优化问题。当参数alpha设置为0时,这两个目标应该给出相同的最小化结果。但我得到的结果却不一样。

这两个问题是:

问题1:

w = cp.Variable(shape = m)
 alpha = cp.Parameter(nonneg=True)
 w_sb = w[some_edge_indices]
 w_ob = w[other_edge_indices]
 MKw = MK @ w
 MKsbwb = MK_sb @ w_sb
 MKobwb = MK_ob @ w_ob
 MKswm = MK_some @ w_some
 MKowm = MK_other @ w_other
 alpha.value = alph
 obj1  = cp.sum_squares(MKw)
 obj2 = cp.sum_squares(MKsbwb - MKswm)
 obj3 = cp.sum_squares(MKobwb - MKowm)
 reg = obj2 + obj3
 objective = cp.Minimize(obj1 + alpha*(reg))
 constraints = [AK@w >= np.ones((n,))] 
 prob = cp.Problem(objective, constraints)
 result = prob.solve()

在这里,所有未知的变量都被视为一些给定的矩阵。同时,alpha是一个给定的值。

问题2:

 w = cp.Variable(shape = m)
 MKw = MK @ w
 obj1  = cp.sum_squares(MKw)
 objective = cp.Minimize(obj1)
 constraints = [AK@w >= np.ones((n,))] 
 prob = cp.Problem(objective, constraints)
 result = prob.solve()

在这里,我们可以看到当alpha = 0时,这两个目标应该返回相同的w值。但它们却给出了不同的w值。这可能是什么原因呢?

0 个回答

暂无回答

撰写回答