You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try the following example and check for dpp True:
# Generate data for optimal advertising problem.
import numpy as np
np.random.seed(1)
m = 5
n = 24
SCALE = 10000
B = np.random.lognormal(mean=8, size=(m,1)) + 10000
B = 1000*np.round(B/1000)
P_ad = np.random.uniform(size=(m,1))
P_time = np.random.uniform(size=(1,n))
P = P_ad.dot(P_time)
T = np.sin(np.linspace(-2*np.pi/2,2*np.pi -2*np.pi/2,n))*SCALE
T += -np.min(T) + SCALE
c = np.random.uniform(size=(m,))
c *= 0.6*T.sum()/c.sum()
c = 1000*np.round(c/1000)
R = np.array([np.random.lognormal(c.min()/c[i]) for i in range(m)])
import cvxpy as cp
D = cp.Variable((m,n))
Si = [cp.minimum(R[i]*P[i,:]@D[i,:].T, B[i]) for i in range(m)]
prob = cp.Problem(cp.Maximize(cp.sum(Si)),
[D >= 0,
D.T @ np.ones(m) <= T,
D @ np.ones(n) >= c])
prob.is_dpp()
Prints True
... But when I convert it to use parameters and variables like this:
# Problem scale
m = 5
n = 24
SCALE = 10000
B = cp.Parameter((m,1))
P = cp.Parameter((m,n))
T = cp.Parameter((n,))
c = cp.Parameter((m,))
R = cp.Parameter((m,))
D = cp.Variable((m,n))
Si = [cp.minimum(R[i]*P[i,:]@D[i,:].T, B[i]) for i in range(m)]
objective = cp.Maximize(cp.sum(Si))
constraints = [D >= 0,
D.T @ np.ones(m) <= T,
D @ np.ones(n) >= c]
problem = cp.Problem(objective, constraints)
problem.is_dpp()
Prints False, so I can't build a layer with it.
The text was updated successfully, but these errors were encountered:
In the first example, there are no cp parameters at all. Only one variable and everything else is constant.
In the second example, you defined some cp parameters, your objective is definitely not DPP. Try to check the documents and use slack variables.
When I try the following example and check for dpp True:
Prints True
... But when I convert it to use parameters and variables like this:
Prints False, so I can't build a layer with it.
The text was updated successfully, but these errors were encountered: