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

Solving problems with no constraints #2

Open
andreadelprete opened this issue Mar 26, 2020 · 2 comments
Open

Solving problems with no constraints #2

andreadelprete opened this issue Mar 26, 2020 · 2 comments

Comments

@andreadelprete
Copy link

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
Copy link
Author

Some additional info. I've tried reducing the degree of the relaxation d to 1, but nothing changed.
If I enable the output of the solver I get a lot of stuff printed, which ends with this:

k = 1035
y = [[4.27207552e+080]
 [4.51955469e+161]]
EIG[0] = [1.00000000e+000 4.51955469e+161]
EIG[1] = [4.27207552e+80]

k = 1036
y = [[4.68619274e+080]
 [5.70445470e+161]]
EIG[0] = [1.0000000e+000 5.7044547e+161]
EIG[1] = [4.68619274e+80]

k = 1037
y = [[5.60596174e+080]
 [8.12844091e+161]]

@andreadelprete
Copy link
Author

Problem solved. Reviewing the theory I've seen that the feasible set needs to be bounded, so I added the constraint 1e4 - x^2>=0 to my problem and now the solver gives me a solution. However, very often it's not a good solution. For instance, for a polynomial with these coefficients:

a [ 0.81115 -0.45637 -0.3268   0.52828  0.24135]

I get the following solution:

Global minimum     f(x)=[42.68568] at x=[21921.42697]

While using BFGS and another scipy solver to optimize the same polynomial I get

Scalar-opt minimum f(x)=0.01851134671778265 at x=[-1.86858]
BFGS minimum        f(x)=0.564046131707772 at x=[0.62908]

I've tried playing with the degree of the relaxation, trying 1, 2, and 3, but I always get this kind of problems. Any suggestion?

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

1 participant