Exemplo n.º 1
0
    def __repr__(self):
        """Prints basic statistics about the multigrid hierarchy.
        """
        from pyamg.util.linalg import condest

        levels = self.levels[::-1]

        output = 'multilevel_solver\n'
        output += 'Conditioning Number of the matrix:     %d\n' % condest(
            self.A)
        output += 'Number of Levels:     %d\n' % len(levels)
        output += 'Operator Complexity: %6.3f\n' % self.operator_complexity()
        output += 'Grid Complexity:     %6.3f\n' % self.grid_complexity()
        #        output += 'Coarse Solver:        %s\n' % self.coarse_solver.name()

        total_nnz = sum([level.A.nnz for level in levels])

        output += '  level   unknowns     nonzeros\n'
        for n, level in enumerate(levels):
            A = level.A
            output += '   %2d   %10d   %10d [%5.2f%%]\n' %\
                    (n, A.shape[1], A.nnz,\
                    (100 * float(A.nnz) / float(total_nnz)))

        return output
Exemplo n.º 2
0
    def test_condest(self):
        # make tests repeatable
        np.random.seed(0)

        # Should be exact for small matrices
        cases = []
        A = np.array([[2.14]])
        cases.append(A)
        A = np.array([[2.14j]])
        cases.append(A)
        A = np.array([[-1.2 + 2.14j]])
        cases.append(A)
        for i in range(1, 6):
            A = np.random.rand(i, i)
            A = 0.5 * (A.conj().T + A)
            cases.append(A)
            A = A + 1.0j*np.random.rand(i, i)
            A = 0.5 * (A.conj().T + A)
            cases.append(A)

        for A in cases:
            U, Sigma, Vh = svd(A)
            exact = max(Sigma)/min(Sigma)
            c = condest(A, symmetric=True)
            assert_almost_equal(exact, c)

        cases = []
        for i in range(1, 6):
            A = np.random.rand(i, i)
            cases.append(A)
            cases.append(1.0j*A)
            A = A + 1.0j*np.random.rand(i, i)
            cases.append(A)

        for A in cases:
            U, Sigma, Vh = svd(A)
            exact = max(Sigma)/min(Sigma)
            c = condest(A, symmetric=False)
            assert_almost_equal(exact, c)
Exemplo n.º 3
0
    def test_condest(self):
        # make tests repeatable
        np.random.seed(0)

        # Should be exact for small matrices
        cases = []
        A = np.array([[2.14]])
        cases.append(A)
        A = np.array([[2.14j]])
        cases.append(A)
        A = np.array([[-1.2 + 2.14j]])
        cases.append(A)
        for i in range(1, 6):
            A = np.random.rand(i, i)
            cases.append(A)
            cases.append(1.0j*A)
            A = A + 1.0j*np.random.rand(i, i)
            cases.append(A)

        for A in cases:
            eigs = eigvals(A)
            exact = max(np.abs(eigs))/min(np.abs(eigs))
            c = condest(A)
            assert_almost_equal(exact, c)
Exemplo n.º 4
0
    def test_condest(self):
        # make tests repeatable
        random.seed(0)

        # Should be exact for small matrices
        cases = []
        A = mat(array([2.14]))
        cases.append(A)
        A = mat(array([2.14j]))
        cases.append(A)
        A = mat(array([-1.2 + 2.14j]))
        cases.append(A)
        for i in range(1, 6):
            A = mat(rand(i, i))
            cases.append(A)
            cases.append(1.0j * A)
            A = mat(A + 1.0j * rand(i, i))
            cases.append(A)

        for A in cases:
            eigs = eigvals(A)
            exact = max(abs(eigs)) / min(abs(eigs))
            c = condest(A)
            assert_almost_equal(exact, c)