Beispiel #1
0
    def test_fit_predict_super(self, predict_mock, random_mock, uniform_mock):
        """If random is higher than POU, super.predict is used."""

        # Set-up
        tunables = (
            ('a_float_param', HyperParameter(ParamTypes.FLOAT, [1., 2.])),
            ('an_int_param', HyperParameter(ParamTypes.INT, [1, 5])),
        )
        tuner = GPEiVelocity(tunables, r_minimum=2)

        tuner.POU = 0.05

        random_mock.random.return_value = 0.1

        # Run
        X = np.array([
            [1., 1],
            [1.2, 2],
            [1.4, 3],
            [1.6, 4],
            [1.8, 5]
        ])
        tuner.predict(X)

        # assert
        predict_mock.assert_called_once_with(X)
        uniform_mock.assert_not_called()
Beispiel #2
0
    def test_fit_predict_uniform(self, predict_mock, random_mock,
                                 uniform_mock):
        """If random is lower than POU, Uniform is used."""

        # Set-up
        tunables = (
            ('a_float_param', HyperParameter(ParamTypes.FLOAT, [1., 2.])),
            ('an_int_param', HyperParameter(ParamTypes.INT, [1, 5])),
        )
        tuner = GPEiVelocity(tunables, r_minimum=2)

        tuner.POU = 0.05

        random_mock.random.return_value = 0.01

        uniform_instance_mock = Mock()
        uniform_mock.return_value = uniform_instance_mock

        # Run
        X = np.array([[1., 1], [1.2, 2], [1.4, 3], [1.6, 4], [1.8, 5]])
        tuner.predict(X)

        # assert
        uniform_mock.assert_called_once_with(tunables)
        uniform_instance_mock.predict.assert_called_once_with(X)

        predict_mock.assert_not_called()
Beispiel #3
0
    def test_fit_gt_r_min(self, fit_mock):
        """If the length of X is greater than r_minimum, calculate POU."""
        # Set-up
        tuner = GPEiVelocity(tuple(), r_minimum=2)

        # Run
        X = np.array([[1., 1], [1.2, 2], [1.4, 3], [1.6, 4], [1.8, 5]])
        y = np.array([0.8, 0.81, 0.9, 0.84, 0.87])
        tuner.fit(X, y)

        # assert
        assert tuner.POU == 0.08208499862389883
Beispiel #4
0
    def test_fit_lt_r_min(self, fit_mock):
        """If the length of X is smaller than r_minimum, nothing is done."""
        # Set-up
        tuner = GPEiVelocity(tuple(), r_minimum=5)

        # Run
        X = np.array([[1., 1], [1.2, 2], [1.4, 4]])
        y = np.array([0.5, 0.6, 0.7])
        tuner.fit(X, y)

        # assert
        assert tuner.POU == 0
Beispiel #5
0
 def test_gpeivelocity(self):
     X = [{'a': 1.1, 'b': 0.01, 'c': 3.5}, {'a': 4, 'b': 0.001, 'c': 6.2}]
     y = [0.5, 0.6]
     c1 = HyperParameter(ParamTypes.INT, [1, 5])
     c2 = HyperParameter(ParamTypes.FLOAT_EXP, [0.0001, 0.1])
     c3 = HyperParameter(ParamTypes.FLOAT, [2, 8])
     tunables = [('a', c1), ('b', c2), ('c', c3)]
     u = GPEiVelocity(tunables)
     u.add(X, y)
     for i in range(100):
         proposed = u.propose()
         self.assertTrue(proposed['a'] >= 1 and proposed['a'] <= 5)
         self.assertTrue(proposed['b'] >= 0.0001 and proposed['b'] <= 0.1)
         self.assertTrue(proposed['c'] >= 2 and proposed['c'] <= 8)
Beispiel #6
0
    def test_fit_lt_r_min(self, fit_mock):
        """If the length of X is smaller than r_minimum, nothing is done."""
        # Set-up
        tuner = GPEiVelocity(tuple(), r_minimum=5)

        # Run
        X = np.array([
            [1., 1],
            [1.2, 2],
            [1.4, 4]
        ])
        y = np.array([0.5, 0.6, 0.7])
        tuner.fit(X, y)

        # assert
        assert tuner.POU == 0
Beispiel #7
0
    def test_fit_gt_r_min(self, fit_mock):
        """If the length of X is greater than r_minimum, calculate POU."""
        # Set-up
        tuner = GPEiVelocity(tuple(), r_minimum=2)

        # Run
        X = np.array([
            [1., 1],
            [1.2, 2],
            [1.4, 3],
            [1.6, 4],
            [1.8, 5]
        ])
        y = np.array([0.8, 0.81, 0.9, 0.84, 0.87])
        tuner.fit(X, y)

        # assert
        assert tuner.POU == 0.08208499862389883