当前位置: 首页>>代码示例>>Python>>正文


Python scipy.linalg方法代码示例

本文整理汇总了Python中scipy.linalg方法的典型用法代码示例。如果您正苦于以下问题:Python scipy.linalg方法的具体用法?Python scipy.linalg怎么用?Python scipy.linalg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy的用法示例。


在下文中一共展示了scipy.linalg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_k

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def get_k(self,dm):
        """
        Update Exact Exchange Matrix

        Args:
            dm: float or complex
                AO density matrix.
        Returns:
            kmat: float or complex
                Exact Exchange in AO basis
        """
        naux = self.auxmol.nao_nr()
        nao = self.ks.mol.nao_nr()
        kpj = np.einsum("ijp,jk->ikp", self.eri3c, dm)
        pik = np.linalg.solve(self.eri2c, kpj.reshape(-1,naux).T.conj())
        kmat = np.einsum("pik,kjp->ij", pik.reshape(naux,nao,nao), self.eri3c)
        return kmat 
开发者ID:pyscf,项目名称:pyscf,代码行数:19,代码来源:tdscf.py

示例2: __init__

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def __init__(self, linear_operator, linear_operator_diagonal, options=None):
        """
        Args:
            linear_operator(scipy.sparse.linalg.LinearOperator): The linear
                operator which defines a dot function when applying on a vector.
            linear_operator_diagonal(numpy.ndarray): The linear operator's
                diagonal elements.
            options(DavidsonOptions): Iteration options.
        """
        if options is None:
            options = DavidsonOptions()

        if not isinstance(linear_operator,
                          (scipy.sparse.linalg.LinearOperator,
                           scipy.sparse.spmatrix)):
            raise ValueError(
                'linear_operator is not a LinearOperator: {}.'.format(type(
                    linear_operator)))

        self.linear_operator = linear_operator
        self.linear_operator_diagonal = linear_operator_diagonal

        self.options = options
        self.options.set_dimension(len(linear_operator_diagonal)) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:26,代码来源:_davidson.py

示例3: generate_random_vectors

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def generate_random_vectors(row, col, real_only=False):
    """Generates orthonormal random vectors with col columns.

    Args:
        row(int): Number of rows for the vectors.
        col(int): Number of columns for the vectors.
        real_only(bool): Real vectors or complex ones.

    Returns:
        random_vectors(numpy.ndarray(complex)): Orthonormal random vectors.
    """
    random_vectors = numpy.random.rand(row, col)
    if not real_only:
        random_vectors = random_vectors + numpy.random.rand(row, col) * 1.0j
    random_vectors = scipy.linalg.orth(random_vectors)
    return random_vectors 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:18,代码来源:_davidson.py

示例4: drss

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def drss(num_states, num_inputs, num_outputs):
    """Generates a discrete-time random state-space system.

    Args:
        ``num_states``: Number of states.

        ``num_inputs``: Number of inputs.

        ``num_outputs``: Number of outputs.

    Returns:
        ``A``, ``B``, ``C``: State-space arrays of discrete-time system.

    By construction, all eigenvalues are real and stable.
    """
    # eig_vals = np.linspace(.9, .95, num_states)
    # eig_vecs = np.random.normal(0, 2., (num_states, num_states))
    eig_vals = np.linspace(.2, .95, num_states)
    eig_vecs = np.random.normal(0, 2., (num_states, num_states))
    A = np.real(
        np.linalg.inv(eig_vecs).dot(np.diag(eig_vals).dot(eig_vecs)))
    B = np.random.normal(0, 1., (num_states, num_inputs))
    C = np.random.normal(0, 1., (num_outputs, num_states))
    return A, B, C 
开发者ID:belson17,项目名称:modred,代码行数:26,代码来源:util.py

示例5: __call__

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def __call__(self, A):
        errString = "can only call scipy.linalg.expm on square arrays"
        if not isinstance(A, PureNumpy.PurePythonNumpyArray):
            raise TypeError(errString)
        if A.shape[0] != A.shape[1]:
            raise TypeError(errString)
            
        result = __inline_fora(
            """fun(@unnamed_args:(matrix), *args) {
                   return purePython.linalgModule.expm(
                       matrix
                       )
                   }"""
            )(A)

        return PureNumpy.PurePythonNumpyArray(
            tuple(result[1]),
            result[0]
            ) 
开发者ID:ufora,项目名称:ufora,代码行数:21,代码来源:pure_scipy.py

示例6: set_corr

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def set_corr(self, R):
		"""
		Set the Correlation matrix of the copula.

		Parameters
		----------
		R : numpy array (of size copula dimensions * copula dimension)
			The definite positive correlation matrix. Note that you should check yourself if the matrix is definite positive.
		"""
		S = np.asarray(R)
		if len(S.shape) > 2:
			raise ValueError("2-dimensional array expected, get {0}-dimensional array.".format(len(S.shape)))
		if S.shape[0] != S.shape[1]:
			raise ValueError("Correlation matrix must be a squared matrix of dimension {0}".format(self.dim))
		if not(np.array_equal(np.transpose(S), S)):
			raise ValueError("Correlation matrix is not symmetric.")
		self.R = S
		self._R_det = np.linalg.det(S)
		self._R_inv = np.linalg.inv(S) 
开发者ID:blent-ai,项目名称:pycopula,代码行数:21,代码来源:copula.py

示例7: test_eigsh_valid_init_operator_with_shape

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_valid_init_operator_with_shape(dtype):
  backend = numpy_backend.NumPyBackend()
  D = 16
  np.random.seed(10)
  init = backend.randn((D,), dtype=dtype, seed=10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], init)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:21,代码来源:numpy_backend_test.py

示例8: test_eigsh_lanczos_1

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_lanczos_1(dtype):
  backend = numpy_backend.NumPyBackend()
  D = 16
  np.random.seed(10)
  init = backend.randn((D,), dtype=dtype, seed=10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], init)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:21,代码来源:numpy_backend_test.py

示例9: test_eigsh_lanczos_2

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_lanczos_2(dtype):
  backend = numpy_backend.NumPyBackend()
  D = 16
  np.random.seed(10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], shape=(D,), dtype=dtype)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:20,代码来源:numpy_backend_test.py

示例10: test_eigs

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigs(dtype, which):

  backend = numpy_backend.NumPyBackend()
  D = 16
  np.random.seed(10)
  init = backend.randn((D,), dtype=dtype, seed=10)
  M = backend.randn((D, D), dtype=dtype, seed=10)

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigs(mv, [M], init, numeig=1, which=which)
  eta2, U2 = np.linalg.eig(M)
  val, index = find(which, eta2)
  v2 = U2[:, index]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(find(which, eta1)[0], val)
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:22,代码来源:numpy_backend_test.py

示例11: test_eigs_no_init

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigs_no_init(which):
  backend = numpy_backend.NumPyBackend()
  dtype = np.complex128
  D = 16
  np.random.seed(10)
  H = backend.randn((D, D), dtype=dtype, seed=10)

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigs(
      mv, [H], shape=(D,), dtype=dtype, numeig=1, which=which)
  eta2, U2 = np.linalg.eig(H)
  val, index = find(which, eta2)
  v2 = U2[:, index]
  v2 = v2 / np.sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / np.sum(v1)
  np.testing.assert_allclose(find(which, eta1)[0], val)
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:22,代码来源:numpy_backend_test.py

示例12: test_eigs_init

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigs_init(dtype, which):
  backend = numpy_backend.NumPyBackend()
  D = 16
  np.random.seed(10)
  H = backend.randn((D, D), dtype=dtype, seed=10)
  init = backend.randn((D,), dtype=dtype)

  def mv(x, mat):
    return np.dot(mat, x)

  eta1, U1 = backend.eigs(mv, [H], initial_state=init, numeig=1, which=which)
  eta2, U2 = np.linalg.eig(H)
  val, index = find(which, eta2)
  v2 = U2[:, index]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(find(which, eta1)[0], val)
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:21,代码来源:numpy_backend_test.py

示例13: test_eigsh_valid_init_operator_with_shape

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_valid_init_operator_with_shape(dtype):
  backend = jax_backend.JaxBackend()
  D = 16
  np.random.seed(10)
  init = backend.randn((D,), dtype=dtype, seed=10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, H):
    return jax.numpy.dot(H, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], init)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:21,代码来源:jax_backend_test.py

示例14: test_eigsh_lanczos_1

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_lanczos_1(dtype):
  backend = jax_backend.JaxBackend()
  D = 16
  np.random.seed(10)
  init = backend.randn((D,), dtype=dtype, seed=10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, H):
    return jax.numpy.dot(H, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], init)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:21,代码来源:jax_backend_test.py

示例15: test_eigsh_lanczos_2

# 需要导入模块: import scipy [as 别名]
# 或者: from scipy import linalg [as 别名]
def test_eigsh_lanczos_2(dtype):
  backend = jax_backend.JaxBackend()
  D = 16
  np.random.seed(10)
  tmp = backend.randn((D, D), dtype=dtype, seed=10)
  H = tmp + backend.transpose(backend.conj(tmp), (1, 0))

  def mv(x, H):
    return jax.numpy.dot(H, x)

  eta1, U1 = backend.eigsh_lanczos(mv, [H], shape=(D,), dtype=dtype)
  eta2, U2 = np.linalg.eigh(H)
  v2 = U2[:, 0]
  v2 = v2 / sum(v2)
  v1 = np.reshape(U1[0], (D))
  v1 = v1 / sum(v1)
  np.testing.assert_allclose(eta1[0], min(eta2))
  np.testing.assert_allclose(v1, v2) 
开发者ID:google,项目名称:TensorNetwork,代码行数:20,代码来源:jax_backend_test.py


注:本文中的scipy.linalg方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。