[Python] Scipy returns error when given an SHGO optimization problem

Discussão em 'Python' iniciado por Stack, Novembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    Following the paragraph "Global optimization" in this page, I run the following code

    from scipy import optimize
    from math import log

    bounds = [(0, 0, 0, 0), (1, 1, 1, 1)]

    def some_function(u_1, w_1, u_2, w_2):
    return log(1+u_1)/(1+w_1) + log(1+u_2)/(1+w_2)

    optimize.shgo(some_function, bounds)


    I get the following error:

    Traceback (most recent call last):
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo_lib/_complex.py", line 499, in refine
    next(self.rls)
    StopIteration

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/home/marc/Documents/virer/OptimizationWithConstraints.py", line 25, in <module>
    optimize.shgo(some_function, bounds)
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo.py", line 455, in shgo
    shc.iterate_all()
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo.py", line 836, in iterate_all
    self.iterate()
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo.py", line 1009, in iterate
    self.iterate_complex()
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo.py", line 1033, in iterate_hypercube
    self.HC.refine(self.n)
    File "/home/marc/PythonEnv/lib/python3.12/site-packages/scipy/optimize/_shgo_lib/_complex.py", line 501, in refine
    vp = self.triangulated_vectors[0]
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^
    IndexError: list index out of range


    Have I done something wrong?

    Continue reading...

Compartilhe esta Página