()
| 11 | |
| 12 | |
| 13 | def test_float_parameters(): |
| 14 | def target_func(**kwargs): |
| 15 | # arbitrary target func |
| 16 | return sum(kwargs.values()) |
| 17 | |
| 18 | pbounds = {"p1": (0, 1), "p2": (1, 2)} |
| 19 | space = TargetSpace(target_func, pbounds) |
| 20 | |
| 21 | assert space.dim == len(pbounds) |
| 22 | assert space.empty |
| 23 | assert space.keys == ["p1", "p2"] |
| 24 | |
| 25 | assert isinstance(space._params_config["p1"], FloatParameter) |
| 26 | assert isinstance(space._params_config["p2"], FloatParameter) |
| 27 | |
| 28 | assert all(space.bounds[:, 0] == np.array([0, 1])) |
| 29 | assert all(space.bounds[:, 1] == np.array([1, 2])) |
| 30 | assert (space.bounds == space.bounds).all() |
| 31 | |
| 32 | point1 = {"p1": 0.2, "p2": 1.5} |
| 33 | target1 = 1.7 |
| 34 | space.probe(point1) |
| 35 | |
| 36 | point2 = {"p1": 0.5, "p2": 1.0} |
| 37 | target2 = 1.5 |
| 38 | space.probe(point2) |
| 39 | |
| 40 | assert (space.params[0] == np.fromiter(point1.values(), dtype=float)).all() |
| 41 | assert (space.params[1] == np.fromiter(point2.values(), dtype=float)).all() |
| 42 | |
| 43 | assert (space.target == np.array([target1, target2])).all() |
| 44 | |
| 45 | p1 = space._params_config["p1"] |
| 46 | assert p1.to_float(0.2) == 0.2 |
| 47 | assert p1.to_float(np.array(2.3)) == 2.3 |
| 48 | assert p1.to_float(3) == 3.0 |
| 49 | |
| 50 | |
| 51 | def test_int_parameters(): |
nothing calls this directly
no test coverage detected