-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.py
executable file
·43 lines (33 loc) · 1.44 KB
/
experiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
from __future__ import division, print_function
import cocoex, cocopp
import scipy.optimize
from numpy.random import rand
import os, webbrowser
def run_experiment(suite_name, output, fmin, budget_multiplier = 1):
"""
Run COCO benchmark.
Define function wrapper for your algorithm like below:
>>> import cma # doctest:+SKIP
>>> def fmin(fun, x0):
... return cma.fmin(fun, x0, 2, {'verbose':-9})
and pass it as a input to the function.
:param: suite_name suite name (e.g. bbob, bbob-largescale, etc.)
:param: output directory where executor will write results
:param: fmin optimization algorithm
:param: budget_multiplier budget_multiplier
"""
suite = cocoex.Suite(suite_name, "", "")
observer = cocoex.Observer(suite_name, "result_folder: " + output)
minimal_print = cocoex.utilities.MiniPrint()
for problem in suite:
problem.observe_with(observer)
x0 = problem.initial_solution
while (problem.evaluations < problem.dimension * budget_multiplier
and not problem.final_target_hit):
fmin(problem, x0)
x0 = problem.lower_bounds + ((rand(problem.dimension) + rand(problem.dimension)) *
(problem.upper_bounds - problem.lower_bounds) / 2)
minimal_print(problem, final=problem.index == len(suite) - 1)
if __name__ == "__main__":
run_experiment("bbob", "[ALGORITHM NAME]", fmin)