CVXPY: Why Norm constraint is not DCP?

84 views Asked by At

cp.norm(weights, 1).is_dcp() returns true. Then why this code works:

import numpy as np
import cvxpy as cp

inputs = np.random.normal(0, 1, (100, 300))
inputs_mean = inputs.mean(axis=1) # shape (features,)
inputs_cov = np.asmatrix(np.cov(inputs)) # shape (features, features)

weights = cp.Variable(len(inputs))
risk = cp.quad_form(weights, inputs_cov)

constraints = [
    # cp.norm(weights, 1) == 1.,
    cp.sum(weights) == 1.,
]
problem = cp.Problem(cp.Minimize(risk), constraints)
problem.solve(verbose=True)
weights.value

But if you use the first constraint (cp.norm) instead of the second, it does not:

DCPError: Problem does not follow DCP rules. Specifically:
The following constraints are not DCP:
norm1(var456) == 1.0 , because the following subexpressions are not:
|--  norm1(var456) == 1.0

Why is it not DCP-compliant? How can I troubleshoot it? Is there an alternative way to solve the problem of requiring the sum of abs weights to be 1? Thanks.

0

There are 0 answers