本文整理汇总了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())