def test_state_hessian(self):
        """
        """
        g_xs = np.ones((1, 3)) * 0.5
        xs = np.ones((1, 3))
        cost_hess =\
            TwoWheeledConfigModule.hessian_cost_fn_state(xs, g_xs)

        # numeric grad
        eps = 1e-4
        expected_hess = np.zeros((1, 3, 3))
        for i in range(3):
            tmp_x = xs.copy()
            tmp_x[0, i] = xs[0, i] + eps
            forward = \
                TwoWheeledConfigModule.gradient_cost_fn_state(
                    tmp_x, g_xs, terminal=False)
            tmp_x = xs.copy()
            tmp_x[0, i] = xs[0, i] - eps
            backward = \
                TwoWheeledConfigModule.gradient_cost_fn_state(
                    tmp_x, g_xs, terminal=False)

            expected_hess[0, :, i] = (forward - backward) / (2. * eps)

        assert cost_hess == pytest.approx(expected_hess)
    def test_state_gradient(self):
        """
        """
        xs = np.ones((1, 3))
        g_xs = np.ones((1, 3)) * 0.5
        cost_grad =\
            TwoWheeledConfigModule.gradient_cost_fn_state(xs, g_xs)

        # numeric grad
        eps = 1e-4
        expected_grad = np.zeros((1, 3))
        for i in range(3):
            tmp_x = xs.copy()
            tmp_x[0, i] = xs[0, i] + eps
            forward = \
                TwoWheeledConfigModule.state_cost_fn(tmp_x, g_xs)
            forward = np.sum(forward)
            tmp_x = xs.copy()
            tmp_x[0, i] = xs[0, i] - eps
            backward = \
                TwoWheeledConfigModule.state_cost_fn(tmp_x, g_xs)
            backward = np.sum(backward)

            expected_grad[0, i] = (forward - backward) / (2. * eps)

        assert cost_grad == pytest.approx(expected_grad)