Esempio n. 1
0
    def test_3d_example(self):
        A = np.array([[1, 8, 1],
                      [4, 2, 2]])
        b = np.array([-16, 2])
        Z, LS, Y = projections(A)

        newton_point = np.array([-1.37090909, 2.23272727, -0.49090909])
        cauchy_point = np.array([0.11165723, 1.73068711, 0.16748585])
        origin = np.zeros_like(newton_point)

        # newton_point inside boundaries
        x = modified_dogleg(A, Y, b, 3, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        assert_array_almost_equal(x, newton_point)

        # line between cauchy_point and newton_point contains best point
        # (spherical constrain is active).
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = cauchy_point
        d = newton_point-cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, np.full(3, 0.40807330))
        assert_array_almost_equal(np.linalg.norm(x), 2)

        # line between cauchy_point and newton_point contains best point
        # (box constrain is active).
        x = modified_dogleg(A, Y, b, 5, [-1, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = cauchy_point
        d = newton_point-cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, np.full(3, 0.7498195))
        assert_array_almost_equal(x[0], -1)

        # line between origin and cauchy_point contains best point
        # (spherical constrain is active).
        x = modified_dogleg(A, Y, b, 1, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = origin
        d = cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, np.full(3, 0.573936265))
        assert_array_almost_equal(np.linalg.norm(x), 1)

        # line between origin and newton_point contains best point
        # (box constrain is active).
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf, -np.inf],
                            [np.inf, 1, np.inf])
        z = origin
        d = newton_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, np.full(3, 0.4478827364))
        assert_array_almost_equal(x[1], 1)
Esempio n. 2
0
    def test_3d_example(self):
        A = np.array([[1, 8, 1],
                      [4, 2, 2]])
        b = np.array([-16, 2])
        Z, LS, Y = projections(A)

        newton_point = np.array([-1.37090909, 2.23272727, -0.49090909])
        cauchy_point = np.array([0.11165723, 1.73068711, 0.16748585])
        origin = np.zeros_like(newton_point)

        # newton_point inside boundaries
        x = modified_dogleg(A, Y, b, 3, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        assert_array_almost_equal(x, newton_point)

        # line between cauchy_point and newton_point contains best point
        # (spherical constrain is active).
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = cauchy_point
        d = newton_point-cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, 0.40807330*np.ones(3))
        assert_array_almost_equal(np.linalg.norm(x), 2)

        # line between cauchy_point and newton_point contains best point
        # (box constrain is active).
        x = modified_dogleg(A, Y, b, 5, [-1, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = cauchy_point
        d = newton_point-cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, 0.7498195*np.ones(3))
        assert_array_almost_equal(x[0], -1)

        # line between origin and cauchy_point contains best point
        # (spherical constrain is active).
        x = modified_dogleg(A, Y, b, 1, [-np.inf, -np.inf, -np.inf],
                            [np.inf, np.inf, np.inf])
        z = origin
        d = cauchy_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, 0.573936265*np.ones(3))
        assert_array_almost_equal(np.linalg.norm(x), 1)

        # line between origin and newton_point contains best point
        # (box constrain is active).
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf, -np.inf],
                            [np.inf, 1, np.inf])
        z = origin
        d = newton_point
        t = ((x-z)/(d))
        assert_array_almost_equal(t, 0.4478827364*np.ones(3))
        assert_array_almost_equal(x[1], 1)
Esempio n. 3
0
    def test_cauchypoint_equalsto_newtonpoint(self):
        A = np.array([[1, 8]])
        b = np.array([-16])
        _, _, Y = projections(A)
        newton_point = np.array([0.24615385, 1.96923077])

        # Newton point inside boundaries
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf], [np.inf, np.inf])
        assert_array_almost_equal(x, newton_point)

        # Spherical constraint active
        x = modified_dogleg(A, Y, b, 1, [-np.inf, -np.inf], [np.inf, np.inf])
        assert_array_almost_equal(x, newton_point/np.linalg.norm(newton_point))

        # Box Constraints active
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf], [0.1, np.inf])
        assert_array_almost_equal(x, (newton_point/newton_point[0]) * 0.1)
Esempio n. 4
0
    def test_cauchypoint_equalsto_newtonpoint(self):
        A = np.array([[1, 8]])
        b = np.array([-16])
        _, _, Y = projections(A)
        newton_point = np.array([0.24615385, 1.96923077])

        # Newton point inside boundaries
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf], [np.inf, np.inf])
        assert_array_almost_equal(x, newton_point)

        # Spherical constraint active
        x = modified_dogleg(A, Y, b, 1, [-np.inf, -np.inf], [np.inf, np.inf])
        assert_array_almost_equal(x, newton_point/np.linalg.norm(newton_point))

        # Box Constraints active
        x = modified_dogleg(A, Y, b, 2, [-np.inf, -np.inf], [0.1, np.inf])
        assert_array_almost_equal(x, (newton_point/newton_point[0]) * 0.1)