本文整理匯總了Python中scipy.sparse.linalg.factorized方法的典型用法代碼示例。如果您正苦於以下問題:Python linalg.factorized方法的具體用法?Python linalg.factorized怎麽用?Python linalg.factorized使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scipy.sparse.linalg
的用法示例。
在下文中一共展示了linalg.factorized方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: admm_phase2
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def admm_phase2(x0, prob, rho, tol=1e-2, num_iters=1000, viol_lim=1e4):
logging.info("Starting ADMM phase 2 with rho %.3f", rho)
bestx = np.copy(x0)
z = np.copy(x0)
xs = [np.copy(x0) for i in range(prob.m)]
us = [np.zeros(prob.n) for i in range(prob.m)]
if prob.rho != rho:
prob.rho = rho
zlhs = 2*(prob.f0.P + rho*prob.m*sp.identity(prob.n)).tocsc()
prob.z_solver = SLA.factorized(zlhs)
last_z = None
for t in range(num_iters):
rhs = 2*rho*(sum(xs)-sum(us)) - prob.f0.qarray
z = prob.z_solver(rhs)
# TODO: parallel x/u-updates
for i in range(prob.m):
xs[i] = onecons_qcqp(z + us[i], prob.fi(i))
for i in range(prob.m):
us[i] += z - xs[i]
# TODO: termination condition
if last_z is not None and LA.norm(last_z - z) < tol:
break
last_z = z
maxviol = max(prob.violations(z))
logging.info("Iteration %d, violation %.3f", t, maxviol)
if maxviol > viol_lim: break
bestx = np.copy(prob.better(z, bestx))
return bestx
示例2: __init__
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def __init__(self, A):
self.solve = factorized(A.tocsc()) # LU decompose
示例3: test_basic_factorized
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def test_basic_factorized():
ps.remove_stored_factorization()
ps.free_memory()
A, b = create_test_A_b_rand()
ppfact = factorized(A)
xpp = ppfact(b)
scipyfact = scipyfactorized(A)
xscipy = scipyfact(b)
np.testing.assert_array_almost_equal(xpp, xscipy)
示例4: init_solver
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def init_solver(self,L):
from scipy.sparse import linalg
self.lusolve = linalg.factorized(self.L1.tocsc())
示例5: _lufactorized
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def _lufactorized(A):
r"""Return a function for solving a sparse linear system (LU decomposition).
Parameters
----------
A : array
Matrix A represented as an (m x n) array.
Returns
-------
callable
Function to solve linear system with input matrix (n x 1).
Notes
-----
LU decomposition factors a matrix as the product of a lower triangular and
an upper triangular matrix L and U.
.. math::
\mathbf{A} = \mathbf{L} \mathbf{U}
Examples
--------
>>> fn = _lufactorized(array([[3, 2, -1], [2, -2, 4], [-1, 0.5, -1]]))
>>> fn(array([1, -2, 0]))
array([ 1., -2., -2.])
"""
return factorized(A)
示例6: init_solver
# 需要導入模塊: from scipy.sparse import linalg [as 別名]
# 或者: from scipy.sparse.linalg import factorized [as 別名]
def init_solver(self, L):
from scipy.sparse import linalg
self.lusolve = linalg.factorized(self.L1.tocsc())