Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: _compute_once() got an unexpected keyword argument 'dpp' #126

Open
BabaUtah opened this issue Apr 2, 2022 · 1 comment
Open

Comments

@BabaUtah
Copy link

BabaUtah commented Apr 2, 2022

Hi!
While executing the following code given for the poisoning attack :

from cvxpylayers.tensorflow.cvxpylayer import CvxpyLayer
from sklearn.datasets import make_blobs
from sklearn.model_selection import train_test_split


tf.random.set_seed(0)
np.random.seed(0)
n = 2
N = 60
X, y = make_blobs(N, n, centers=np.array([[2, 2], [-2, -2]]), cluster_std=3)
Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, test_size=.5)

Xtrain, Xtest, ytrain, ytest = map(
    tf.constant, [Xtrain, Xtest, ytrain, ytest])
m = Xtrain.shape[0]

lambda1_tf = tf.constant([[0.1]], dtype=tf.float64)
lambda2_tf = tf.constant([[0.1]], dtype=tf.float64)

a = cp.Variable((n, 1))
b = cp.Variable((1, 1))
lambda1 = cp.Parameter((1, 1), nonneg=True)
lambda2 = cp.Parameter((1, 1), nonneg=True)
X = cp.Parameter((m, n))
Y = ytrain.numpy()[:, np.newaxis]

log_likelihood = (1. / m) * cp.sum(
    cp.multiply(Y, X @ a + b) -
    cp.log_sum_exp(cp.hstack([np.zeros((m, 1)), X @ a + b]).T, axis=0,
                   keepdims=True).T
)
regularization = - lambda1 * cp.norm(a, 1) - lambda2 * cp.sum_squares(a)
prob = cp.Problem(cp.Maximize(log_likelihood + regularization))
fit_logreg = CvxpyLayer(prob, [X, lambda1, lambda2], [a, b])

I encounter the following error :

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-46df02174119> in <module>()
     38 regularization = - lambda1 * cp.norm(a, 1) - lambda2 * cp.sum_squares(a)
     39 prob = cp.Problem(cp.Maximize(log_likelihood + regularization))
---> 40 fit_logreg = CvxpyLayer(prob, [X, lambda1, lambda2], [a, b])

/usr/local/lib/python3.7/dist-packages/cvxpylayers/tensorflow/cvxpylayer.py in __init__(self, problem, parameters, variables, gp)
     73                 raise ValueError('Problem must be DPP.')
     74         else:
---> 75             if not problem.is_dcp(dpp=True):
     76                 raise ValueError('Problem must be DPP.')
     77         if set(parameters) != set(problem.parameters()):

TypeError: _compute_once() got an unexpected keyword argument 'dpp'

Any idea to overcome this issue ?

@akshayka
Copy link
Member

akshayka commented Apr 2, 2022

Try upgrading your version of CVXPY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants