2

I am playing with the cvxpy library in order to solve some particular optimisation problem

import cvxpy as cp
import numpy as np

(...)

prob = cp.Problem(
    cp.Minimize(max(M*theta-b)) <= 45,
    [-48 <= theta, theta <= 48])

(Here M and b are certain numpy matrices.)

Interestingly, it screams:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-62-0296c965b1ff> in <module>
      1 prob = cp.Problem(
----> 2     cp.Minimize(max(M*theta-b)) <= 45,
      3     [-10 <= theta, theta <= 10])

~\Anaconda3\lib\site-packages\cvxpy\expressions\expression.py in __gt__(self, other)
    595         """Unsupported.
    596         """
--> 597         raise NotImplementedError("Strict inequalities are not allowed.")

NotImplementedError: Strict inequalities are not allowed.

however, to me, they do not look strict at all...

sascha
  • 32,238
  • 6
  • 68
  • 110
Tomasz Kania
  • 231
  • 2
  • 10

1 Answers1

1

Same reason as in your earlier question (although things like that are hard to analyze).

You need to ask cvxpy for it's max function explicitly. This is always required / recommended.

cp.Minimize(max(M*theta-b))

should be

cp.Minimize(cp.max(M*theta-b))

You basically have to use only functions from cvxpy, except for the following:

The CVXPY function sum sums all the entries in a single expression. The built-in Python sum should be used to add together a list of expressions.

sascha
  • 32,238
  • 6
  • 68
  • 110
  • That's right! However still some funny errors appear ```---> 50 return result.astype(numpy.float64) 51 52 # Return an identity matrix. TypeError: float() argument must be a string or a number, not 'Inequality' ``` – Tomasz Kania Dec 18 '19 at 21:31
  • There i can't help without a reproducible example (yours is missing code). My only very wild guess: did you use `np.matrix`? If, don't! In 2019 (and probably years for now), np.matrix is deprecated / not recommended [see note](https://docs.scipy.org/doc/numpy/reference/generated/numpy.matrix.html). Use a plain 2d numpy-array. – sascha Dec 18 '19 at 21:33
  • Thank you. Would you mind taking a look? https://stackoverflow.com/questions/59400478/typeeror-in-cvxpy-float-argument-must-be-a-string-or-a-number-not-inequalit – Tomasz Kania Dec 18 '19 at 21:55