Completed
Push — master ( 8b8364...81d861 )
by Simon
04:18
created

hyperactive.checks._check_init_config()   A

Complexity

Conditions 4

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 4
nop 1
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(
21
            r'Keyword argument memory must be "short", "long", True or False'
22
        )
23
24
    if not isinstance(random_state, int) and random_state is not False:
25
        raise ValueError(r"Keyword argument random_state must be of type int or False")
26
27
    if not isinstance(verbosity, int):
28
        raise ValueError(r"Keyword argument verbosity must be of type int")
29
30
31
def check_para(para, type):
32
    if not isinstance(para, type):
33
        raise ValueError(
34
            r"Keyword argument " + str(para) + "must be of type " + str(type)
35
        )
36
37
38
def check_search_para(
39
    search_config, max_time, n_iter, optimizer, n_jobs, scheduler, init_config
40
):
41
    scheduler_list = [None, "default", "smart"]
42
43
    if not isinstance(search_config, dict):
44
        raise ValueError(r"Positional argument search_config must be of type dict")
45
    elif isinstance(search_config, dict):
46
        _check_config(search_config)
47
48
    if not isinstance(max_time, (int, float)) and max_time is not None:
49
        raise ValueError(
50
            r"Keyword argument max_time must be of type int, float or None"
51
        )
52
53
    check_para(n_iter, int)
54
    check_para(optimizer, (dict, str))
55
    check_para(n_jobs, int)
56
57
    if scheduler not in scheduler_list:
58
        raise ValueError(
59
            r'Keyword argument scheduler must be None, "default" or "smart"'
60
        )
61
62
    if not isinstance(init_config, dict) and init_config is not None:
63
        raise ValueError(r"Keyword argument init_config must be of type dict or None")
64
    elif isinstance(init_config, dict):
65
        _check_config(init_config)
66
67
68
def _check_config(config):
69
    for key in config.keys():
70
        if not isinstance(key, collections.Callable):
71
            raise ValueError(r"Key in " + str(config) + " must be callable")
72
        if not isinstance(config[key], dict):
73
            raise ValueError(r"Value in " + str(config) + " must be of type dict")
74