|
1
|
|
|
# Author: Simon Blanke |
|
2
|
|
|
# Email: [email protected] |
|
3
|
|
|
# License: MIT License |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
import collections |
|
7
|
|
|
import numpy as np |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
def _check_objective_function(value): |
|
11
|
|
|
if not isinstance(value, collections.Callable): |
|
12
|
|
|
raise ValueError(r"objective_function must be callable") |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
def _check_function_parameter(value): |
|
16
|
|
|
if not isinstance(value, dict): |
|
17
|
|
|
raise ValueError(r"function_parameter must be of type dict") |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
def _check_search_space(value): |
|
21
|
|
|
if not isinstance(value, dict): |
|
22
|
|
|
raise ValueError(r"search_space must be of type dict") |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def _check_memory(value): |
|
26
|
|
|
memory_list = ["short", "long", False] |
|
27
|
|
|
if value not in memory_list: |
|
28
|
|
|
raise ValueError(r"memory must be 'short', 'long' or False") |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def _check_optimizer(value): |
|
32
|
|
|
if not isinstance(value, (dict, str)): |
|
33
|
|
|
raise ValueError(r"optimizer must be of type dict or str") |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
def _check_n_iter(value): |
|
37
|
|
|
if not isinstance(value, int): |
|
38
|
|
|
raise ValueError(r"n_iter must be of type int") |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
def _check_n_jobs(value): |
|
42
|
|
|
if not isinstance(value, int): |
|
43
|
|
|
raise ValueError(r"n_jobs must be of type int") |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def _check_init_para(value): |
|
47
|
|
|
if not isinstance(value, list) and value is not None: |
|
48
|
|
|
raise ValueError(r"init_para must be of type list or None") |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
def _check_distribution(value): |
|
52
|
|
|
if not isinstance(value, dict) and value is not None: |
|
53
|
|
|
raise ValueError(r"distribution must be of type dict or None") |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
arguments = { |
|
57
|
|
|
"objective_function": _check_objective_function, |
|
58
|
|
|
"function_parameter": _check_function_parameter, |
|
59
|
|
|
"search_space": _check_search_space, |
|
60
|
|
|
"memory": _check_memory, |
|
61
|
|
|
"optimizer": _check_optimizer, |
|
62
|
|
|
"n_iter": _check_n_iter, |
|
63
|
|
|
"n_jobs": _check_n_jobs, |
|
64
|
|
|
"init_para": _check_init_para, |
|
65
|
|
|
"distribution": _check_distribution, |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
def check_kwargs(kwargs): |
|
70
|
|
|
for keyword in kwargs: |
|
71
|
|
|
if keyword not in arguments: |
|
72
|
|
|
raise TypeError( |
|
73
|
|
|
"add_search got an unexpected keyword argument " + str(keyword) |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
value = kwargs[keyword] |
|
77
|
|
|
check_function = arguments[keyword] |
|
78
|
|
|
check_function(value) |
|
79
|
|
|
|
|
80
|
|
|
|