当前位置: 首页>>代码示例>>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;未经允许,请勿转载。