MCPcopy Index your code
hub / github.com/bayesian-optimization/BayesianOptimization / test_int_parameters

Function test_int_parameters

tests/test_parameter.py:51–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

49
50
51def test_int_parameters():
52 def target_func(**kwargs):
53 assert [isinstance(kwargs[key], int) for key in kwargs]
54 # arbitrary target func
55 return sum(kwargs.values())
56
57 pbounds = {"p1": (0, 5, int), "p3": (-1, 3, int)}
58 space = TargetSpace(target_func, pbounds)
59
60 assert space.dim == len(pbounds)
61 assert space.empty
62 assert space.keys == ["p1", "p3"]
63
64 assert isinstance(space._params_config["p1"], IntParameter)
65 assert isinstance(space._params_config["p3"], IntParameter)
66
67 point1 = {"p1": 2, "p3": 0}
68 target1 = 2
69 space.probe(point1)
70
71 point2 = {"p1": 1, "p3": -1}
72 target2 = 0
73 space.probe(point2)
74
75 assert (space.params[0] == np.fromiter(point1.values(), dtype=float)).all()
76 assert (space.params[1] == np.fromiter(point2.values(), dtype=float)).all()
77
78 assert (space.target == np.array([target1, target2])).all()
79
80 p1 = space._params_config["p1"]
81 assert p1.to_float(0) == 0.0
82 assert p1.to_float(np.array(2)) == 2.0
83 assert p1.to_float(3) == 3.0
84
85 assert p1.kernel_transform(0) == 0.0
86 assert p1.kernel_transform(2.3) == 2.0
87 assert p1.kernel_transform(np.array([1.3, 3.6, 7.2])) == pytest.approx(np.array([1, 4, 7]))
88
89
90def test_cat_parameters():

Callers

nothing calls this directly

Calls 5

probeMethod · 0.95
TargetSpaceClass · 0.90
approxMethod · 0.80
to_floatMethod · 0.45
kernel_transformMethod · 0.45

Tested by

no test coverage detected