def test_finite_difference_gradients(self):
        def myfun(x):
            return 2 - 5*x[0,0] + 4*x[0,1]
            
        np.random.seed(42)
        X = np.random.uniform(-1.0,1.0,size=(10,2))

        df = gr.finite_difference_gradients(X, myfun)
        M = df.shape[0]
        df_test = np.tile(np.array([-5.0, 4.0]), (M,1))
        np.testing.assert_array_almost_equal(df, df_test, decimal=6)
    def test_finite_difference_gradients(self):
        def myfun(x):
            return 2 - 5 * x[0, 0] + 4 * x[0, 1]

        np.random.seed(42)
        X = np.random.uniform(-1.0, 1.0, size=(10, 2))

        df = gr.finite_difference_gradients(X, myfun)
        M = df.shape[0]
        df_test = np.tile(np.array([-5.0, 4.0]), (M, 1))
        np.testing.assert_array_almost_equal(df, df_test, decimal=6)
Esempio n. 3
0
    def test_finite_difference_gradients(self):
        def myfun(x):
            return 2 - 5*x[0,0] + 4*x[0,1]
            
        data = helper.load_test_npz('train_points_10_2.npz')
        X = data['X'].copy()

        df = gr.finite_difference_gradients(X, myfun)
        M = df.shape[0]
        df_test = np.tile(np.array([-5.0, 4.0]), (M,1))
        np.testing.assert_array_almost_equal(df, df_test, decimal=6)