Ejemplo n.º 1
0
    def test_perturb_cat(self):
        explore = PerturbExplore()
        rng = RNGStub()
        rng.randint = lambda low, high, size: [1]
        rng.choice = lambda choices: choices[0]

        dim = Categorical("name", ["one", "two", 3, 4.0])
        assert explore.perturb_cat(rng, "whatever", dim) in dim
Ejemplo n.º 2
0
    def test_perturb(self, space):
        explore = PerturbExplore()
        rng = RNGStub()
        rng.randint = lambda low, high, size: [1]
        rng.random = lambda: 1.0
        rng.normal = lambda mean, variance: 0.0
        rng.choice = lambda choices: choices[0]

        params = {"x": 1.0, "y": 2, "z": 0, "f": 10}
        new_params = explore(rng, space, params)
        for key in space.keys():
            assert new_params[key] in space[key]
Ejemplo n.º 3
0
    def test_resample_probability(self, space):
        explore = ResampleExplore(probability=0.5)

        rng = RNGStub()
        rng.randint = lambda low, high, size: [1]
        rng.random = lambda: 0.5

        params = {"x": 1.0, "y": 2, "z": 0, "f": 10}

        assert explore(rng, space, params) is params

        rng.random = lambda: 0.4

        assert explore(rng, space, params) is not params
Ejemplo n.º 4
0
    def test_perturb_hierarchical_params(self, hspace):
        explore = PerturbExplore()
        rng = RNGStub()
        rng.randint = lambda low, high, size: [1]
        rng.random = lambda: 1.0
        rng.normal = lambda mean, variance: 0.0
        rng.choice = lambda choices: choices[0]

        params = {"numerical": {"x": 1.0, "y": 2, "f": 10}, "z": 0}
        new_params = explore(rng, hspace, params)
        assert "numerical" in new_params
        assert "x" in new_params["numerical"]
        for key in hspace.keys():
            assert flatten(new_params)[key] in hspace[key]