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


Python linalg.lu_factor方法代码示例

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


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

示例1: __init__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def __init__(self, inv_array, inv_lu_and_piv, inv_lu_transposed):
        """
        Args:
            inv_array (array): 2D array specifying inverse matrix entries.
            inv_lu_and_piv (Tuple[array, array]): Pivoted LU factorisation
                represented as a tuple with first element a 2D array containing
                the lower and upper triangular factors (with the unit diagonal
                of the lower triangular factor not stored) and the second
                element a 1D array containing the pivot indices. Corresponds
                to the output of `scipy.linalg.lu_factor` and input to
                `scipy.linalg.lu_solve`.
            inv_lu_transposed (bool): Whether LU factorisation is of inverse of
                array or transpose of inverse of array.
        """
        super().__init__(inv_array.shape)
        self._inv_array = inv_array
        self._inv_lu_and_piv = inv_lu_and_piv
        self._inv_lu_transposed = inv_lu_transposed 
开发者ID:matt-graham,项目名称:mici,代码行数:20,代码来源:matrices.py

示例2: lu_factor

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def lu_factor(sigma, A):
    """
    LU Factorisation wrapper of:

    .. math:: LU = (\sigma \mathbf{I} - \mathbf{A})

    In the case of ``A`` being a sparse matrix, the sparse methods in scipy are employed

    Args:
        sigma (float): Expansion frequency
        A (csc_matrix or np.ndarray): Dynamics matrix

    Returns:
        tuple or SuperLU: tuple (dense) or SuperLU (sparse) objects containing the LU factorisation
    """
    n = A.shape[0]
    if type(A) == libsp.csc_matrix:
        return scsp.linalg.splu(sigma * scsp.identity(n, dtype=complex, format='csc') - A)
    else:
        return sclalg.lu_factor(sigma * np.eye(n) - A) 
开发者ID:ImperialCollegeLondon,项目名称:sharpy,代码行数:22,代码来源:krylovutils.py

示例3: build_krylov_space

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def build_krylov_space(frequency, r, side, a, b):

    if frequency == np.inf or frequency.real == np.inf:
        approx_type = 'partial_realisation'
        lu_a = a
    else:
        approx_type = 'Pade'
        lu_a = lu_factor(frequency, a)

    try:
        nu = b.shape[1]
    except IndexError:
        nu = 1

    if nu == 1:
        krylov_function = construct_krylov
    else:
        krylov_function = construct_mimo_krylov

    v = krylov_function(r, lu_a, b, approx_type, side)

    return v 
开发者ID:ImperialCollegeLondon,项目名称:sharpy,代码行数:24,代码来源:krylovutils.py

示例4: __init__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def __init__(self, M):
        self.M_lu = lu_factor(M)
        self.shape = M.shape
        self.dtype = M.dtype 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:6,代码来源:arpack.py

示例5: __init__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def __init__(self, M):
        self.M_lu = lu_factor(M)
        LinearOperator.__init__(self, M.shape, self._matvec, dtype=M.dtype) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:arpack.py

示例6: solve_nonlinear

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def solve_nonlinear(self, inputs, outputs):
        self.lu = lu_factor(inputs['mtx'])

        outputs['circulations'] = lu_solve(self.lu, inputs['rhs']) 
开发者ID:mdolab,项目名称:OpenAeroStruct,代码行数:6,代码来源:solve_matrix.py

示例7: linearize

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def linearize(self, inputs, outputs, partials):
        system_size = self.system_size
        self.lu = lu_factor(inputs['mtx'])

        partials['circulations', 'circulations'] = inputs['mtx'].flatten()
        partials['circulations', 'mtx'] = \
            np.outer(np.ones(system_size), outputs['circulations']).flatten() 
开发者ID:mdolab,项目名称:OpenAeroStruct,代码行数:9,代码来源:solve_matrix.py

示例8: statdist

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def statdist(generator):
    """Compute the stationary distribution of a Markov chain.

    Parameters
    ----------
    generator : array_like
        Infinitesimal generator matrix of the Markov chain.

    Returns
    -------
    dist : numpy.ndarray
        The unnormalized stationary distribution of the Markov chain.

    Raises
    ------
    ValueError
        If the Markov chain does not have a unique stationary distribution.
    """
    generator = np.asarray(generator)
    n = generator.shape[0]
    with warnings.catch_warnings():
        # The LU decomposition raises a warning when the generator matrix is
        # singular (which it, by construction, is!).
        warnings.filterwarnings("ignore")
        lu, piv = spl.lu_factor(generator.T, check_finite=False)
    # The last row contains 0's only.
    left = lu[:-1,:-1]
    right = -lu[:-1,-1]
    # Solves system `left * x = right`. Assumes that `left` is
    # upper-triangular (ignores lower triangle).
    try:
        res = spl.solve_triangular(left, right, check_finite=False)
    except:
        # Ideally we would like to catch `spl.LinAlgError` only, but there seems
        # to be a bug in scipy, in the code that raises the LinAlgError (!!).
        raise ValueError(
                "stationary distribution could not be computed. "
                "Perhaps the Markov chain has more than one absorbing class?")
    res = np.append(res, 1.0)
    return (n / res.sum()) * res 
开发者ID:lucasmaystre,项目名称:choix,代码行数:42,代码来源:utils.py

示例9: factorise_interp_matrix

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def factorise_interp_matrix(self):
        if not self.factorisation_current:
            A, self.left_scaling, self.right_scaling = self.interpolation_matrix()
            self.lu, self.piv = LA.lu_factor(A)
            self.factorisation_current = True
        return 
开发者ID:numericalalgorithmsgroup,项目名称:pybobyqa,代码行数:8,代码来源:model.py

示例10: factored

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def factored(self):
        "Caches the LU factorisation of the matrix"
        try:
            return self.lu_factored
        except AttributeError:
            self.lu_factored = la.lu_factor(self.val().simple_view())
            return self.lu_factored 
开发者ID:DavidPowell,项目名称:OpenModes,代码行数:9,代码来源:impedance.py

示例11: lu_and_piv

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def lu_and_piv(self):
        """Pivoted LU factorisation of matrix."""
        if self._lu_and_piv is None:
            self._lu_and_piv = sla.lu_factor(self._array, check_finite=False)
            self._lu_transposed = False
        return self._lu_and_piv 
开发者ID:matt-graham,项目名称:mici,代码行数:8,代码来源:matrices.py

示例12: __init__

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def __init__(self):
        matrix_pairs = {}
        rng = np.random.RandomState(SEED)
        for sz in SIZES:
            for transposed in [True, False]:
                inverse_array = rng.standard_normal((sz, sz))
                inverse_lu_and_piv = sla.lu_factor(
                    inverse_array.T if transposed else inverse_array)
                array = nla.inv(inverse_array)
                matrix_pairs[(sz, transposed)] = (
                    matrices.InverseLUFactoredSquareMatrix(
                        inverse_array, inverse_lu_and_piv, transposed), array)
            super().__init__(matrix_pairs, rng) 
开发者ID:matt-graham,项目名称:mici,代码行数:15,代码来源:test_matrices.py

示例13: lu_factor

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def lu_factor(A, rho):
    r"""
    Compute LU factorisation of either :math:`A^T A + \rho I` or
    :math:`A A^T + \rho I`, depending on which matrix is smaller.

    Parameters
    ----------
    A : array_like
      Array :math:`A`
    rho : float
      Scalar :math:`\rho`

    Returns
    -------
    lu : ndarray
      Matrix containing U in its upper triangle, and L in its lower triangle,
      as returned by :func:`scipy.linalg.lu_factor`
    piv : ndarray
      Pivot indices representing the permutation matrix P, as returned by
      :func:`scipy.linalg.lu_factor`
    """

    N, M = A.shape
    # If N < M it is cheaper to factorise A*A^T + rho*I and then use the
    # matrix inversion lemma to compute the inverse of A^T*A + rho*I
    if N >= M:
        lu, piv = linalg.lu_factor(A.T.dot(A) + rho*np.identity(M,
                                   dtype=A.dtype))
    else:
        lu, piv = linalg.lu_factor(A.dot(A.T) + rho*np.identity(N,
                                   dtype=A.dtype))
    return lu, piv 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:34,代码来源:linalg.py

示例14: lu_solve_ATAI

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def lu_solve_ATAI(A, rho, b, lu, piv):
    r"""
    Solve the linear system :math:`(A^T A + \rho I)\mathbf{x} = \mathbf{b}`
    or :math:`(A^T A + \rho I)X = B` using :func:`scipy.linalg.lu_solve`.

    Parameters
    ----------
    A : array_like
      Matrix :math:`A`
    rho : float
      Scalar :math:`\rho`
    b : array_like
      Vector :math:`\mathbf{b}` or matrix :math:`B`
    lu : array_like
      Matrix containing U in its upper triangle, and L in its lower triangle,
      as returned by :func:`scipy.linalg.lu_factor`
    piv : array_like
      Pivot indices representing the permutation matrix P, as returned by
      :func:`scipy.linalg.lu_factor`

    Returns
    -------
    x : ndarray
      Solution to the linear system.
    """

    N, M = A.shape
    if N >= M:
        x = linalg.lu_solve((lu, piv), b)
    else:
        x = (b - A.T.dot(linalg.lu_solve((lu, piv), A.dot(b), 1))) / rho
    return x 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:34,代码来源:linalg.py

示例15: lu_solve_AATI

# 需要导入模块: from scipy import linalg [as 别名]
# 或者: from scipy.linalg import lu_factor [as 别名]
def lu_solve_AATI(A, rho, b, lu, piv):
    r"""
    Solve the linear system :math:`(A A^T + \rho I)\mathbf{x} = \mathbf{b}`
    or :math:`(A A^T + \rho I)X = B` using :func:`scipy.linalg.lu_solve`.

    Parameters
    ----------
    A : array_like
      Matrix :math:`A`
    rho : float
      Scalar :math:`\rho`
    b : array_like
      Vector :math:`\mathbf{b}` or matrix :math:`B`
    lu : array_like
      Matrix containing U in its upper triangle, and L in its lower triangle,
      as returned by :func:`scipy.linalg.lu_factor`
    piv : array_like
      Pivot indices representing the permutation matrix P, as returned by
      :func:`scipy.linalg.lu_factor`

    Returns
    -------
    x : ndarray
      Solution to the linear system.
    """

    N, M = A.shape
    if N >= M:
        x = (b - linalg.lu_solve((lu, piv), b.dot(A).T).T.dot(A.T)) / rho
    else:
        x = linalg.lu_solve((lu, piv), b.T).T
    return x 
开发者ID:alphacsc,项目名称:alphacsc,代码行数:34,代码来源:linalg.py


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