forked from CyberAgentAILab/cmaes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem_six_hump_camel.py
55 lines (42 loc) · 1.54 KB
/
problem_six_hump_camel.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from kurobako import problem
from kurobako.problem import Problem
from typing import List
from typing import Optional
class SixHumpCamelEvaluator(problem.Evaluator):
"""
See https://www.sfu.ca/~ssurjano/camel6.html
"""
def __init__(self, params: List[Optional[float]]):
self._x1, self._x2 = params
self._current_step = 0
def evaluate(self, next_step: int) -> List[float]:
self._current_step = 1
value = (
(4 - 2.1 * (self._x1 ** 2) + (self._x1 ** 4) / 3) * (self._x1 ** 2)
+ self._x1 * self._x2
+ (-4 + 4 * self._x2 ** 2) * (self._x2 ** 2)
)
return [value]
def current_step(self) -> int:
return self._current_step
class SixHumpCamelProblem(problem.Problem):
def create_evaluator(
self, params: List[Optional[float]]
) -> Optional[problem.Evaluator]:
return SixHumpCamelEvaluator(params)
class SixHumpCamelProblemFactory(problem.ProblemFactory):
def create_problem(self, seed: int) -> Problem:
return SixHumpCamelProblem()
def specification(self) -> problem.ProblemSpec:
params = [
problem.Var("x1", problem.ContinuousRange(-5, 10)),
problem.Var("x2", problem.ContinuousRange(-5, 10)),
]
return problem.ProblemSpec(
name="Six-Hump Camel Function",
params=params,
values=[problem.Var("Six-Hump Camel")],
)
if __name__ == "__main__":
runner = problem.ProblemRunner(SixHumpCamelProblemFactory())
runner.run()