-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
Hello everybody. First of all, thank you very much for this incredible tool. I'm trying to solve a problem that seems to be very difficult: even in very little instances the solvers struggle to find a solution (and the give a warning saying that is inaccurate). Now, because of the nature of the problem, the solution might be very close to the zero vector. That's why I tried to give the solver a hand and use warm_start having instantiated previously the zero vector to the variables of the problem. However, the solver gives a solution that is way worse than the one initialized with warm start.
To Reproduce
import cvxpy as cp
import numpy as np
C_sound = 0.43633231299858233
G_sound = np.asarray([[0.4156921938165309 - 0.23999999999999963j, 0.29692299558323665 + 0.1714285714285704j],
[-0.665569940421644 + 0.009673545578146104j, 0.14151808351117373 + 0.21848875925703226j],
[-4.656133759306296e-16 - 0.8j, 2.287657973439295e-16 + 0.26666666666666666j],
[-0.665569940421644 + 0.009673545578146104j, 0.14151808351117298 + 0.21848875925703276j],
[-2.078460969082654 - 1.1999999999999944j, -0.18895099718933187 + 0.10909090909090943j]])
u0_sound = np.asarray([0.009906430846671255 - 0.0010830386455277078j, 0.008187941456002363 + 0.00178927838865346j,
0.005509237543204766 - 0.007985358398429381j, -0.006763413493560299 - 0.009293348678396056j,
-0.007994080650317923 - 0.004615384615384564j])
T_w_sound = np.asarray(
[285855.5924994196, 383076.31134604354, 299134.1010521829, 224575.94674223074, 325376.06626492966])
C_silence = 43633231.29985823
G_silence = np.asarray([[-0.18895099718933187 + 0.10909090909090943j, -2.078460969082654 - 1.1999999999999944j],
[0.14151808351117373 + 0.21848875925703226j, -0.6655699404216439 + 0.009673545578147284j],
[2.287657973439295e-16 + 0.26666666666666666j, -4.656133759306296e-16 - 0.8j],
[0.14151808351117373 + 0.21848875925703226j, -0.6655699404216441 + 0.009673545578144925j],
[0.29692299558323665 + 0.1714285714285704j, 0.4156921938165309 - 0.23999999999999963j]])
u0_silence = [0, 0, 0, 0, 0]
T_w_silence = np.asarray(
[350427711.1795277, 350427711.1795277, 350427711.1795277, 350427711.1795277, 350427711.1795277])
print(f'T_w_sound.shape: {T_w_sound.shape}')
print(f'T_w_silence.shape: {T_w_silence.shape}')
M = cp.Variable(2, complex=True)
u_sound = G_sound @ M
u_silence = G_silence @ M
T_sound = cp.multiply(cp.square(cp.abs(u_sound - u0_sound)), T_w_sound)
T_silence = cp.multiply(cp.square(cp.abs(u_silence - u0_silence)), T_w_silence)
print(f'u_sound.shape: {u_sound.shape}')
print(f'u_silence.shape: {u_silence.shape}')
print(f'T_sound.shape: {T_sound.shape}')
print(f'T_silence.shape: {T_silence.shape}\n')
error_sound = C_sound * cp.sum(cp.pos(T_sound - 1))
error_silence = C_silence * cp.sum(cp.pos(T_silence - 1))
p_objective = cp.Minimize(error_sound + error_silence)
p_constraints = []
p_problem = cp.Problem(p_objective, p_constraints)
M.value = np.zeros(2)
optimum = p_problem.solve(solver=cp.ECOS, warm_start=True)
u_sound_sol = G_sound @ M.value
u_silence_sol = G_silence @ M.value
error_sound = C_sound * np.sum(np.maximum(np.square(np.abs(u_sound_sol - u0_sound)) * T_w_sound - 1, 0))
error_silence = C_silence * np.sum(np.maximum(np.square(np.abs(u_silence_sol - u0_silence)) * T_w_silence - 1, 0))
error_sound_zero_solution = C_sound * np.sum(np.maximum(np.square(np.abs(u0_sound)) * T_w_sound - 1, 0))
error_silence_zero_solution = C_silence * np.sum(np.maximum(np.square(np.abs(u0_silence)) * T_w_silence - 1, 0))
print(f'Error sound (cvxpy solution): {error_sound}')
print(f'Error silence (cvxpy solution): {error_silence}')
print(f'Error total (cvxpy solution): {error_sound + error_silence}\n')
print(f'Error sound (zero solution): {error_sound_zero_solution}')
print(f'Error silence (zero solution): {error_silence_zero_solution}')
print(f'Error total (zero solution): {error_sound_zero_solution + error_silence_zero_solution}')
Expected behavior
The optimum of the solution should be at least better than the cost of the zero vector.
Output
cvxpy solution: [3.23884193e-03+1.17611822e-03j, 2.05843534e-05+3.76955289e-05j]
Error sound (cvxpy solution): 42.66145923187379
Error silence (cvxpy solution): 65501359411.383835
Error total (cvxpy solution): 65501359454.045296
Error sound (zero solution): 59.27316616477894
Error silence (zero solution): 0.0
Error total (zero solution): 59.27316616477894
Version
- OS: 10.15.6
- CVXPY Version: 1.1.12
Maybe the warm_start needs to be implementated in an other way?
Thank you in advance,
Pedro Izquierdo L.