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

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

示例1: __init__

​点赞 6

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def __init__(self, A, M, sigma, ifunc=gmres, tol=0):

if tol <= 0:

# when tol=0, ARPACK uses machine tolerance as calculated

# by LAPACK's _LAMCH function. We should match this

tol = 2 * np.finfo(A.dtype).eps

self.A = A

self.M = M

self.sigma = sigma

self.ifunc = ifunc

self.tol = tol

x = np.zeros(A.shape[1])

if M is None:

dtype = self.mult_func_M_None(x).dtype

self.OP = LinearOperator(self.A.shape,

self.mult_func_M_None,

dtype=dtype)

else:

dtype = self.mult_func(x).dtype

self.OP = LinearOperator(self.A.shape,

self.mult_func,

dtype=dtype)

LinearOperator.__init__(self, A.shape, self._matvec, dtype=dtype)

开发者ID:ktraunmueller,项目名称:Computable,代码行数:25,

示例2: solve_system

​点赞 6

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def solve_system(self,rhs,factor,u0,t):

"""

Simple linear solver for (I-dtA)u = rhs

Args:

rhs: right-hand side for the nonlinear system

factor: abbrev. for the node-to-node stepsize (or any other factor required)

u0: initial guess for the iterative solver (not used here so far)

t: current time (e.g. for time-dependent BCs)

Returns:

solution as mesh

"""

b = rhs.values.flatten()

# NOTE: A = -M, therefore solve Id + factor*M here

sol, info = LA.gmres( self.Id + factor*self.c_s*self.M, b, x0=u0.values.flatten(), tol=1e-13, restart=10, maxiter=20)

me = mesh(self.nvars)

me.values = unflatten(sol, 3, self.N[0], self.N[1])

return me

开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:23,

示例3: solve_system

​点赞 6

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def solve_system(self, rhs, factor, u0, t):

"""

Simple linear solver for (I-factor*A)u = rhs

Args:

rhs (dtype_f): right-hand side for the linear system

factor (float): abbrev. for the local stepsize (or any other factor required)

u0 (dtype_u): initial guess for the iterative solver

t (float): current time (e.g. for time-dependent BCs)

Returns:

dtype_u: solution as mesh

"""

me = self.dtype_u(self.init)

if self.params.direct_solver:

me.values = spsolve(self.Id - factor * self.A, rhs.values.flatten())

else:

me.values = gmres(self.Id - factor * self.A, rhs.values.flatten(), x0=u0.values.flatten(),

tol=self.params.lintol, maxiter=self.params.liniter)[0]

me.values = me.values.reshape(self.params.nvars)

return me

开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:25,

示例4: __init__

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def __init__(self, M, ifunc=gmres, tol=0):

if tol <= 0:

# when tol=0, ARPACK uses machine tolerance as calculated

# by LAPACK's _LAMCH function. We should match this

tol = 2 * np.finfo(M.dtype).eps

self.M = M

self.ifunc = ifunc

self.tol = tol

if hasattr(M, 'dtype'):

self.dtype = M.dtype

else:

x = np.zeros(M.shape[1])

self.dtype = (M * x).dtype

self.shape = M.shape

开发者ID:ryfeus,项目名称:lambda-packs,代码行数:16,

示例5: SetSolver

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def SetSolver(self,linear_solver="direct", linear_solver_type="umfpack",

apply_preconditioner=False, preconditioner="amg_smoothed_aggregation",

iterative_solver_tolerance=1.0e-12, reduce_matrix_bandwidth=False,

geometric_discretisation=None):

"""

input:

linear_solver: [str] type of solver either "direct",

"iterative", "petsc" or "amg"

linear_solver_type [str] type of direct or linear solver to

use, for instance "umfpack", "superlu" or

"mumps" for direct solvers, or "cg", "gmres"

etc for iterative solvers or "amg" for algebraic

multigrid solver. See WhichSolvers method for

the complete set of available linear solvers

preconditioner: [str] either "smoothed_aggregation",

or "ruge_stuben" or "rootnode" for

a preconditioner based on algebraic multigrid

or "ilu" for scipy's spilu linear

operator

geometric_discretisation:

[str] type of geometric discretisation used, for

instance for FEM discretisations this would correspond

to "tri", "quad", "tet", "hex" etc

"""

self.solver_type = linear_solver

self.solver_subtype = "umfpack"

self.iterative_solver_tolerance = iterative_solver_tolerance

self.apply_preconditioner = apply_preconditioner

self.requires_cuthill_mckee = reduce_matrix_bandwidth

self.geometric_discretisation = geometric_discretisation

开发者ID:romeric,项目名称:florence,代码行数:38,

示例6: WhichLinearSolvers

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def WhichLinearSolvers(self):

return {"direct":["superlu", "umfpack", "mumps", "pardiso"],

"iterative":["cg", "bicg", "cgstab", "bicgstab", "gmres", "lgmres"],

"amg":["cg", "bicg", "cgstab", "bicgstab", "gmres", "lgmres"],

"petsc":["cg", "bicgstab", "gmres"]}

开发者ID:romeric,项目名称:florence,代码行数:7,

示例7: gmres_loose

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def gmres_loose(A, b, tol):

"""

gmres with looser termination condition.

"""

b = np.asarray(b)

min_tol = 1000 * np.sqrt(b.size) * np.finfo(b.dtype).eps

return gmres(A, b, tol=max(tol, min_tol), atol=0)

开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:9,

示例8: solve_system

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def solve_system(self, rhs, factor, u0, t):

"""

Simple linear solver for (I-dtA)u = rhs using GMRES

Args:

rhs (dtype_f): right-hand side for the nonlinear system

factor (float): abbrev. for the node-to-node stepsize (or any other factor required)

u0 (dtype_u): initial guess for the iterative solver (not used here so far)

t (float): current time (e.g. for time-dependent BCs)

Returns:

dtype_u: solution as mesh

"""

b = rhs.values.flatten()

cb = Callback()

sol, info = gmres(self.Id - factor * self.M, b, x0=u0.values.flatten(), tol=self.params.gmres_tol_limit,

restart=self.params.gmres_restart, maxiter=self.params.gmres_maxiter, callback=cb)

# If this is a dummy call with factor==0.0, do not log because it should not be counted as a solver call

if factor != 0.0:

self.gmres_logger.add(cb.getcounter())

me = self.dtype_u(self.init)

me.values = unflatten(sol, 4, self.N[0], self.N[1])

return me

开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:28,

示例9: f_fast_solve

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def f_fast_solve(self, rhs, alpha, u0):

cb = Callback()

sol, info = gmres(self.problem.Id - alpha * self.problem.M, rhs, x0=u0,

tol=self.problem.params.gmres_tol_limit, restart=self.problem.params.gmres_restart,

maxiter=self.problem.params.gmres_maxiter, callback=cb)

if alpha != 0.0:

self.logger.add(cb.getcounter())

return sol

#

# Trapezoidal rule

#

开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:15,

示例10: f_solve

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def f_solve(self, b, alpha, u0):

cb = Callback()

sol, info = gmres(self.problem.Id - alpha * (self.problem.D_upwind + self.problem.M), b, x0=u0,

tol=self.problem.params.gmres_tol_limit, restart=self.problem.params.gmres_restart,

maxiter=self.problem.params.gmres_maxiter, callback=cb)

if alpha != 0.0:

self.logger.add(cb.getcounter())

return sol

#

# Split-Explicit method

#

开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:15,

示例11: __init__

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def __init__(self,

A,

drop_tol=0.005,

fill_factor=2.0,

normalize_inplace=False):

# the spilu and gmres functions are most efficient with csc sparse. If the

# matrix is already csc then this will do nothing

A = sp.csc_matrix(A)

n = row_norms(A)

if normalize_inplace:

divide_rows(A, n, inplace=True)

else:

A = divide_rows(A, n, inplace=False).tocsc()

LOGGER.debug(

'computing the ILU decomposition of a %s by %s sparse matrix with %s '

'nonzeros ' % (A.shape + (A.nnz,)))

ilu = spla.spilu(

A,

drop_rule='basic',

drop_tol=drop_tol,

fill_factor=fill_factor)

LOGGER.debug('done')

M = spla.LinearOperator(A.shape, ilu.solve)

self.A = A

self.M = M

self.n = n

开发者ID:treverhines,项目名称:RBF,代码行数:29,

示例12: solve

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def solve(self, b, tol=1.0e-10):

'''

Solve `Ax = b` for `x`

Parameters

----------

b : (n,) array

tol : float, optional

Returns

-------

(n,) array

'''

# solve the system using GMRES and define the callback function to

# print info for each iteration

def callback(res, _itr=[0]):

l2 = np.linalg.norm(res)

LOGGER.debug('GMRES error on iteration %s: %s' % (_itr[0], l2))

_itr[0] += 1

LOGGER.debug('solving the system with GMRES')

x, info = spla.gmres(

self.A,

b/self.n,

tol=tol,

M=self.M,

callback=callback)

LOGGER.debug('finished GMRES with info %s' % info)

return x

开发者ID:treverhines,项目名称:RBF,代码行数:33,

示例13: krylovMethod

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def krylovMethod(self,tol=1e-8):

"""

We obtain ``pi`` by using the :func:``gmres`` solver for the system of linear equations.

It searches in Krylov subspace for a vector with minimal residual. The result is stored in the class attribute ``pi``.

Example

-------

>>> P = np.array([[0.5,0.5],[0.6,0.4]])

>>> mc = markovChain(P)

>>> mc.krylovMethod()

>>> print(mc.pi)

[ 0.54545455 0.45454545]

Parameters

----------

tol : float, optional(default=1e-8)

Tolerance level for the precision of the end result. A lower tolerance leads to more accurate estimate of ``pi``.

Remarks

-------

For large state spaces, this method may not always give a solution.

Code due to http://stackoverflow.com/questions/21308848/

"""

P = self.getIrreducibleTransitionMatrix()

#if P consists of one element, then set self.pi = 1.0

if P.shape == (1, 1):

self.pi = np.array([1.0])

return

size = P.shape[0]

dP = P - eye(size)

#Replace the first equation by the normalizing condition.

A = vstack([np.ones(size), dP.T[1:,:]]).tocsr()

rhs = np.zeros((size,))

rhs[0] = 1

pi, info = gmres(A, rhs, tol=tol)

if info != 0:

raise RuntimeError("gmres did not converge")

self.pi = pi

开发者ID:gvanderheide,项目名称:discreteMarkovChain,代码行数:43,

示例14: gmres_linsolve

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def gmres_linsolve(A, b):

"""

:param A:

:param b:

:return:

"""

x, info = gmres(A, b)

return x

开发者ID:SanPen,项目名称:GridCal,代码行数:11,

示例15: solve_gmres

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def solve_gmres(A, b):

LOG.debug(f"Solve with GMRES for {A}.")

if LOG.isEnabledFor(logging.DEBUG):

counter = Counter()

x, info = ssl.gmres(A, b, atol=1e-6, callback=counter)

LOG.debug(f"End of GMRES after {counter.nb_iter} iterations.")

else:

x, info = ssl.gmres(A, b, atol=1e-6)

if info != 0:

LOG.warning(f"No convergence of the GMRES. Error code: {info}")

return x

开发者ID:mancellin,项目名称:capytaine,代码行数:17,

示例16: gmres_no_fft

​点赞 5

# 需要导入模块: from scipy.sparse import linalg [as 别名]

# 或者: from scipy.sparse.linalg import gmres [as 别名]

def gmres_no_fft(A, b):

LOG.debug(f"Solve with GMRES for {A} without using FFT.")

x, info = ssl.gmres(A.no_toeplitz() if isinstance(A, BlockMatrix) else A, b, atol=1e-6)

if info != 0:

LOG.warning(f"No convergence of the GMRES. Error code: {info}")

return x

开发者ID:mancellin,项目名称:capytaine,代码行数:11,

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

python安装库的方法linalg_Python linalg.gmres方法代码示例相关推荐

  1. python 安装库 报错 SSL: CERTIFICATE_VERIFY_FAILED 解决方法

    目录 问题描述 临时解决方法 永久生效方法 问题描述 pip install virtualenv Collecting virtualenv /opt/python27/lib/python2.7/ ...

  2. python中turtle怎么确定坐标_关于Python turtle库使用时坐标的确定方法

    关于Python turtle库使用时坐标的确定方法 想画一个比较复杂的图像,而且还想用turtle画,最让人想退却的是无规律的笔势和繁多的坐标,但既然没有按奈住冲动的心,那我告诉你一个比较笨的方法吧 ...

  3. python安装库常用命令

    python安装库常用命令 1.python库添加与查询 添加库的方法: 1.Windows+R打开运行,然后输入CMD进入命令提示符. 2.输入:where python .就会反馈出python安 ...

  4. python 安装库 requirements.txt

    python 安装库 requirements.txt 注意 windows下用 pip linux 下用 pip3 生成库文件 pip freeze > requirements.txt 下载 ...

  5. python123九宫格输入_使用python PIL库实现简单验证码的去噪方法步骤

    字符型图片验证码识别完整过程及Python实现的博主,我的大部分知识点都是从他那里学来的. 想要识别验证码,收集足够多的样本后,首先要做的就是对验证码原始图片进行处理,对验证码识别分类之前,一般包括: ...

  6. python安装途中遇到的问题和解决方法

    python安装途中遇到的问题和解决方法 参考文章: (1)python安装途中遇到的问题和解决方法 (2)https://www.cnblogs.com/xiaowenshu/p/10239851. ...

  7. python安装库备忘

    python安装库备忘 参考 pip注意事项 python库备忘 参考 Python开发之pip使用详解 pypi pypi pip注意事项 默认安装库时按最新版本安装,可能把以前的库冲掉,造成版本不 ...

  8. 1000道Python题库系列分享15(1道代码改写题)

    考虑到前面分享题库的时候,要等下一期才给出答案,不方便大家及时核对和学习.以后改为每期在文末直接给出答案,不明白的地方可以文末留言交流,提高学习效率. ================= 问题描述: ...

  9. 电脑python安装库_Python安装第三方库的3种方法 -电脑资料

    这篇文章主要介绍了Python安装第三方库的3种方法,本文讲解了通过setuptools来安装python模块.通过pip来安装python模块.直接从网上下载下可执行文件来安装三种方法,需要的朋友可 ...

最新文章

  1. AR独角兽的死亡教训:融资3亿美元,成投资人木偶,营销大于技术
  2. 任正非:华为自己做芯片很难,咬着牙慢慢挺过来了
  3. c语言 坐标系转换 axistoradius,dynamo编程语言翻译.pdf
  4. apache 定义日志格式 及日志记录
  5. BZOJ 1084: [SCOI2005]最大子矩阵
  6. 对接口编程:接口和抽象类
  7. 意大利终于付出了代价
  8. python 按条件选择行和列数据_小白学数据结构-排序算法Python(冒泡、选择、快速、希尔等等)...
  9. 14种模式解决面试算法编程题(PART II)
  10. linux0.11 init函数,linux0.11启动与初始化
  11. 一张速查表看懂Git命令,搞定版本控制照做就ok丨新手福利
  12. 全球互联网大面积瘫痪不再是虚幻
  13. yii2 控制器添加xhprof分析
  14. 2022年茶艺师(初级)考试试题及在线模拟考试
  15. 小程序源码:全新独立后台修复登录在线答题-多玩法安装简单
  16. WebService开发--手机号码归属地查询和天气预报查询
  17. Java学习笔记 | 尚硅谷项目三详解
  18. 构建伟大的思想体系的重要性
  19. 博奥智源之软件开发系统中心机房网络管理和日常维护怎么做
  20. [转载]在Vmware ESXI中安装群晖Synology DSM 5.0 (4528)

热门文章

  1. 奋战杭电ACM(DAY10)1015
  2. 修改Oracle最大连接数
  3. 红外遥控协议-NEC协议
  4. [ES6] 细化ES6之 -- 迭代器与生成器
  5. JS-数组和函数冒泡排序递归函数
  6. Logistic混沌序列加密
  7. Linux基础(6)--文件IO操作
  8. 为什么要学Win32及Win32程序框架
  9. PocketSphinx语音识别系统的编程
  10. EasyPR车牌识别学习总结