本文整理匯總了Python中scipy.linalg.eigvals_banded方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.eigvals_banded方法的具體用法?Python linalg.eigvals_banded怎麽用?Python linalg.eigvals_banded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.linalg
的用法示例。
在下文中一共展示了linalg.eigvals_banded方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _gen_roots_and_weights
# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import eigvals_banded [as 別名]
def _gen_roots_and_weights(n, mu0, an_func, bn_func, f, df, symmetrize, mu):
"""[x,w] = gen_roots_and_weights(n,an_func,sqrt_bn_func,mu)
Returns the roots (x) of an nth order orthogonal polynomial,
and weights (w) to use in appropriate Gaussian quadrature with that
orthogonal polynomial.
The polynomials have the recurrence relation
P_n+1(x) = (x - A_n) P_n(x) - B_n P_n-1(x)
an_func(n) should return A_n
sqrt_bn_func(n) should return sqrt(B_n)
mu ( = h_0 ) is the integral of the weight over the orthogonal
interval
"""
k = np.arange(n, dtype='d')
c = np.zeros((2, n))
c[0,1:] = bn_func(k[1:])
c[1,:] = an_func(k)
x = linalg.eigvals_banded(c, overwrite_a_band=True)
# improve roots by one application of Newton's method
y = f(n, x)
dy = df(n, x)
x -= y/dy
fm = f(n-1, x)
fm /= np.abs(fm).max()
dy /= np.abs(dy).max()
w = 1.0 / (fm * dy)
if symmetrize:
w = (w + w[::-1]) / 2
x = (x - x[::-1]) / 2
w *= mu0 / w.sum()
if mu:
return x, w, mu0
else:
return x, w
# Jacobi Polynomials 1 P^(alpha,beta)_n(x)
示例2: _find_tapers_from_optimization
# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import eigvals_banded [as 別名]
def _find_tapers_from_optimization(n_time_samples_per_window, time_index,
half_bandwidth, n_tapers):
'''here we want to set up an optimization problem to find a sequence
whose energy is maximally concentrated within band
[-half_bandwidth, half_bandwidth]. Thus,
the measure lambda(T, half_bandwidth) is the ratio between the
energy within that band, and the total energy. This leads to the
eigen-system (A - (l1)I)v = 0, where the eigenvector corresponding
to the largest eigenvalue is the sequence with maximally
concentrated energy. The collection of eigenvectors of this system
are called Slepian sequences, or discrete prolate spheroidal
sequences (DPSS). Only the first K, K = 2NW/dt orders of DPSS will
exhibit good spectral concentration
[see http://en.wikipedia.org/wiki/Spectral_concentration_problem]
Here I set up an alternative symmetric tri-diagonal eigenvalue
problem such that
(B - (l2)I)v = 0, and v are our DPSS (but eigenvalues l2 != l1)
the main diagonal = ([n_time_samples_per_window-1-2*t]/2)**2 cos(2PIW),
t=[0,1,2,...,n_time_samples_per_window-1] and the first off-diagonal =
t(n_time_samples_per_window-t)/2, t=[1,2,...,
n_time_samples_per_window-1] [see Percival and Walden, 1993]'''
diagonal = (
((n_time_samples_per_window - 1 - 2 * time_index) / 2.) ** 2
* np.cos(2 * np.pi * half_bandwidth))
off_diag = np.zeros_like(time_index)
off_diag[:-1] = (
time_index[1:] * (n_time_samples_per_window - time_index[1:]) / 2.)
# put the diagonals in LAPACK 'packed' storage
ab = np.zeros((2, n_time_samples_per_window), dtype='d')
ab[1] = diagonal
ab[0, 1:] = off_diag[:-1]
# only calculate the highest n_tapers eigenvalues
w = eigvals_banded(
ab, select='i',
select_range=(n_time_samples_per_window - n_tapers,
n_time_samples_per_window - 1))
w = w[::-1]
# find the corresponding eigenvectors via inverse iteration
t = np.linspace(0, np.pi, n_time_samples_per_window)
tapers = np.zeros((n_tapers, n_time_samples_per_window), dtype='d')
for taper_ind in range(n_tapers):
tapers[taper_ind, :] = tridi_inverse_iteration(
diagonal, off_diag, w[taper_ind],
x0=np.sin((taper_ind + 1) * t))
return tapers