polyopt icon indicating copy to clipboard operation
polyopt copied to clipboard

Solving problems with no constraints

Open andreadelprete opened this issue 4 years ago • 2 comments

Hi,

first of all, thanks for this package, it is really what I was looking for! I'm trying to use it to optimize a simple 1d polynomial, with no constraints, but I'm getting this error:

Traceback (most recent call last):
  File "/home/student/repos/polyopt/demoPOPSolver.py", line 27, in <module>
    POP = polyopt.POPSolver(f, g, d)
  File "/home/student/repos/polyopt/polyopt/POPSolver.py", line 37, in __init__
    if max(gDegsHalf) > d:
ValueError: max() arg is an empty sequence

I guess the solver is not done for the unconstrained case. I was able to get around this by adding a dummy constraint (x+100>=0). Here is the code I'm running now:

f = {(0,): 5, (1,): -2, (2,): 1}
g = [{(0,): 1e2, (1,): 1,}] # constraint function x + 1e2 >=0
d = 2
POP = polyopt.POPSolver(f, g, d)
y0 = POP.getFeasiblePoint([array([[1]]), array([[2]]), array([[-1]]), array([[-2]])])
POP.setPrintOutput(False)
x = POP.solve(y0)

However, I still get an error:

    x = POP.solve(y0) #solve the problem
  File "/home/student/repos/polyopt/polyopt/POPSolver.py", line 80, in solve
    y = self.SDP.solve(startPoint, self.SDP.dampedNewton)
  File "/home/student/repos/polyopt/polyopt/SDPSolver.py", line 188, in solve
    x0 = method(start)
  File "/home/student/repos/polyopt/polyopt/SDPSolver.py", line 314, in dampedNewton
    FdLN = Utils.LocalNormA(Fd, Fdd)
  File "/home/student/repos/polyopt/polyopt/utils.py", line 29, in LocalNormA
    return sqrt(dot((solve(hessian, u)).T, u))[0,0]
  File "<__array_function__ internals>", line 6, in solve
  File "/home/student/.local/lib/python3.5/site-packages/numpy/linalg/linalg.py", line 399, in solve
    r = gufunc(a, b, signature=signature, extobj=extobj)
  File "/home/student/.local/lib/python3.5/site-packages/numpy/linalg/linalg.py", line 97, in _raise_linalgerror_singular
    raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix

This time I'm not sure what the problem is. Any suggestion? Moreover, would it be simple to modify the code to handle unconstrained minimization?

andreadelprete avatar Mar 26 '20 21:03 andreadelprete