Stefan-Endres / shgo

Simplicial Homology Global Optimization
https://stefan-endres.github.io/shgo
MIT License
44 stars 12 forks source link

Incorporate the FunctionCache class #8

Closed Stefan-Endres closed 3 years ago

Stefan-Endres commented 6 years ago

Incorporate the FunctionCache class from pointclasses.py into the main code. While the global routine will not evaluate the same value twice (and it is very unlikely that a non-deterministic local minimization would), it will allow us to reduce some complexity in the random sampling code to make it more similar to the simplicial sampling.

alchemyst commented 6 years ago

Why not just use functools.lru_cache?

Stefan-Endres commented 6 years ago

I wanted to discuss this at some point.

The algorithm ensures convergence (and other properties) for non-continuous functions (even large domains of the search space the objective function does not necessarily need to be defined as long as there exists an arbitrarily small continuous subdomain) as long as the 'simplicial' sampling method is used.

The proof depends on defining points of discontinuity as being mapped to infinity. For this I use numpy.inf for any constraint violations.

Ideally I would like to convert any non-float value outputs such as None values and other objects from the objective function to numpy.inf.

However, other problems can arise such as division by zero stopping the algorithm.

So our options are:

  1. Capture any exceptions that are related to mathematical errors. Add a caveat to the documentation that the user loses the errors (perhaps store them in a log?). We can add this exception handling to the cache in a similar way to the construction of the complex in triangulation.py.
  2. Require the users to define their functions so that it outputs numpy.inf at the discontinuities.

The first option appears more robust, however, the second option allows more control.

Stefan-Endres commented 3 years ago

Implemented 1 with cc51c2348f239b6378ac00e5768832f51c66fe61.