python类eigvals()的实例源码

pedWorks.py 文件源码 项目:PedWorks 作者: BrnCPrz 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def calculate_katz_centrality(graph):
    """
    Compute the katz centrality for nodes.
    """
    # if not graph.is_directed():
    #    raise nx.NetworkXError( \
    #       "katz_centrality() not defined for undirected graphs.")
    print "\n\tCalculating Katz Centrality..."
    print "\tWarning: This might take a long time larger pedigrees."
    g = graph
    A = nx.adjacency_matrix(g)
    from scipy import linalg as LA
    max_eign = float(np.real(max(LA.eigvals(A.todense()))))
    print "\t-Max.Eigenvalue(A) ", round(max_eign, 3)
    kt = nx.katz_centrality(g, tol=1.0e-4, alpha=1/max_eign-0.01, beta=1.0, max_iter=999999)
    nx.set_node_attributes(g, 'katz', kt)
    katz_sorted = sorted(kt.items(), key=itemgetter(1), reverse=True)
    for key, value in katz_sorted[0:10]:
        print "\t   > ", key, round(value, 4)
    return g, kt
system.py 文件源码 项目:ADER-WENO 作者: haranjackson 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def max_abs_eigs(q, d):
    """ Returns the largest of the absolute values of the eigenvalues of system matrix at q in
        direction d
    """
    J = jacobian(q, d)
    return max(abs(eigvals(J)))
_symmetric_hamiltonian.py 文件源码 项目:kdotp-symmetry 作者: greschd 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _numeric_nullspace_dim(mat):
    """Numerically computes the nullspace dimension of a matrix."""
    mat_numeric = np.array(mat.evalf().tolist(), dtype=complex)
    eigenvals = la.eigvals(mat_numeric)
    return np.sum(np.isclose(eigenvals, np.zeros_like(eigenvals)))
pychebfun.py 文件源码 项目:fluids 作者: CalebBell 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def roots(self):
        """
        Utilises Boyd's O(n^2) recursive subdivision algorithm. The chebfun
        is recursively subsampled until it is successfully represented to
        machine precision by a sequence of piecewise interpolants of degree
        100 or less. A colleague matrix eigenvalue solve is then applied to
        each of these pieces and the results are concatenated.
        See:
        J. P. Boyd, Computing zeros on a real interval through Chebyshev
        expansion and polynomial rootfinding, SIAM J. Numer. Anal., 40
        (2002), pp. 1666–1682.
        """
        if self.size() == 1:
            return np.array([])

        elif self.size() <= 100:
            ak = self.coefficients()
            v = np.zeros_like(ak[:-1])
            v[1] = 0.5
            C1 = linalg.toeplitz(v)
            C2 = np.zeros_like(C1)
            C1[0,1] = 1.
            C2[-1,:] = ak[:-1]
            C = C1 - .5/ak[-1] * C2
            eigenvalues = linalg.eigvals(C)
            roots = [eig.real for eig in eigenvalues
                    if np.allclose(eig.imag,0,atol=1e-10)
                        and np.abs(eig.real) <=1]
            scaled_roots = self._ui_to_ab(np.array(roots))
            return scaled_roots
        else:
            # divide at a close-to-zero split-point
            split_point = self._ui_to_ab(0.0123456789)
            return np.concatenate(
                (self.restrict([self._domain[0],split_point]).roots(),
                 self.restrict([split_point,self._domain[1]]).roots())
            )

    # ----------------------------------------------------------------
    # Interpolation and evaluation (go from values to coefficients)
    # ----------------------------------------------------------------


问题


面经


文章

微信
公众号

扫码关注公众号