當前位置: 首頁>>代碼示例>>Python>>正文


Python arpack.eigsh方法代碼示例

本文整理匯總了Python中scipy.sparse.linalg.eigen.arpack.eigsh方法的典型用法代碼示例。如果您正苦於以下問題:Python arpack.eigsh方法的具體用法?Python arpack.eigsh怎麽用?Python arpack.eigsh使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.sparse.linalg.eigen.arpack的用法示例。


在下文中一共展示了arpack.eigsh方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: update_bond

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def update_bond(self, i):
        j = (i + 1) % self.psi.L
        # get effective Hamiltonian
        Heff = SimpleHeff(self.LPs[i], self.RPs[j], self.H_mpo[i], self.H_mpo[j])
        # Diagonalize Heff, find ground state `theta`
        theta0 = np.reshape(self.psi.get_theta2(i), [Heff.shape[0]])  # initial guess
        e, v = arp.eigsh(Heff, k=1, which='SA', return_eigenvectors=True, v0=theta0)
        theta = np.reshape(v[:, 0], Heff.theta_shape)
        # split and truncate
        Ai, Sj, Bj = split_truncate_theta(theta, self.chi_max, self.eps)
        # put back into MPS
        Gi = np.tensordot(np.diag(self.psi.Ss[i]**(-1)), Ai, axes=[1, 0])  # vL [vL*], [vL] i vC
        self.psi.Bs[i] = np.tensordot(Gi, np.diag(Sj), axes=[2, 0])  # vL i [vC], [vC*] vC
        self.psi.Ss[j] = Sj  # vC
        self.psi.Bs[j] = Bj  # vC j vR
        self.update_LP(i)
        self.update_RP(j) 
開發者ID:tenpy,項目名稱:tenpy,代碼行數:19,代碼來源:d_dmrg.py

示例2: chebyshev_polynomials

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def chebyshev_polynomials(adj, k):
    """Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation)."""
    print("Calculating Chebyshev polynomials up to order {}...".format(k))

    adj_normalized = normalize_adj(adj)
    laplacian = sp.eye(adj.shape[0]) - adj_normalized
    largest_eigval, _ = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (
        2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])

    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return 2 * s_lap.dot(t_k_minus_one) - t_k_minus_two

    for i in range(2, k+1):
        t_k.append(chebyshev_recurrence(t_k[-1], t_k[-2], scaled_laplacian))

    return sparse_to_tuple(t_k) 
開發者ID:thunlp,項目名稱:OpenNE,代碼行數:24,代碼來源:utils.py

示例3: chebyshev_polynomials

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def chebyshev_polynomials(adj, k):
    """Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation)."""
    print("Calculating Chebyshev polynomials up to order {}...".format(k))

    adj_normalized = normalize_adj(adj)
    laplacian = sp.eye(adj.shape[0]) - adj_normalized
    largest_eigval, _ = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])

    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return 2 * s_lap.dot(t_k_minus_one) - t_k_minus_two

    for i in range(2, k+1):
        t_k.append(chebyshev_recurrence(t_k[-1], t_k[-2], scaled_laplacian))

    return sparse_to_tuple(t_k) 
開發者ID:dfdazac,項目名稱:dgi,代碼行數:23,代碼來源:utils.py

示例4: chebyshev_polynomials

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def chebyshev_polynomials(adj, k):
    """Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation)."""
    print("Calculating Chebyshev polynomials up to order {}...".format(k))

    adj_normalized = normalize_adj(adj)
    laplacian = sp.eye(adj.shape[0]) - adj_normalized
    largest_eigval, _ = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])

    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return 2 * s_lap.dot(t_k_minus_one) - t_k_minus_two

    for i in range(2, k + 1):
        t_k.append(chebyshev_recurrence(t_k[-1], t_k[-2], scaled_laplacian))

    return sparse_to_tuple(t_k) 
開發者ID:JudyYe,項目名稱:zero-shot-gcn,代碼行數:23,代碼來源:utils.py

示例5: compute_chebyshev_polynomial

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def compute_chebyshev_polynomial(adj, degree):
    '''Method to compute Chebyshev Polynomial upto degree `degree`'''

    adj_normalized = renormalization_trick(adj=adj)

    identity_size  = adj.shape[0]

    # laplacian_normalized = In - adj_normalized
    laplacian_normalized = get_identity(identity_size) - adj_normalized
    eigval, _ = eigsh(A = laplacian_normalized, k = 1, which="LM")

    # L = 2L/lamba_max - In
    laplacian_normalized_scaled = (2.0 * laplacian_normalized)/eigval[0] - get_identity(identity_size)
    Tk = [get_identity(identity_size), laplacian_normalized_scaled]
    # Tk = [Tk[-1] + Tk[-2]]

    for i in range(2, degree+1):
        Tk.append(_compute_chebyshev_recurrence(current = Tk[-1],
                                               previous = Tk[-2],
                                               X = laplacian_normalized_scaled))
    return Tk 
開發者ID:shagunsodhani,項目名稱:pregel,代碼行數:23,代碼來源:base_graph.py

示例6: chebyshev_polynomials

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def chebyshev_polynomials(adj, k):
    """Calculate Chebyshev polynomials up to order k. Return a list of sparse matrices (tuple representation)."""
    print("Calculating Chebyshev polynomials up to order {}...".format(k))
    adj_normalized = normalize_adj(adj)
    laplacian = sp.eye(adj.shape[0]) - adj_normalized
    largest_eigval, _ = eigsh(laplacian, 1, which='LM')
    scaled_laplacian = (2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])
    t_k = list()
    t_k.append(sp.eye(adj.shape[0]))
    t_k.append(scaled_laplacian)

    def chebyshev_recurrence(t_k_minus_one, t_k_minus_two, scaled_lap):
        s_lap = sp.csr_matrix(scaled_lap, copy=True)
        return 2 * s_lap.dot(t_k_minus_one) - t_k_minus_two

    for i in range(2, k + 1):
        t_k.append(chebyshev_recurrence(t_k[-1], t_k[-2], scaled_laplacian))
    return sparse_to_tuple(t_k) 
開發者ID:nju-websoft,項目名稱:AliNet,代碼行數:20,代碼來源:util.py

示例7: finite_gs_energy

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def finite_gs_energy(L, J, g):
    """For comparison: obtain ground state energy from exact diagonalization.

    Exponentially expensive in L, only works for small enough `L` <~ 20.
    """
    if L >= 20:
        warnings.warn("Large L: Exact diagonalization might take a long time!")
    # get single site operaors
    sx = sparse.csr_matrix(np.array([[0., 1.], [1., 0.]]))
    sz = sparse.csr_matrix(np.array([[1., 0.], [0., -1.]]))
    id = sparse.csr_matrix(np.eye(2))
    sx_list = []  # sx_list[i] = kron([id, id, ..., id, sx, id, .... id])
    sz_list = []
    for i_site in range(L):
        x_ops = [id] * L
        z_ops = [id] * L
        x_ops[i_site] = sx
        z_ops[i_site] = sz
        X = x_ops[0]
        Z = z_ops[0]
        for j in range(1, L):
            X = sparse.kron(X, x_ops[j], 'csr')
            Z = sparse.kron(Z, z_ops[j], 'csr')
        sx_list.append(X)
        sz_list.append(Z)
    H_xx = sparse.csr_matrix((2**L, 2**L))
    H_z = sparse.csr_matrix((2**L, 2**L))
    for i in range(L - 1):
        H_xx = H_xx + sx_list[i] * sx_list[(i + 1) % L]
    for i in range(L):
        H_z = H_z + sz_list[i]
    H = -J * H_xx - g * H_z
    E, V = arp.eigsh(H, k=1, which='SA', return_eigenvectors=True, ncv=20)
    return E[0] 
開發者ID:tenpy,項目名稱:tenpy,代碼行數:36,代碼來源:tfi_exact.py

示例8: _matvec

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def _matvec(self, theta):
        """Calculate |theta'> = H_eff |theta>.

        This function is used by :func:scipy.sparse.linalg.eigen.arpack.eigsh` to diagonalize
        the effective Hamiltonian with a Lanczos method, withouth generating the full matrix."""
        x = np.reshape(theta, self.theta_shape)  # vL i j vR
        x = np.tensordot(self.LP, x, axes=(2, 0))  # vL wL* [vL*], [vL] i j vR
        x = np.tensordot(x, self.W1, axes=([1, 2], [0, 3]))  # vL [wL*] [i] j vR, [wL] wC i [i*]
        x = np.tensordot(x, self.W2, axes=([3, 1], [0, 3]))  # vL [j] vR [wC] i, [wC] wR j [j*]
        x = np.tensordot(x, self.RP, axes=([1, 3], [0, 1]))  # vL [vR] i [wR] j, [vR*] [wR*] vR
        x = np.reshape(x, self.shape[0])
        return x 
開發者ID:tenpy,項目名稱:tenpy,代碼行數:14,代碼來源:d_dmrg.py

示例9: process_adj

# 需要導入模塊: from scipy.sparse.linalg.eigen import arpack [as 別名]
# 或者: from scipy.sparse.linalg.eigen.arpack import eigsh [as 別名]
def process_adj(adj, model_name):
  """Symmetrically normalize adjacency matrix."""
  if model_name == 'Cheby':
    laplacian = sp.eye(adj.shape[0]) - normalize_adj(adj - sp.eye(adj.shape[0]))
    # TODO(chamii): compare with
    # adj)
    largest_eigval, _ = eigsh(laplacian, 1, which='LM')
    laplacian_norm = (2. / largest_eigval[0]) * laplacian - sp.eye(adj.shape[0])
    return laplacian_norm
  else:
    return normalize_adj(adj) 
開發者ID:google,項目名稱:gcnn-survey-paper,代碼行數:13,代碼來源:data_utils.py


注:本文中的scipy.sparse.linalg.eigen.arpack.eigsh方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。