當前位置: 首頁>>代碼示例>>Python>>正文


Python linalg.lu_solve方法代碼示例

本文整理匯總了Python中scipy.linalg.lu_solve方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.lu_solve方法的具體用法?Python linalg.lu_solve怎麽用?Python linalg.lu_solve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scipy.linalg的用法示例。


在下文中一共展示了linalg.lu_solve方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: solve

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def solve(self, vec):
        """Solve the impedance matrix for a source vector. Caches the
        factorised matrix for efficiently solving multiple vectors"""
        if self.part_o != self.part_s:
            raise ValueError("Can only invert a self-impedance matrix")

        Z_lu = self.factored()
        if isinstance(vec, LookupArray):
            vec = vec.simple_view()

        lookup = (self.unknowns, (self.part_s, self.basis_container))

        if len(vec.shape) > 1:
            lookup = lookup+(vec.shape[1],)

        I = LookupArray(lookup, dtype=np.complex128)
        I_simp = I.simple_view()
        I_simp[:] = la.lu_solve(Z_lu, vec)
        return I 
開發者ID:DavidPowell,項目名稱:OpenModes,代碼行數:21,代碼來源:impedance.py

示例2: lu_compute_mtx_obj

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def lu_compute_mtx_obj(Tbeta_lst, num_bands, K, lu_R_GtGinv_Rt_lst):
    """
    compute the matrix (M) in the objective function:
        min   c^H M c
        s.t.  c0^H c = 1

    Parameters
    ----------
    GtG_lst: 
        list of G^H * G
    Tbeta_lst: 
        list of Teoplitz matrices for beta-s
    Rc0: 
        right dual matrix for the annihilating filter (same of each block -> not a list)
    """
    mtx = np.zeros((K + 1, K + 1), dtype=float)  # <= assume G, Tbeta and Rc0 are real-valued

    for loop in range(num_bands):
        Tbeta_loop = Tbeta_lst[loop]
        mtx += np.dot(Tbeta_loop.T,
                      linalg.lu_solve(lu_R_GtGinv_Rt_lst[loop],
                                      Tbeta_loop, check_finite=False)
                      )

    return mtx 
開發者ID:LCAV,項目名稱:pyroomacoustics,代碼行數:27,代碼來源:tools_fri_doa_plane.py

示例3: compute_obj_val

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def compute_obj_val(GtG_inv_lst, Tbeta_lst, Rc0, c_ri_half, num_bands, K):
    """
    compute the fitting error.
    CAUTION: Here we assume use_lu = True
    """
    mtx = np.zeros((K + 1, K + 1), dtype=float)  # <= assume G, Tbeta and Rc0 are real-valued
    fitting_error = 0
    for band_count in range(num_bands):
        #GtG_loop = GtG_lst[band_count]
        Tbeta_loop = Tbeta_lst[band_count]

        mtx += np.dot(Tbeta_loop.T,
                      linalg.solve(
                          np.dot(Rc0, 
                              #linalg.lu_solve(GtG_loop, Rc0.T, check_finite=False)
                              np.dot(GtG_inv_lst[band_count], Rc0.T)
                              ),
                          Tbeta_loop, check_finite=False
                      )
                      )

    fitting_error += np.sqrt(np.dot(c_ri_half.T, np.dot(mtx, c_ri_half)).real)

    return fitting_error, mtx 
開發者ID:LCAV,項目名稱:pyroomacoustics,代碼行數:26,代碼來源:tools_fri_doa_plane.py

示例4: __init__

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [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

示例5: _matvec

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def _matvec(self, x):
        return lu_solve(self.M_lu, x) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:4,代碼來源:arpack.py

示例6: solve_nonlinear

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [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: solve_linear

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def solve_linear(self, d_outputs, d_residuals, mode):
        if mode == 'fwd':
            d_outputs['circulations'] = lu_solve(self.lu, d_residuals['circulations'], trans=0)
        else:
            d_residuals['circulations'] = lu_solve(self.lu, d_outputs['circulations'], trans=1) 
開發者ID:mdolab,項目名稱:OpenAeroStruct,代碼行數:7,代碼來源:solve_matrix.py

示例8: solve_system

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def solve_system(self, rhs):
        # To do preconditioning below, we will need to scale each column of A elementwise by the entries of some vector
        col_scale = lambda A, scale: (A.T * scale).T  # Uses the trick that A*x scales the 0th column of A by x[0], etc.

        if self.factorisation_current:
            # A(preconditioned) = diag(left_scaling) * A(original) * diag(right_scaling)
            # Solve A(original)\rhs
            return col_scale(LA.lu_solve((self.lu, self.piv), col_scale(rhs, self.left_scaling)), self.right_scaling)
        else:
            if self.do_logging:
                logging.warning("model.solve_system not using factorisation")
            A, left_scaling, right_scaling = self.interpolation_matrix()
            return col_scale(LA.solve(A, col_scale(rhs, left_scaling)), right_scaling) 
開發者ID:numericalalgorithmsgroup,項目名稱:pybobyqa,代碼行數:15,代碼來源:model.py

示例9: _left_matrix_multiply

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def _left_matrix_multiply(self, other):
        return sla.lu_solve(
            self._inv_lu_and_piv, other, self._inv_lu_transposed, 
            check_finite=False) 
開發者ID:matt-graham,項目名稱:mici,代碼行數:6,代碼來源:matrices.py

示例10: _right_matrix_multiply

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def _right_matrix_multiply(self, other):
        return sla.lu_solve(
            self._inv_lu_and_piv, other.T, not self._inv_lu_transposed,
            check_finite=False).T 
開發者ID:matt-graham,項目名稱:mici,代碼行數:6,代碼來源:matrices.py

示例11: lu_solve_ATAI

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [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

示例12: lu_solve_AATI

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [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

示例13: lu_solve_ATAI

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def lu_solve_ATAI(A, rho, b, lu, piv, check_finite=True):
    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`
    check_finite : bool, optional (default False)
      Flag indicating whether the input array should be checked for Inf
      and NaN values

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

    N, M = A.shape
    if N >= M:
        x = linalg.lu_solve((lu, piv), b, check_finite=check_finite)
    else:
        x = (b - A.T.dot(linalg.lu_solve((lu, piv), A.dot(b), 1,
                                         check_finite=check_finite))) / rho
    return x 
開發者ID:bwohlberg,項目名稱:sporco,代碼行數:37,代碼來源:linalg.py

示例14: lu_solve_AATI

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def lu_solve_AATI(A, rho, b, lu, piv, check_finite=True):
    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`
    check_finite : bool, optional (default False)
      Flag indicating whether the input array should be checked for Inf
      and NaN values

    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,
                                 check_finite=check_finite).T.dot(A.T)) / rho
    else:
        x = linalg.lu_solve((lu, piv), b.T, check_finite=check_finite).T
    return x 
開發者ID:bwohlberg,項目名稱:sporco,代碼行數:37,代碼來源:linalg.py

示例15: mimo_block_arnoldi

# 需要導入模塊: from scipy import linalg [as 別名]
# 或者: from scipy.linalg import lu_solve [as 別名]
def mimo_block_arnoldi(self, frequency, r):

        n = self.ss.states

        A = self.ss.A
        B = self.ss.B
        C = self.ss.C

        for i in range(self.nfreq):

            if self.frequency[i] == np.inf:
                F = A
                G = B
            else:
                lu_a = krylovutils.lu_factor(frequency[i], A)
                F = krylovutils.lu_solve(lu_a, np.eye(n))
                G = krylovutils.lu_solve(lu_a, B)

            if i == 0:
                V = krylovutils.block_arnoldi_krylov(r, F, G)
            else:
                Vi = krylovutils.block_arnoldi_krylov(r, F, G)
                V = np.block([V, Vi])

        self.V = V

        Ar = V.T.dot(A.dot(V))
        Br = V.T.dot(B)
        Cr = C.dot(V)

        return Ar, Br, Cr 
開發者ID:ImperialCollegeLondon,項目名稱:sharpy,代碼行數:33,代碼來源:krylov.py


注:本文中的scipy.linalg.lu_solve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。