Пример #1
0
    def test_inverse_iteration(self):
        M = random_symmetric(3)

        expected_eigval, expected_eigvec = self.np_eig(M, largest=False)

        actual_eigval, actual_eigvec = single.inverse_iteration(M)

        self.assertTrue(self.absallclose(actual_eigvec, expected_eigvec))
        self.assertTrue(self.absallclose(actual_eigval, expected_eigval))
Пример #2
0
  def test_factorization_equals_initial_symmetric(self):
    A = utils.random_symmetric(3)

    U, S, V = SVD(A).decompose()

    actual = U @ S @ V.T
    expected = A

    self.assertTrue(np.allclose(actual, expected))
Пример #3
0
    def test_power_iteration(self):
        M = random_symmetric(3)

        expected_eigval, expected_eigvec = self.np_eig(M)

        actual_eigval, actual_eigvec = single.power_iteration(M)

        self.assertTrue(self.absallclose(actual_eigval, expected_eigval))
        self.assertTrue(self.absallclose(actual_eigvec, expected_eigvec))
Пример #4
0
    def test_rayleigh_smallest(self):
        M = random_symmetric(3)

        expected_eigval, expected_eigvec = self.np_eig(M, largest=False)

        initial_eigval = single.inverse_iteration(M)[0]
        actual_eigval, actual_eigvec = single.rayleigh_quotient_iteration(
            M, initial_eigval)

        self.assertTrue(self.absallclose(actual_eigvec, expected_eigvec))
        self.assertTrue(self.absallclose(actual_eigval, expected_eigval))
Пример #5
0
    def test_projected_iteration(self):
        M = random_symmetric(3)

        eigvals, eigvecs = LA.eig(M)
        idx = np.abs(eigvals).argsort()[::-1]
        expected_eigvecs = eigvecs[:, idx]
        expected_eigvals = eigvals[idx]

        actual_eigvals, actual_eigvecs = multi.projected_iteration(M, 3)

        self.assertTrue(self.absallclose(actual_eigvecs, expected_eigvecs))
        self.assertTrue(self.absallclose(actual_eigvals, expected_eigvals))
Пример #6
0
    def test_qr_algorithm_with_hessenberg(self):
        M = random_symmetric(4)

        eigvals, eigvecs = LA.eig(M)
        idx = np.abs(eigvals).argsort()[::-1]
        expected_eigvecs = eigvecs[:, idx]
        expected_eigvals = eigvals[idx]

        actual_eigvals, actual_eigvecs = multi.qr_algorithm(M)

        self.assertTrue(self.absallclose(actual_eigvecs, expected_eigvecs))
        self.assertTrue(self.absallclose(actual_eigvals, expected_eigvals))
Пример #7
0
    def test_hessenberg_symmetric_stays_symmetric(self):
        M = random_symmetric(4)

        hess = multi.hessenberg(M)
        self.assertTrue(is_symmetric(hess))