示例#1
0
    def test_beta_rmsprop_exception(self):
        def objective_func(x):
            return x

        with self.assertRaises(ValueError) as e:
            var_init = np.array([0.2])
            optimizer = Optimizer(objective_func, var_init)
            optimizer.rmsprop_optimize(beta=54, num_iterations=1000)
        self.assertEqual(
            "The value of beta (sample weight) should be between 0 and 1.",
            str(e.exception),
        )
示例#2
0
    def test_univariate_scalar_rmsprop_optimization(self):
        def objective_func(x):
            return x * np.log(x)

        var_init = np.array([2])
        optimizer = Optimizer(objective_func, var_init)
        min_value, var_value = optimizer.rmsprop_optimize(tolerance=None,
                                                          num_iterations=10000)
        self.assertAlmostEqual(min_value, -1 / np.e, places=5)
        self.assertAlmostEqual(var_value[0], 1 / np.e, places=5)
示例#3
0
    def test_multivariate_vector_rmsprop_optimization(self):
        def objective_func(x):
            return x[0]**2 + x[0] * x[1] + x[1]**2

        var_init = np.array([0.2, 0.5])
        optimizer = Optimizer(objective_func, var_init, scalar=False)
        min_value, var_value = optimizer.rmsprop_optimize(tolerance=None,
                                                          num_iterations=10000)
        self.assertAlmostEqual(min_value, 0, places=5)
        self.assertAlmostEqual(var_value[0], 0, places=3)
        self.assertAlmostEqual(var_value[1], 0, places=3)