-
-
Save andyfaff/6dada7148fead6af3e781122dcfaf516 to your computer and use it in GitHub Desktop.
Modifications for benchmarking shgo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/benchmarks/benchmarks/optimize.py b/benchmarks/benchmarks/optimize.py | |
| index 6696f7d..3a9abf6 100644 | |
| --- a/benchmarks/benchmarks/optimize.py | |
| +++ b/benchmarks/benchmarks/optimize.py | |
| @@ -17,6 +17,8 @@ try: | |
| except ImportError: | |
| pass | |
| +from shgo import shgo | |
| + | |
| from . import test_functions as funcs | |
| from . import go_benchmark_functions as gbf | |
| from .common import Benchmark | |
| @@ -187,16 +189,29 @@ class _BenchOptimizers(Benchmark): | |
| res.nfev = self.function.nfev | |
| self.add_result(res, t1 - t0, 'DE') | |
| + def run_shgo(self): | |
| + self.function.nfev = 0 | |
| + | |
| + t0 = time.time() | |
| + | |
| + res = shgo(self.fun, self.bounds) | |
| + | |
| + t1 = time.time() | |
| + res.success = self.function.success(res.x) | |
| + res.nfev = self.function.nfev | |
| + self.add_result(res, t1 - t0, 'shgo') | |
| + | |
| def bench_run_global(self, numtrials=50, methods=None): | |
| """ | |
| Run the optimization tests for the required minimizers. | |
| """ | |
| if methods is None: | |
| - methods = ['DE', 'basinh.'] | |
| + methods = ['DE', 'basinh.', 'shgo'] | |
| method_fun = {'DE': self.run_differentialevolution, | |
| - 'basinh.': self.run_basinhopping} | |
| + 'basinh.': self.run_basinhopping, | |
| + 'shgo': self.run_shgo} | |
| for i in range(numtrials): | |
| for m in methods: | |
| @@ -424,7 +439,7 @@ class BenchGlobal(Benchmark): | |
| params = [ | |
| list(_functions.keys()), | |
| ["success%", "<nfev>"], | |
| - ['DE', 'basinh.'], | |
| + ['DE', 'basinh.', 'shgo'], | |
| ] | |
| param_names = ["test function", "result type", "solver"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment