Due to the lack of knowledge of CVXPY, I have a problem with reconciling a simple optimization problem's results when using different versions of it.
When I use CVXPY with version 0.4.5 I wrote my problem as:
import numpy as np
from cvxpy import *
n = 5
np.random.seed(123)
g1 = np.random.rand(2*n, 1)
H1 = np.eye(2*n)
w = Variable(2*n)
gamma = Parameter(sign="positive")
ret = -g1.T*w
risk = quad_form(w, H1)
prob = Problem(Maximize(ret - gamma*risk),
[w >= 0])
gamma.value = 0.5
prob.solve()
res = w.value
and the res equals to:
res = [[ 2.86653834e-12],
[ 2.47912037e-11],
[ 3.73027873e-11],
[ 7.13532730e-12],
[ 2.31133274e-12],
[ 1.27710498e-11],
[ -2.50944234e-12],
[ 3.15803733e-12],
[ 9.90353521e-12],
[ 1.46452182e-11]]
However, When I use CVXPY with version 1.0.8, I type almost the same codes as follows:
n = 5
np.random.seed(123)
g1 = np.random.rand(2*n, 1)
H1 = np.eye(2*n)
w = Variable(2*n)
gamma = Parameter(nonneg=True)
ret = -g1.T*w
risk = quad_form(w, H1)
prob = Problem(Maximize(ret - gamma*risk),
[w >= 0])
gamma.value = 0.5
prob.solve()
res = w.value
The result is:
(Pdb) res
array([6.66098380e-25, 2.73633363e-25, 2.16955532e-25, 5.27275998e-25,
6.88070573e-25, 4.04646723e-25, 9.37904145e-25, 6.54954091e-25,
4.60002892e-25, 3.75018828e-25])
The only difference I made when using version 1.0.8 of CVXPY is that I use attribute 'nonneg=True' instead of 'sign=positive' which I think they are essentially the same thing. Can someone help me out here? What are the possible reasons that the results are so different?
Many thanks