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_hyperactive_para(X, y, memory, random_state, verbosity): |
11
|
|
|
memory_list = ["short", "long", True, False] |
12
|
|
|
|
13
|
|
|
if not isinstance(X, np.ndarray): |
14
|
|
|
raise ValueError(r'Positional argument X must be of type numpy.ndarray') |
15
|
|
|
|
16
|
|
|
if not isinstance(y, np.ndarray): |
17
|
|
|
raise ValueError(r'Positional argument X must be of type numpy.ndarray') |
18
|
|
|
|
19
|
|
|
if memory not in memory_list: |
20
|
|
|
raise ValueError(r'Keyword argument memory must be "short", "long", True or False') |
21
|
|
|
|
22
|
|
|
if not isinstance(random_state, int) and not random_state == False: |
23
|
|
|
raise ValueError(r'Keyword argument random_state must be of type int or False') |
24
|
|
|
|
25
|
|
|
if not isinstance(verbosity, int): |
26
|
|
|
raise ValueError(r'Keyword argument verbosity must be of type int') |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
def check_search_para(search_config, max_time, n_iter, optimizer, n_jobs, init_config): |
30
|
|
|
|
31
|
|
|
if not isinstance(search_config, dict): |
32
|
|
|
raise ValueError(r'Positional argument search_config must be of type dict') |
33
|
|
|
elif isinstance(search_config, dict): |
34
|
|
|
_check_search_config(search_config) |
35
|
|
|
|
36
|
|
|
if not isinstance(max_time, (int, float)) and not max_time == None: |
37
|
|
|
raise ValueError(r'Keyword argument max_time must be of type int, float or None') |
38
|
|
|
|
39
|
|
|
if not isinstance(n_iter, int): |
40
|
|
|
raise ValueError(r'Keyword argument n_iter must be of type int') |
41
|
|
|
|
42
|
|
|
if not isinstance(optimizer, dict) and not isinstance(optimizer, str): |
43
|
|
|
raise ValueError(r'Keyword argument optimizer must be of type str or dict') |
44
|
|
|
|
45
|
|
|
if not isinstance(n_jobs, int): |
46
|
|
|
raise ValueError(r'Keyword argument n_jobs must be of type int') |
47
|
|
|
|
48
|
|
|
if not isinstance(init_config, dict) and not init_config == None: |
49
|
|
|
raise ValueError(r'Keyword argument init_config must be of type dict or None') |
50
|
|
|
elif isinstance(init_config, dict): |
51
|
|
|
_check_init_config(init_config) |
52
|
|
|
|
53
|
|
|
|
54
|
|
|
def _check_search_config(search_config): |
55
|
|
|
for key in search_config.keys(): |
56
|
|
|
if not isinstance(key, collections.Callable): |
57
|
|
|
raise ValueError(r'Key in search_config must be callable') |
58
|
|
|
if not isinstance(search_config[key], dict): |
59
|
|
|
raise ValueError(r'Value in search_config must be of type dict') |
60
|
|
|
|
61
|
|
|
def _check_init_config(init_config): |
62
|
|
|
for key in init_config.keys(): |
63
|
|
|
if not isinstance(key, collections.Callable): |
64
|
|
|
raise ValueError(r'Key in init_config must be callable') |
65
|
|
|
if not isinstance(init_config[key], dict): |
66
|
|
|
raise ValueError(r'Value in init_config must be of type dict') |
67
|
|
|
|
68
|
|
|
|