Passed
Push — master ( 7e35c2...37974c )
by Simon
03:12
created

tests.test_data_collector.test_data_collector_1()   A

Complexity

Conditions 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nop 0
dl 20
loc 20
rs 9.7
c 0
b 0
f 0
1
import numpy as np
2
from hyperactive import Hyperactive
3
from hyperactive.data_tools import DataCollector
4
5
6 View Code Duplication
def test_data_collector_0():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
    def objective_function(opt):
8
        score = -opt["x1"] * opt["x1"]
9
        return score
10
11
    search_space = {
12
        "x1": np.arange(-100, 101, 1),
13
    }
14
15
    hyper = Hyperactive()
16
    hyper.add_search(objective_function, search_space, n_iter=20)
17
    hyper.run()
18
19
    search_data = hyper.results(objective_function)
20
21
    data_c = DataCollector("./search_data.csv")
22
    data_c.save(search_data)
23
    search_data_ = data_c.load()
24
25
    search_data.equals(search_data_)
26
27
28 View Code Duplication
def test_data_collector_1():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29
    def objective_function(opt):
30
        score = -opt["x1"] * opt["x1"]
31
        return score
32
33
    search_space = {
34
        "x1": np.arange(-100, 101, 1),
35
    }
36
37
    hyper = Hyperactive()
38
    hyper.add_search(objective_function, search_space, n_iter=20)
39
    hyper.run()
40
41
    search_data = hyper.results(objective_function)
42
43
    data_c = DataCollector("./search_data.csv")
44
    data_c.save(search_data, replace_existing=True)
45
    search_data_ = data_c.load()
46
47
    search_data.equals(search_data_)
48
49
50
def test_data_collector_2():
51
    data_c = DataCollector("./search_data.csv")
52
53
    def objective_function(opt):
54
        score = -opt["x1"] * opt["x1"]
55
56
        para_dict = {
57
            "x1": opt["x1"],
58
            "score": score,
59
        }
60
61
        data_c.append(para_dict)
62
63
        return score
64
65
    search_space = {
66
        "x1": np.arange(-100, 101, 1),
67
    }
68
69
    hyper = Hyperactive()
70
    hyper.add_search(objective_function, search_space, n_iter=20)
71
    hyper.run()
72
73
    search_data_ = data_c.load()
74