_root.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. """
  2. Unified interfaces to root finding algorithms.
  3. Functions
  4. ---------
  5. - root : find a root of a vector function.
  6. """
  7. from __future__ import division, print_function, absolute_import
  8. __all__ = ['root']
  9. import numpy as np
  10. from scipy._lib.six import callable
  11. from warnings import warn
  12. from .optimize import MemoizeJac, OptimizeResult, _check_unknown_options
  13. from .minpack import _root_hybr, leastsq
  14. from ._spectral import _root_df_sane
  15. from . import nonlin
  16. def root(fun, x0, args=(), method='hybr', jac=None, tol=None, callback=None,
  17. options=None):
  18. """
  19. Find a root of a vector function.
  20. Parameters
  21. ----------
  22. fun : callable
  23. A vector function to find a root of.
  24. x0 : ndarray
  25. Initial guess.
  26. args : tuple, optional
  27. Extra arguments passed to the objective function and its Jacobian.
  28. method : str, optional
  29. Type of solver. Should be one of
  30. - 'hybr' :ref:`(see here) <optimize.root-hybr>`
  31. - 'lm' :ref:`(see here) <optimize.root-lm>`
  32. - 'broyden1' :ref:`(see here) <optimize.root-broyden1>`
  33. - 'broyden2' :ref:`(see here) <optimize.root-broyden2>`
  34. - 'anderson' :ref:`(see here) <optimize.root-anderson>`
  35. - 'linearmixing' :ref:`(see here) <optimize.root-linearmixing>`
  36. - 'diagbroyden' :ref:`(see here) <optimize.root-diagbroyden>`
  37. - 'excitingmixing' :ref:`(see here) <optimize.root-excitingmixing>`
  38. - 'krylov' :ref:`(see here) <optimize.root-krylov>`
  39. - 'df-sane' :ref:`(see here) <optimize.root-dfsane>`
  40. jac : bool or callable, optional
  41. If `jac` is a Boolean and is True, `fun` is assumed to return the
  42. value of Jacobian along with the objective function. If False, the
  43. Jacobian will be estimated numerically.
  44. `jac` can also be a callable returning the Jacobian of `fun`. In
  45. this case, it must accept the same arguments as `fun`.
  46. tol : float, optional
  47. Tolerance for termination. For detailed control, use solver-specific
  48. options.
  49. callback : function, optional
  50. Optional callback function. It is called on every iteration as
  51. ``callback(x, f)`` where `x` is the current solution and `f`
  52. the corresponding residual. For all methods but 'hybr' and 'lm'.
  53. options : dict, optional
  54. A dictionary of solver options. E.g. `xtol` or `maxiter`, see
  55. :obj:`show_options()` for details.
  56. Returns
  57. -------
  58. sol : OptimizeResult
  59. The solution represented as a ``OptimizeResult`` object.
  60. Important attributes are: ``x`` the solution array, ``success`` a
  61. Boolean flag indicating if the algorithm exited successfully and
  62. ``message`` which describes the cause of the termination. See
  63. `OptimizeResult` for a description of other attributes.
  64. See also
  65. --------
  66. show_options : Additional options accepted by the solvers
  67. Notes
  68. -----
  69. This section describes the available solvers that can be selected by the
  70. 'method' parameter. The default method is *hybr*.
  71. Method *hybr* uses a modification of the Powell hybrid method as
  72. implemented in MINPACK [1]_.
  73. Method *lm* solves the system of nonlinear equations in a least squares
  74. sense using a modification of the Levenberg-Marquardt algorithm as
  75. implemented in MINPACK [1]_.
  76. Method *df-sane* is a derivative-free spectral method. [3]_
  77. Methods *broyden1*, *broyden2*, *anderson*, *linearmixing*,
  78. *diagbroyden*, *excitingmixing*, *krylov* are inexact Newton methods,
  79. with backtracking or full line searches [2]_. Each method corresponds
  80. to a particular Jacobian approximations. See `nonlin` for details.
  81. - Method *broyden1* uses Broyden's first Jacobian approximation, it is
  82. known as Broyden's good method.
  83. - Method *broyden2* uses Broyden's second Jacobian approximation, it
  84. is known as Broyden's bad method.
  85. - Method *anderson* uses (extended) Anderson mixing.
  86. - Method *Krylov* uses Krylov approximation for inverse Jacobian. It
  87. is suitable for large-scale problem.
  88. - Method *diagbroyden* uses diagonal Broyden Jacobian approximation.
  89. - Method *linearmixing* uses a scalar Jacobian approximation.
  90. - Method *excitingmixing* uses a tuned diagonal Jacobian
  91. approximation.
  92. .. warning::
  93. The algorithms implemented for methods *diagbroyden*,
  94. *linearmixing* and *excitingmixing* may be useful for specific
  95. problems, but whether they will work may depend strongly on the
  96. problem.
  97. .. versionadded:: 0.11.0
  98. References
  99. ----------
  100. .. [1] More, Jorge J., Burton S. Garbow, and Kenneth E. Hillstrom.
  101. 1980. User Guide for MINPACK-1.
  102. .. [2] C. T. Kelley. 1995. Iterative Methods for Linear and Nonlinear
  103. Equations. Society for Industrial and Applied Mathematics.
  104. <https://archive.siam.org/books/kelley/fr16/>
  105. .. [3] W. La Cruz, J.M. Martinez, M. Raydan. Math. Comp. 75, 1429 (2006).
  106. Examples
  107. --------
  108. The following functions define a system of nonlinear equations and its
  109. jacobian.
  110. >>> def fun(x):
  111. ... return [x[0] + 0.5 * (x[0] - x[1])**3 - 1.0,
  112. ... 0.5 * (x[1] - x[0])**3 + x[1]]
  113. >>> def jac(x):
  114. ... return np.array([[1 + 1.5 * (x[0] - x[1])**2,
  115. ... -1.5 * (x[0] - x[1])**2],
  116. ... [-1.5 * (x[1] - x[0])**2,
  117. ... 1 + 1.5 * (x[1] - x[0])**2]])
  118. A solution can be obtained as follows.
  119. >>> from scipy import optimize
  120. >>> sol = optimize.root(fun, [0, 0], jac=jac, method='hybr')
  121. >>> sol.x
  122. array([ 0.8411639, 0.1588361])
  123. """
  124. if not isinstance(args, tuple):
  125. args = (args,)
  126. meth = method.lower()
  127. if options is None:
  128. options = {}
  129. if callback is not None and meth in ('hybr', 'lm'):
  130. warn('Method %s does not accept callback.' % method,
  131. RuntimeWarning)
  132. # fun also returns the jacobian
  133. if not callable(jac) and meth in ('hybr', 'lm'):
  134. if bool(jac):
  135. fun = MemoizeJac(fun)
  136. jac = fun.derivative
  137. else:
  138. jac = None
  139. # set default tolerances
  140. if tol is not None:
  141. options = dict(options)
  142. if meth in ('hybr', 'lm'):
  143. options.setdefault('xtol', tol)
  144. elif meth in ('df-sane',):
  145. options.setdefault('ftol', tol)
  146. elif meth in ('broyden1', 'broyden2', 'anderson', 'linearmixing',
  147. 'diagbroyden', 'excitingmixing', 'krylov'):
  148. options.setdefault('xtol', tol)
  149. options.setdefault('xatol', np.inf)
  150. options.setdefault('ftol', np.inf)
  151. options.setdefault('fatol', np.inf)
  152. if meth == 'hybr':
  153. sol = _root_hybr(fun, x0, args=args, jac=jac, **options)
  154. elif meth == 'lm':
  155. sol = _root_leastsq(fun, x0, args=args, jac=jac, **options)
  156. elif meth == 'df-sane':
  157. _warn_jac_unused(jac, method)
  158. sol = _root_df_sane(fun, x0, args=args, callback=callback,
  159. **options)
  160. elif meth in ('broyden1', 'broyden2', 'anderson', 'linearmixing',
  161. 'diagbroyden', 'excitingmixing', 'krylov'):
  162. _warn_jac_unused(jac, method)
  163. sol = _root_nonlin_solve(fun, x0, args=args, jac=jac,
  164. _method=meth, _callback=callback,
  165. **options)
  166. else:
  167. raise ValueError('Unknown solver %s' % method)
  168. return sol
  169. def _warn_jac_unused(jac, method):
  170. if jac is not None:
  171. warn('Method %s does not use the jacobian (jac).' % (method,),
  172. RuntimeWarning)
  173. def _root_leastsq(func, x0, args=(), jac=None,
  174. col_deriv=0, xtol=1.49012e-08, ftol=1.49012e-08,
  175. gtol=0.0, maxiter=0, eps=0.0, factor=100, diag=None,
  176. **unknown_options):
  177. """
  178. Solve for least squares with Levenberg-Marquardt
  179. Options
  180. -------
  181. col_deriv : bool
  182. non-zero to specify that the Jacobian function computes derivatives
  183. down the columns (faster, because there is no transpose operation).
  184. ftol : float
  185. Relative error desired in the sum of squares.
  186. xtol : float
  187. Relative error desired in the approximate solution.
  188. gtol : float
  189. Orthogonality desired between the function vector and the columns
  190. of the Jacobian.
  191. maxiter : int
  192. The maximum number of calls to the function. If zero, then
  193. 100*(N+1) is the maximum where N is the number of elements in x0.
  194. epsfcn : float
  195. A suitable step length for the forward-difference approximation of
  196. the Jacobian (for Dfun=None). If epsfcn is less than the machine
  197. precision, it is assumed that the relative errors in the functions
  198. are of the order of the machine precision.
  199. factor : float
  200. A parameter determining the initial step bound
  201. (``factor * || diag * x||``). Should be in interval ``(0.1, 100)``.
  202. diag : sequence
  203. N positive entries that serve as a scale factors for the variables.
  204. """
  205. _check_unknown_options(unknown_options)
  206. x, cov_x, info, msg, ier = leastsq(func, x0, args=args, Dfun=jac,
  207. full_output=True,
  208. col_deriv=col_deriv, xtol=xtol,
  209. ftol=ftol, gtol=gtol,
  210. maxfev=maxiter, epsfcn=eps,
  211. factor=factor, diag=diag)
  212. sol = OptimizeResult(x=x, message=msg, status=ier,
  213. success=ier in (1, 2, 3, 4), cov_x=cov_x,
  214. fun=info.pop('fvec'))
  215. sol.update(info)
  216. return sol
  217. def _root_nonlin_solve(func, x0, args=(), jac=None,
  218. _callback=None, _method=None,
  219. nit=None, disp=False, maxiter=None,
  220. ftol=None, fatol=None, xtol=None, xatol=None,
  221. tol_norm=None, line_search='armijo', jac_options=None,
  222. **unknown_options):
  223. _check_unknown_options(unknown_options)
  224. f_tol = fatol
  225. f_rtol = ftol
  226. x_tol = xatol
  227. x_rtol = xtol
  228. verbose = disp
  229. if jac_options is None:
  230. jac_options = dict()
  231. jacobian = {'broyden1': nonlin.BroydenFirst,
  232. 'broyden2': nonlin.BroydenSecond,
  233. 'anderson': nonlin.Anderson,
  234. 'linearmixing': nonlin.LinearMixing,
  235. 'diagbroyden': nonlin.DiagBroyden,
  236. 'excitingmixing': nonlin.ExcitingMixing,
  237. 'krylov': nonlin.KrylovJacobian
  238. }[_method]
  239. if args:
  240. if jac:
  241. def f(x):
  242. return func(x, *args)[0]
  243. else:
  244. def f(x):
  245. return func(x, *args)
  246. else:
  247. f = func
  248. x, info = nonlin.nonlin_solve(f, x0, jacobian=jacobian(**jac_options),
  249. iter=nit, verbose=verbose,
  250. maxiter=maxiter, f_tol=f_tol,
  251. f_rtol=f_rtol, x_tol=x_tol,
  252. x_rtol=x_rtol, tol_norm=tol_norm,
  253. line_search=line_search,
  254. callback=_callback, full_output=True,
  255. raise_exception=False)
  256. sol = OptimizeResult(x=x)
  257. sol.update(info)
  258. return sol
  259. def _root_broyden1_doc():
  260. """
  261. Options
  262. -------
  263. nit : int, optional
  264. Number of iterations to make. If omitted (default), make as many
  265. as required to meet tolerances.
  266. disp : bool, optional
  267. Print status to stdout on every iteration.
  268. maxiter : int, optional
  269. Maximum number of iterations to make. If more are needed to
  270. meet convergence, `NoConvergence` is raised.
  271. ftol : float, optional
  272. Relative tolerance for the residual. If omitted, not used.
  273. fatol : float, optional
  274. Absolute tolerance (in max-norm) for the residual.
  275. If omitted, default is 6e-6.
  276. xtol : float, optional
  277. Relative minimum step size. If omitted, not used.
  278. xatol : float, optional
  279. Absolute minimum step size, as determined from the Jacobian
  280. approximation. If the step size is smaller than this, optimization
  281. is terminated as successful. If omitted, not used.
  282. tol_norm : function(vector) -> scalar, optional
  283. Norm to use in convergence check. Default is the maximum norm.
  284. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  285. Which type of a line search to use to determine the step size in
  286. the direction given by the Jacobian approximation. Defaults to
  287. 'armijo'.
  288. jac_options : dict, optional
  289. Options for the respective Jacobian approximation.
  290. alpha : float, optional
  291. Initial guess for the Jacobian is (-1/alpha).
  292. reduction_method : str or tuple, optional
  293. Method used in ensuring that the rank of the Broyden
  294. matrix stays low. Can either be a string giving the
  295. name of the method, or a tuple of the form ``(method,
  296. param1, param2, ...)`` that gives the name of the
  297. method and values for additional parameters.
  298. Methods available:
  299. - ``restart``: drop all matrix columns. Has no
  300. extra parameters.
  301. - ``simple``: drop oldest matrix column. Has no
  302. extra parameters.
  303. - ``svd``: keep only the most significant SVD
  304. components.
  305. Extra parameters:
  306. - ``to_retain``: number of SVD components to
  307. retain when rank reduction is done.
  308. Default is ``max_rank - 2``.
  309. max_rank : int, optional
  310. Maximum rank for the Broyden matrix.
  311. Default is infinity (ie., no rank reduction).
  312. """
  313. pass
  314. def _root_broyden2_doc():
  315. """
  316. Options
  317. -------
  318. nit : int, optional
  319. Number of iterations to make. If omitted (default), make as many
  320. as required to meet tolerances.
  321. disp : bool, optional
  322. Print status to stdout on every iteration.
  323. maxiter : int, optional
  324. Maximum number of iterations to make. If more are needed to
  325. meet convergence, `NoConvergence` is raised.
  326. ftol : float, optional
  327. Relative tolerance for the residual. If omitted, not used.
  328. fatol : float, optional
  329. Absolute tolerance (in max-norm) for the residual.
  330. If omitted, default is 6e-6.
  331. xtol : float, optional
  332. Relative minimum step size. If omitted, not used.
  333. xatol : float, optional
  334. Absolute minimum step size, as determined from the Jacobian
  335. approximation. If the step size is smaller than this, optimization
  336. is terminated as successful. If omitted, not used.
  337. tol_norm : function(vector) -> scalar, optional
  338. Norm to use in convergence check. Default is the maximum norm.
  339. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  340. Which type of a line search to use to determine the step size in
  341. the direction given by the Jacobian approximation. Defaults to
  342. 'armijo'.
  343. jac_options : dict, optional
  344. Options for the respective Jacobian approximation.
  345. alpha : float, optional
  346. Initial guess for the Jacobian is (-1/alpha).
  347. reduction_method : str or tuple, optional
  348. Method used in ensuring that the rank of the Broyden
  349. matrix stays low. Can either be a string giving the
  350. name of the method, or a tuple of the form ``(method,
  351. param1, param2, ...)`` that gives the name of the
  352. method and values for additional parameters.
  353. Methods available:
  354. - ``restart``: drop all matrix columns. Has no
  355. extra parameters.
  356. - ``simple``: drop oldest matrix column. Has no
  357. extra parameters.
  358. - ``svd``: keep only the most significant SVD
  359. components.
  360. Extra parameters:
  361. - ``to_retain``: number of SVD components to
  362. retain when rank reduction is done.
  363. Default is ``max_rank - 2``.
  364. max_rank : int, optional
  365. Maximum rank for the Broyden matrix.
  366. Default is infinity (ie., no rank reduction).
  367. """
  368. pass
  369. def _root_anderson_doc():
  370. """
  371. Options
  372. -------
  373. nit : int, optional
  374. Number of iterations to make. If omitted (default), make as many
  375. as required to meet tolerances.
  376. disp : bool, optional
  377. Print status to stdout on every iteration.
  378. maxiter : int, optional
  379. Maximum number of iterations to make. If more are needed to
  380. meet convergence, `NoConvergence` is raised.
  381. ftol : float, optional
  382. Relative tolerance for the residual. If omitted, not used.
  383. fatol : float, optional
  384. Absolute tolerance (in max-norm) for the residual.
  385. If omitted, default is 6e-6.
  386. xtol : float, optional
  387. Relative minimum step size. If omitted, not used.
  388. xatol : float, optional
  389. Absolute minimum step size, as determined from the Jacobian
  390. approximation. If the step size is smaller than this, optimization
  391. is terminated as successful. If omitted, not used.
  392. tol_norm : function(vector) -> scalar, optional
  393. Norm to use in convergence check. Default is the maximum norm.
  394. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  395. Which type of a line search to use to determine the step size in
  396. the direction given by the Jacobian approximation. Defaults to
  397. 'armijo'.
  398. jac_options : dict, optional
  399. Options for the respective Jacobian approximation.
  400. alpha : float, optional
  401. Initial guess for the Jacobian is (-1/alpha).
  402. M : float, optional
  403. Number of previous vectors to retain. Defaults to 5.
  404. w0 : float, optional
  405. Regularization parameter for numerical stability.
  406. Compared to unity, good values of the order of 0.01.
  407. """
  408. pass
  409. def _root_linearmixing_doc():
  410. """
  411. Options
  412. -------
  413. nit : int, optional
  414. Number of iterations to make. If omitted (default), make as many
  415. as required to meet tolerances.
  416. disp : bool, optional
  417. Print status to stdout on every iteration.
  418. maxiter : int, optional
  419. Maximum number of iterations to make. If more are needed to
  420. meet convergence, ``NoConvergence`` is raised.
  421. ftol : float, optional
  422. Relative tolerance for the residual. If omitted, not used.
  423. fatol : float, optional
  424. Absolute tolerance (in max-norm) for the residual.
  425. If omitted, default is 6e-6.
  426. xtol : float, optional
  427. Relative minimum step size. If omitted, not used.
  428. xatol : float, optional
  429. Absolute minimum step size, as determined from the Jacobian
  430. approximation. If the step size is smaller than this, optimization
  431. is terminated as successful. If omitted, not used.
  432. tol_norm : function(vector) -> scalar, optional
  433. Norm to use in convergence check. Default is the maximum norm.
  434. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  435. Which type of a line search to use to determine the step size in
  436. the direction given by the Jacobian approximation. Defaults to
  437. 'armijo'.
  438. jac_options : dict, optional
  439. Options for the respective Jacobian approximation.
  440. alpha : float, optional
  441. initial guess for the jacobian is (-1/alpha).
  442. """
  443. pass
  444. def _root_diagbroyden_doc():
  445. """
  446. Options
  447. -------
  448. nit : int, optional
  449. Number of iterations to make. If omitted (default), make as many
  450. as required to meet tolerances.
  451. disp : bool, optional
  452. Print status to stdout on every iteration.
  453. maxiter : int, optional
  454. Maximum number of iterations to make. If more are needed to
  455. meet convergence, `NoConvergence` is raised.
  456. ftol : float, optional
  457. Relative tolerance for the residual. If omitted, not used.
  458. fatol : float, optional
  459. Absolute tolerance (in max-norm) for the residual.
  460. If omitted, default is 6e-6.
  461. xtol : float, optional
  462. Relative minimum step size. If omitted, not used.
  463. xatol : float, optional
  464. Absolute minimum step size, as determined from the Jacobian
  465. approximation. If the step size is smaller than this, optimization
  466. is terminated as successful. If omitted, not used.
  467. tol_norm : function(vector) -> scalar, optional
  468. Norm to use in convergence check. Default is the maximum norm.
  469. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  470. Which type of a line search to use to determine the step size in
  471. the direction given by the Jacobian approximation. Defaults to
  472. 'armijo'.
  473. jac_options : dict, optional
  474. Options for the respective Jacobian approximation.
  475. alpha : float, optional
  476. initial guess for the jacobian is (-1/alpha).
  477. """
  478. pass
  479. def _root_excitingmixing_doc():
  480. """
  481. Options
  482. -------
  483. nit : int, optional
  484. Number of iterations to make. If omitted (default), make as many
  485. as required to meet tolerances.
  486. disp : bool, optional
  487. Print status to stdout on every iteration.
  488. maxiter : int, optional
  489. Maximum number of iterations to make. If more are needed to
  490. meet convergence, `NoConvergence` is raised.
  491. ftol : float, optional
  492. Relative tolerance for the residual. If omitted, not used.
  493. fatol : float, optional
  494. Absolute tolerance (in max-norm) for the residual.
  495. If omitted, default is 6e-6.
  496. xtol : float, optional
  497. Relative minimum step size. If omitted, not used.
  498. xatol : float, optional
  499. Absolute minimum step size, as determined from the Jacobian
  500. approximation. If the step size is smaller than this, optimization
  501. is terminated as successful. If omitted, not used.
  502. tol_norm : function(vector) -> scalar, optional
  503. Norm to use in convergence check. Default is the maximum norm.
  504. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  505. Which type of a line search to use to determine the step size in
  506. the direction given by the Jacobian approximation. Defaults to
  507. 'armijo'.
  508. jac_options : dict, optional
  509. Options for the respective Jacobian approximation.
  510. alpha : float, optional
  511. Initial Jacobian approximation is (-1/alpha).
  512. alphamax : float, optional
  513. The entries of the diagonal Jacobian are kept in the range
  514. ``[alpha, alphamax]``.
  515. """
  516. pass
  517. def _root_krylov_doc():
  518. """
  519. Options
  520. -------
  521. nit : int, optional
  522. Number of iterations to make. If omitted (default), make as many
  523. as required to meet tolerances.
  524. disp : bool, optional
  525. Print status to stdout on every iteration.
  526. maxiter : int, optional
  527. Maximum number of iterations to make. If more are needed to
  528. meet convergence, `NoConvergence` is raised.
  529. ftol : float, optional
  530. Relative tolerance for the residual. If omitted, not used.
  531. fatol : float, optional
  532. Absolute tolerance (in max-norm) for the residual.
  533. If omitted, default is 6e-6.
  534. xtol : float, optional
  535. Relative minimum step size. If omitted, not used.
  536. xatol : float, optional
  537. Absolute minimum step size, as determined from the Jacobian
  538. approximation. If the step size is smaller than this, optimization
  539. is terminated as successful. If omitted, not used.
  540. tol_norm : function(vector) -> scalar, optional
  541. Norm to use in convergence check. Default is the maximum norm.
  542. line_search : {None, 'armijo' (default), 'wolfe'}, optional
  543. Which type of a line search to use to determine the step size in
  544. the direction given by the Jacobian approximation. Defaults to
  545. 'armijo'.
  546. jac_options : dict, optional
  547. Options for the respective Jacobian approximation.
  548. rdiff : float, optional
  549. Relative step size to use in numerical differentiation.
  550. method : {'lgmres', 'gmres', 'bicgstab', 'cgs', 'minres'} or function
  551. Krylov method to use to approximate the Jacobian.
  552. Can be a string, or a function implementing the same
  553. interface as the iterative solvers in
  554. `scipy.sparse.linalg`.
  555. The default is `scipy.sparse.linalg.lgmres`.
  556. inner_M : LinearOperator or InverseJacobian
  557. Preconditioner for the inner Krylov iteration.
  558. Note that you can use also inverse Jacobians as (adaptive)
  559. preconditioners. For example,
  560. >>> jac = BroydenFirst()
  561. >>> kjac = KrylovJacobian(inner_M=jac.inverse).
  562. If the preconditioner has a method named 'update', it will
  563. be called as ``update(x, f)`` after each nonlinear step,
  564. with ``x`` giving the current point, and ``f`` the current
  565. function value.
  566. inner_tol, inner_maxiter, ...
  567. Parameters to pass on to the "inner" Krylov solver.
  568. See `scipy.sparse.linalg.gmres` for details.
  569. outer_k : int, optional
  570. Size of the subspace kept across LGMRES nonlinear
  571. iterations.
  572. See `scipy.sparse.linalg.lgmres` for details.
  573. """
  574. pass