本文整理匯總了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)
示例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)
示例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)
示例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)
示例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
示例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)
示例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]
示例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
示例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)