1

I am having a problem trying to get the optimal value of the f(x,w) matrix by optimizing the entropy of f(x, w)*w/sum(f(x, w)*w).

import cvxpy as cp

fxw = cp.Variable((len(x), len(w)))
pmx = fxw@w/cp.sum(fxw@w*dx)
objective = cp.Minimize(-cp.sum(cp.entr(pmx)))
prob = cp.Problem(objective)
prob.solve()

The w (and x) variable is a simple numpy array (ex. numpy.arange(len(w))).

dx=x[1]-x[0]

The program returns the error:

cvxpy.error.DCPError: Problem does not follow DCP rules. Specifically:
The objective is not DCP. Its following subexpressions are not:
var0 @ [0.08578193 0.26092004 0.43605815 0.61119627 0.78633438 0.96147249
 1.1366106  1.31174871 1.48688682 1.66202493 1.83716304 2.01230115
 2.18743926 2.36257738 2.53771549 2.7128536  2.88799171 3.06312982
 3.23826793 3.41340604 3.58854415 3.76368226 3.93882037 4.11395849
 4.2890966  4.46423471 4.63937282 4.81451093 4.98964904 5.16478715
 5.33992526 5.51506337 5.69020148 5.8653396  6.04047771 6.21561582
 6.39075393 6.56589204 6.74103015 6.91616826 7.09130637 7.26644448
 7.4415826  7.61672071 7.79185882 7.96699693 8.14213504 8.31727315] / Promote(Sum(var0 @ [0.08578193 0.26092004 0.43605815 0.61119627 0.78633438 0.96147249
 1.1366106  1.31174871 1.48688682 1.66202493 1.83716304 2.01230115
 2.18743926 2.36257738 2.53771549 2.7128536  2.88799171 3.06312982
 3.23826793 3.41340604 3.58854415 3.76368226 3.93882037 4.11395849
 4.2890966  4.46423471 4.63937282 4.81451093 4.98964904 5.16478715
 5.33992526 5.51506337 5.69020148 5.8653396  6.04047771 6.21561582
 6.39075393 6.56589204 6.74103015 6.91616826 7.09130637 7.26644448
 7.4415826  7.61672071 7.79185882 7.96699693 8.14213504 8.31727315] @ Promote(0.0651530766959471, (49,)), None, False), (49,))
[Finished in 895ms with exit code 1]

What could be the explanation for this and how can I solve this problem? I would appreciate any form of help.

mate jozsa
  • 13
  • 3
  • The documentation says "expr1*expr2, expr1/expr2, and expr1@expr2 can only be DCP when one of the expressions is constant. The curvature rules above apply. For example, expr1/expr2 is convex when expr1 is concave and expr2 is negative and constant." – Erwin Kalvelagen Nov 15 '21 at 11:47
  • This means that I cant optimize a normalized expression? Like "expr1/sum(expr1)". – mate jozsa Nov 15 '21 at 14:35
  • CVXPY does not support just any NLP model: it only works with certain classes of (convex) problems. – Erwin Kalvelagen Nov 16 '21 at 03:10

0 Answers0