Coverage for /usr/lib/python3/dist-packages/scipy/optimize/_root.py: 22%

88 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-14 15:55 +0200

1""" 

2Unified interfaces to root finding algorithms. 

3 

4Functions 

5--------- 

6- root : find a root of a vector function. 

7""" 

8__all__ = ['root'] 

9 

10import numpy as np 

11 

12from warnings import warn 

13 

14from ._optimize import MemoizeJac, OptimizeResult, _check_unknown_options 

15from ._minpack_py import _root_hybr, leastsq 

16from ._spectral import _root_df_sane 

17from . import _nonlin as nonlin 

18 

19 

20ROOT_METHODS = ['hybr', 'lm', 'broyden1', 'broyden2', 'anderson', 

21 'linearmixing', 'diagbroyden', 'excitingmixing', 'krylov', 

22 'df-sane'] 

23 

24 

25def root(fun, x0, args=(), method='hybr', jac=None, tol=None, callback=None, 

26 options=None): 

27 r""" 

28 Find a root of a vector function. 

29 

30 Parameters 

31 ---------- 

32 fun : callable 

33 A vector function to find a root of. 

34 x0 : ndarray 

35 Initial guess. 

36 args : tuple, optional 

37 Extra arguments passed to the objective function and its Jacobian. 

38 method : str, optional 

39 Type of solver. Should be one of 

40 

41 - 'hybr' :ref:`(see here) <optimize.root-hybr>` 

42 - 'lm' :ref:`(see here) <optimize.root-lm>` 

43 - 'broyden1' :ref:`(see here) <optimize.root-broyden1>` 

44 - 'broyden2' :ref:`(see here) <optimize.root-broyden2>` 

45 - 'anderson' :ref:`(see here) <optimize.root-anderson>` 

46 - 'linearmixing' :ref:`(see here) <optimize.root-linearmixing>` 

47 - 'diagbroyden' :ref:`(see here) <optimize.root-diagbroyden>` 

48 - 'excitingmixing' :ref:`(see here) <optimize.root-excitingmixing>` 

49 - 'krylov' :ref:`(see here) <optimize.root-krylov>` 

50 - 'df-sane' :ref:`(see here) <optimize.root-dfsane>` 

51 

52 jac : bool or callable, optional 

53 If `jac` is a Boolean and is True, `fun` is assumed to return the 

54 value of Jacobian along with the objective function. If False, the 

55 Jacobian will be estimated numerically. 

56 `jac` can also be a callable returning the Jacobian of `fun`. In 

57 this case, it must accept the same arguments as `fun`. 

58 tol : float, optional 

59 Tolerance for termination. For detailed control, use solver-specific 

60 options. 

61 callback : function, optional 

62 Optional callback function. It is called on every iteration as 

63 ``callback(x, f)`` where `x` is the current solution and `f` 

64 the corresponding residual. For all methods but 'hybr' and 'lm'. 

65 options : dict, optional 

66 A dictionary of solver options. E.g., `xtol` or `maxiter`, see 

67 :obj:`show_options()` for details. 

68 

69 Returns 

70 ------- 

71 sol : OptimizeResult 

72 The solution represented as a ``OptimizeResult`` object. 

73 Important attributes are: ``x`` the solution array, ``success`` a 

74 Boolean flag indicating if the algorithm exited successfully and 

75 ``message`` which describes the cause of the termination. See 

76 `OptimizeResult` for a description of other attributes. 

77 

78 See also 

79 -------- 

80 show_options : Additional options accepted by the solvers 

81 

82 Notes 

83 ----- 

84 This section describes the available solvers that can be selected by the 

85 'method' parameter. The default method is *hybr*. 

86 

87 Method *hybr* uses a modification of the Powell hybrid method as 

88 implemented in MINPACK [1]_. 

89 

90 Method *lm* solves the system of nonlinear equations in a least squares 

91 sense using a modification of the Levenberg-Marquardt algorithm as 

92 implemented in MINPACK [1]_. 

93 

94 Method *df-sane* is a derivative-free spectral method. [3]_ 

95 

96 Methods *broyden1*, *broyden2*, *anderson*, *linearmixing*, 

97 *diagbroyden*, *excitingmixing*, *krylov* are inexact Newton methods, 

98 with backtracking or full line searches [2]_. Each method corresponds 

99 to a particular Jacobian approximations. 

100 

101 - Method *broyden1* uses Broyden's first Jacobian approximation, it is 

102 known as Broyden's good method. 

103 - Method *broyden2* uses Broyden's second Jacobian approximation, it 

104 is known as Broyden's bad method. 

105 - Method *anderson* uses (extended) Anderson mixing. 

106 - Method *Krylov* uses Krylov approximation for inverse Jacobian. It 

107 is suitable for large-scale problem. 

108 - Method *diagbroyden* uses diagonal Broyden Jacobian approximation. 

109 - Method *linearmixing* uses a scalar Jacobian approximation. 

110 - Method *excitingmixing* uses a tuned diagonal Jacobian 

111 approximation. 

112 

113 .. warning:: 

114 

115 The algorithms implemented for methods *diagbroyden*, 

116 *linearmixing* and *excitingmixing* may be useful for specific 

117 problems, but whether they will work may depend strongly on the 

118 problem. 

119 

120 .. versionadded:: 0.11.0 

121 

122 References 

123 ---------- 

124 .. [1] More, Jorge J., Burton S. Garbow, and Kenneth E. Hillstrom. 

125 1980. User Guide for MINPACK-1. 

126 .. [2] C. T. Kelley. 1995. Iterative Methods for Linear and Nonlinear 

127 Equations. Society for Industrial and Applied Mathematics. 

128 <https://archive.siam.org/books/kelley/fr16/> 

129 .. [3] W. La Cruz, J.M. Martinez, M. Raydan. Math. Comp. 75, 1429 (2006). 

130 

131 Examples 

132 -------- 

133 The following functions define a system of nonlinear equations and its 

134 jacobian. 

135 

136 >>> import numpy as np 

137 >>> def fun(x): 

138 ... return [x[0] + 0.5 * (x[0] - x[1])**3 - 1.0, 

139 ... 0.5 * (x[1] - x[0])**3 + x[1]] 

140 

141 >>> def jac(x): 

142 ... return np.array([[1 + 1.5 * (x[0] - x[1])**2, 

143 ... -1.5 * (x[0] - x[1])**2], 

144 ... [-1.5 * (x[1] - x[0])**2, 

145 ... 1 + 1.5 * (x[1] - x[0])**2]]) 

146 

147 A solution can be obtained as follows. 

148 

149 >>> from scipy import optimize 

150 >>> sol = optimize.root(fun, [0, 0], jac=jac, method='hybr') 

151 >>> sol.x 

152 array([ 0.8411639, 0.1588361]) 

153 

154 **Large problem** 

155 

156 Suppose that we needed to solve the following integrodifferential 

157 equation on the square :math:`[0,1]\times[0,1]`: 

158 

159 .. math:: 

160 

161 \nabla^2 P = 10 \left(\int_0^1\int_0^1\cosh(P)\,dx\,dy\right)^2 

162 

163 with :math:`P(x,1) = 1` and :math:`P=0` elsewhere on the boundary of 

164 the square. 

165 

166 The solution can be found using the ``method='krylov'`` solver: 

167 

168 >>> from scipy import optimize 

169 >>> # parameters 

170 >>> nx, ny = 75, 75 

171 >>> hx, hy = 1./(nx-1), 1./(ny-1) 

172 

173 >>> P_left, P_right = 0, 0 

174 >>> P_top, P_bottom = 1, 0 

175 

176 >>> def residual(P): 

177 ... d2x = np.zeros_like(P) 

178 ... d2y = np.zeros_like(P) 

179 ... 

180 ... d2x[1:-1] = (P[2:] - 2*P[1:-1] + P[:-2]) / hx/hx 

181 ... d2x[0] = (P[1] - 2*P[0] + P_left)/hx/hx 

182 ... d2x[-1] = (P_right - 2*P[-1] + P[-2])/hx/hx 

183 ... 

184 ... d2y[:,1:-1] = (P[:,2:] - 2*P[:,1:-1] + P[:,:-2])/hy/hy 

185 ... d2y[:,0] = (P[:,1] - 2*P[:,0] + P_bottom)/hy/hy 

186 ... d2y[:,-1] = (P_top - 2*P[:,-1] + P[:,-2])/hy/hy 

187 ... 

188 ... return d2x + d2y - 10*np.cosh(P).mean()**2 

189 

190 >>> guess = np.zeros((nx, ny), float) 

191 >>> sol = optimize.root(residual, guess, method='krylov') 

192 >>> print('Residual: %g' % abs(residual(sol.x)).max()) 

193 Residual: 5.7972e-06 # may vary 

194 

195 >>> import matplotlib.pyplot as plt 

196 >>> x, y = np.mgrid[0:1:(nx*1j), 0:1:(ny*1j)] 

197 >>> plt.pcolormesh(x, y, sol.x, shading='gouraud') 

198 >>> plt.colorbar() 

199 >>> plt.show() 

200 

201 """ 

202 if not isinstance(args, tuple): 

203 args = (args,) 

204 

205 meth = method.lower() 

206 if options is None: 

207 options = {} 

208 

209 if callback is not None and meth in ('hybr', 'lm'): 

210 warn('Method %s does not accept callback.' % method, 

211 RuntimeWarning) 

212 

213 # fun also returns the Jacobian 

214 if not callable(jac) and meth in ('hybr', 'lm'): 

215 if bool(jac): 

216 fun = MemoizeJac(fun) 

217 jac = fun.derivative 

218 else: 

219 jac = None 

220 

221 # set default tolerances 

222 if tol is not None: 

223 options = dict(options) 

224 if meth in ('hybr', 'lm'): 

225 options.setdefault('xtol', tol) 

226 elif meth in ('df-sane',): 

227 options.setdefault('ftol', tol) 

228 elif meth in ('broyden1', 'broyden2', 'anderson', 'linearmixing', 

229 'diagbroyden', 'excitingmixing', 'krylov'): 

230 options.setdefault('xtol', tol) 

231 options.setdefault('xatol', np.inf) 

232 options.setdefault('ftol', np.inf) 

233 options.setdefault('fatol', np.inf) 

234 

235 if meth == 'hybr': 

236 sol = _root_hybr(fun, x0, args=args, jac=jac, **options) 

237 elif meth == 'lm': 

238 sol = _root_leastsq(fun, x0, args=args, jac=jac, **options) 

239 elif meth == 'df-sane': 

240 _warn_jac_unused(jac, method) 

241 sol = _root_df_sane(fun, x0, args=args, callback=callback, 

242 **options) 

243 elif meth in ('broyden1', 'broyden2', 'anderson', 'linearmixing', 

244 'diagbroyden', 'excitingmixing', 'krylov'): 

245 _warn_jac_unused(jac, method) 

246 sol = _root_nonlin_solve(fun, x0, args=args, jac=jac, 

247 _method=meth, _callback=callback, 

248 **options) 

249 else: 

250 raise ValueError('Unknown solver %s' % method) 

251 

252 return sol 

253 

254 

255def _warn_jac_unused(jac, method): 

256 if jac is not None: 

257 warn(f'Method {method} does not use the jacobian (jac).', 

258 RuntimeWarning) 

259 

260 

261def _root_leastsq(fun, x0, args=(), jac=None, 

262 col_deriv=0, xtol=1.49012e-08, ftol=1.49012e-08, 

263 gtol=0.0, maxiter=0, eps=0.0, factor=100, diag=None, 

264 **unknown_options): 

265 """ 

266 Solve for least squares with Levenberg-Marquardt 

267 

268 Options 

269 ------- 

270 col_deriv : bool 

271 non-zero to specify that the Jacobian function computes derivatives 

272 down the columns (faster, because there is no transpose operation). 

273 ftol : float 

274 Relative error desired in the sum of squares. 

275 xtol : float 

276 Relative error desired in the approximate solution. 

277 gtol : float 

278 Orthogonality desired between the function vector and the columns 

279 of the Jacobian. 

280 maxiter : int 

281 The maximum number of calls to the function. If zero, then 

282 100*(N+1) is the maximum where N is the number of elements in x0. 

283 epsfcn : float 

284 A suitable step length for the forward-difference approximation of 

285 the Jacobian (for Dfun=None). If epsfcn is less than the machine 

286 precision, it is assumed that the relative errors in the functions 

287 are of the order of the machine precision. 

288 factor : float 

289 A parameter determining the initial step bound 

290 (``factor * || diag * x||``). Should be in interval ``(0.1, 100)``. 

291 diag : sequence 

292 N positive entries that serve as a scale factors for the variables. 

293 """ 

294 

295 _check_unknown_options(unknown_options) 

296 x, cov_x, info, msg, ier = leastsq(fun, x0, args=args, Dfun=jac, 

297 full_output=True, 

298 col_deriv=col_deriv, xtol=xtol, 

299 ftol=ftol, gtol=gtol, 

300 maxfev=maxiter, epsfcn=eps, 

301 factor=factor, diag=diag) 

302 sol = OptimizeResult(x=x, message=msg, status=ier, 

303 success=ier in (1, 2, 3, 4), cov_x=cov_x, 

304 fun=info.pop('fvec')) 

305 sol.update(info) 

306 return sol 

307 

308 

309def _root_nonlin_solve(fun, x0, args=(), jac=None, 

310 _callback=None, _method=None, 

311 nit=None, disp=False, maxiter=None, 

312 ftol=None, fatol=None, xtol=None, xatol=None, 

313 tol_norm=None, line_search='armijo', jac_options=None, 

314 **unknown_options): 

315 _check_unknown_options(unknown_options) 

316 

317 f_tol = fatol 

318 f_rtol = ftol 

319 x_tol = xatol 

320 x_rtol = xtol 

321 verbose = disp 

322 if jac_options is None: 

323 jac_options = dict() 

324 

325 jacobian = {'broyden1': nonlin.BroydenFirst, 

326 'broyden2': nonlin.BroydenSecond, 

327 'anderson': nonlin.Anderson, 

328 'linearmixing': nonlin.LinearMixing, 

329 'diagbroyden': nonlin.DiagBroyden, 

330 'excitingmixing': nonlin.ExcitingMixing, 

331 'krylov': nonlin.KrylovJacobian 

332 }[_method] 

333 

334 if args: 

335 if jac is True: 

336 def f(x): 

337 return fun(x, *args)[0] 

338 else: 

339 def f(x): 

340 return fun(x, *args) 

341 else: 

342 f = fun 

343 

344 x, info = nonlin.nonlin_solve(f, x0, jacobian=jacobian(**jac_options), 

345 iter=nit, verbose=verbose, 

346 maxiter=maxiter, f_tol=f_tol, 

347 f_rtol=f_rtol, x_tol=x_tol, 

348 x_rtol=x_rtol, tol_norm=tol_norm, 

349 line_search=line_search, 

350 callback=_callback, full_output=True, 

351 raise_exception=False) 

352 sol = OptimizeResult(x=x) 

353 sol.update(info) 

354 return sol 

355 

356def _root_broyden1_doc(): 

357 """ 

358 Options 

359 ------- 

360 nit : int, optional 

361 Number of iterations to make. If omitted (default), make as many 

362 as required to meet tolerances. 

363 disp : bool, optional 

364 Print status to stdout on every iteration. 

365 maxiter : int, optional 

366 Maximum number of iterations to make. If more are needed to 

367 meet convergence, `NoConvergence` is raised. 

368 ftol : float, optional 

369 Relative tolerance for the residual. If omitted, not used. 

370 fatol : float, optional 

371 Absolute tolerance (in max-norm) for the residual. 

372 If omitted, default is 6e-6. 

373 xtol : float, optional 

374 Relative minimum step size. If omitted, not used. 

375 xatol : float, optional 

376 Absolute minimum step size, as determined from the Jacobian 

377 approximation. If the step size is smaller than this, optimization 

378 is terminated as successful. If omitted, not used. 

379 tol_norm : function(vector) -> scalar, optional 

380 Norm to use in convergence check. Default is the maximum norm. 

381 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

382 Which type of a line search to use to determine the step size in 

383 the direction given by the Jacobian approximation. Defaults to 

384 'armijo'. 

385 jac_options : dict, optional 

386 Options for the respective Jacobian approximation. 

387 alpha : float, optional 

388 Initial guess for the Jacobian is (-1/alpha). 

389 reduction_method : str or tuple, optional 

390 Method used in ensuring that the rank of the Broyden 

391 matrix stays low. Can either be a string giving the 

392 name of the method, or a tuple of the form ``(method, 

393 param1, param2, ...)`` that gives the name of the 

394 method and values for additional parameters. 

395 

396 Methods available: 

397 

398 - ``restart`` 

399 Drop all matrix columns. Has no 

400 extra parameters. 

401 - ``simple`` 

402 Drop oldest matrix column. Has no 

403 extra parameters. 

404 - ``svd`` 

405 Keep only the most significant SVD 

406 components. 

407 

408 Extra parameters: 

409 

410 - ``to_retain`` 

411 Number of SVD components to 

412 retain when rank reduction is done. 

413 Default is ``max_rank - 2``. 

414 max_rank : int, optional 

415 Maximum rank for the Broyden matrix. 

416 Default is infinity (i.e., no rank reduction). 

417 

418 Examples 

419 -------- 

420 >>> def func(x): 

421 ... return np.cos(x) + x[::-1] - [1, 2, 3, 4] 

422 ... 

423 >>> from scipy import optimize 

424 >>> res = optimize.root(func, [1, 1, 1, 1], method='broyden1', tol=1e-14) 

425 >>> x = res.x 

426 >>> x 

427 array([4.04674914, 3.91158389, 2.71791677, 1.61756251]) 

428 >>> np.cos(x) + x[::-1] 

429 array([1., 2., 3., 4.]) 

430 

431 """ 

432 pass 

433 

434def _root_broyden2_doc(): 

435 """ 

436 Options 

437 ------- 

438 nit : int, optional 

439 Number of iterations to make. If omitted (default), make as many 

440 as required to meet tolerances. 

441 disp : bool, optional 

442 Print status to stdout on every iteration. 

443 maxiter : int, optional 

444 Maximum number of iterations to make. If more are needed to 

445 meet convergence, `NoConvergence` is raised. 

446 ftol : float, optional 

447 Relative tolerance for the residual. If omitted, not used. 

448 fatol : float, optional 

449 Absolute tolerance (in max-norm) for the residual. 

450 If omitted, default is 6e-6. 

451 xtol : float, optional 

452 Relative minimum step size. If omitted, not used. 

453 xatol : float, optional 

454 Absolute minimum step size, as determined from the Jacobian 

455 approximation. If the step size is smaller than this, optimization 

456 is terminated as successful. If omitted, not used. 

457 tol_norm : function(vector) -> scalar, optional 

458 Norm to use in convergence check. Default is the maximum norm. 

459 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

460 Which type of a line search to use to determine the step size in 

461 the direction given by the Jacobian approximation. Defaults to 

462 'armijo'. 

463 jac_options : dict, optional 

464 Options for the respective Jacobian approximation. 

465 

466 alpha : float, optional 

467 Initial guess for the Jacobian is (-1/alpha). 

468 reduction_method : str or tuple, optional 

469 Method used in ensuring that the rank of the Broyden 

470 matrix stays low. Can either be a string giving the 

471 name of the method, or a tuple of the form ``(method, 

472 param1, param2, ...)`` that gives the name of the 

473 method and values for additional parameters. 

474 

475 Methods available: 

476 

477 - ``restart`` 

478 Drop all matrix columns. Has no 

479 extra parameters. 

480 - ``simple`` 

481 Drop oldest matrix column. Has no 

482 extra parameters. 

483 - ``svd`` 

484 Keep only the most significant SVD 

485 components. 

486 

487 Extra parameters: 

488 

489 - ``to_retain`` 

490 Number of SVD components to 

491 retain when rank reduction is done. 

492 Default is ``max_rank - 2``. 

493 max_rank : int, optional 

494 Maximum rank for the Broyden matrix. 

495 Default is infinity (i.e., no rank reduction). 

496 """ 

497 pass 

498 

499def _root_anderson_doc(): 

500 """ 

501 Options 

502 ------- 

503 nit : int, optional 

504 Number of iterations to make. If omitted (default), make as many 

505 as required to meet tolerances. 

506 disp : bool, optional 

507 Print status to stdout on every iteration. 

508 maxiter : int, optional 

509 Maximum number of iterations to make. If more are needed to 

510 meet convergence, `NoConvergence` is raised. 

511 ftol : float, optional 

512 Relative tolerance for the residual. If omitted, not used. 

513 fatol : float, optional 

514 Absolute tolerance (in max-norm) for the residual. 

515 If omitted, default is 6e-6. 

516 xtol : float, optional 

517 Relative minimum step size. If omitted, not used. 

518 xatol : float, optional 

519 Absolute minimum step size, as determined from the Jacobian 

520 approximation. If the step size is smaller than this, optimization 

521 is terminated as successful. If omitted, not used. 

522 tol_norm : function(vector) -> scalar, optional 

523 Norm to use in convergence check. Default is the maximum norm. 

524 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

525 Which type of a line search to use to determine the step size in 

526 the direction given by the Jacobian approximation. Defaults to 

527 'armijo'. 

528 jac_options : dict, optional 

529 Options for the respective Jacobian approximation. 

530 

531 alpha : float, optional 

532 Initial guess for the Jacobian is (-1/alpha). 

533 M : float, optional 

534 Number of previous vectors to retain. Defaults to 5. 

535 w0 : float, optional 

536 Regularization parameter for numerical stability. 

537 Compared to unity, good values of the order of 0.01. 

538 """ 

539 pass 

540 

541def _root_linearmixing_doc(): 

542 """ 

543 Options 

544 ------- 

545 nit : int, optional 

546 Number of iterations to make. If omitted (default), make as many 

547 as required to meet tolerances. 

548 disp : bool, optional 

549 Print status to stdout on every iteration. 

550 maxiter : int, optional 

551 Maximum number of iterations to make. If more are needed to 

552 meet convergence, ``NoConvergence`` is raised. 

553 ftol : float, optional 

554 Relative tolerance for the residual. If omitted, not used. 

555 fatol : float, optional 

556 Absolute tolerance (in max-norm) for the residual. 

557 If omitted, default is 6e-6. 

558 xtol : float, optional 

559 Relative minimum step size. If omitted, not used. 

560 xatol : float, optional 

561 Absolute minimum step size, as determined from the Jacobian 

562 approximation. If the step size is smaller than this, optimization 

563 is terminated as successful. If omitted, not used. 

564 tol_norm : function(vector) -> scalar, optional 

565 Norm to use in convergence check. Default is the maximum norm. 

566 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

567 Which type of a line search to use to determine the step size in 

568 the direction given by the Jacobian approximation. Defaults to 

569 'armijo'. 

570 jac_options : dict, optional 

571 Options for the respective Jacobian approximation. 

572 

573 alpha : float, optional 

574 initial guess for the jacobian is (-1/alpha). 

575 """ 

576 pass 

577 

578def _root_diagbroyden_doc(): 

579 """ 

580 Options 

581 ------- 

582 nit : int, optional 

583 Number of iterations to make. If omitted (default), make as many 

584 as required to meet tolerances. 

585 disp : bool, optional 

586 Print status to stdout on every iteration. 

587 maxiter : int, optional 

588 Maximum number of iterations to make. If more are needed to 

589 meet convergence, `NoConvergence` is raised. 

590 ftol : float, optional 

591 Relative tolerance for the residual. If omitted, not used. 

592 fatol : float, optional 

593 Absolute tolerance (in max-norm) for the residual. 

594 If omitted, default is 6e-6. 

595 xtol : float, optional 

596 Relative minimum step size. If omitted, not used. 

597 xatol : float, optional 

598 Absolute minimum step size, as determined from the Jacobian 

599 approximation. If the step size is smaller than this, optimization 

600 is terminated as successful. If omitted, not used. 

601 tol_norm : function(vector) -> scalar, optional 

602 Norm to use in convergence check. Default is the maximum norm. 

603 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

604 Which type of a line search to use to determine the step size in 

605 the direction given by the Jacobian approximation. Defaults to 

606 'armijo'. 

607 jac_options : dict, optional 

608 Options for the respective Jacobian approximation. 

609 

610 alpha : float, optional 

611 initial guess for the jacobian is (-1/alpha). 

612 """ 

613 pass 

614 

615def _root_excitingmixing_doc(): 

616 """ 

617 Options 

618 ------- 

619 nit : int, optional 

620 Number of iterations to make. If omitted (default), make as many 

621 as required to meet tolerances. 

622 disp : bool, optional 

623 Print status to stdout on every iteration. 

624 maxiter : int, optional 

625 Maximum number of iterations to make. If more are needed to 

626 meet convergence, `NoConvergence` is raised. 

627 ftol : float, optional 

628 Relative tolerance for the residual. If omitted, not used. 

629 fatol : float, optional 

630 Absolute tolerance (in max-norm) for the residual. 

631 If omitted, default is 6e-6. 

632 xtol : float, optional 

633 Relative minimum step size. If omitted, not used. 

634 xatol : float, optional 

635 Absolute minimum step size, as determined from the Jacobian 

636 approximation. If the step size is smaller than this, optimization 

637 is terminated as successful. If omitted, not used. 

638 tol_norm : function(vector) -> scalar, optional 

639 Norm to use in convergence check. Default is the maximum norm. 

640 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

641 Which type of a line search to use to determine the step size in 

642 the direction given by the Jacobian approximation. Defaults to 

643 'armijo'. 

644 jac_options : dict, optional 

645 Options for the respective Jacobian approximation. 

646 

647 alpha : float, optional 

648 Initial Jacobian approximation is (-1/alpha). 

649 alphamax : float, optional 

650 The entries of the diagonal Jacobian are kept in the range 

651 ``[alpha, alphamax]``. 

652 """ 

653 pass 

654 

655def _root_krylov_doc(): 

656 """ 

657 Options 

658 ------- 

659 nit : int, optional 

660 Number of iterations to make. If omitted (default), make as many 

661 as required to meet tolerances. 

662 disp : bool, optional 

663 Print status to stdout on every iteration. 

664 maxiter : int, optional 

665 Maximum number of iterations to make. If more are needed to 

666 meet convergence, `NoConvergence` is raised. 

667 ftol : float, optional 

668 Relative tolerance for the residual. If omitted, not used. 

669 fatol : float, optional 

670 Absolute tolerance (in max-norm) for the residual. 

671 If omitted, default is 6e-6. 

672 xtol : float, optional 

673 Relative minimum step size. If omitted, not used. 

674 xatol : float, optional 

675 Absolute minimum step size, as determined from the Jacobian 

676 approximation. If the step size is smaller than this, optimization 

677 is terminated as successful. If omitted, not used. 

678 tol_norm : function(vector) -> scalar, optional 

679 Norm to use in convergence check. Default is the maximum norm. 

680 line_search : {None, 'armijo' (default), 'wolfe'}, optional 

681 Which type of a line search to use to determine the step size in 

682 the direction given by the Jacobian approximation. Defaults to 

683 'armijo'. 

684 jac_options : dict, optional 

685 Options for the respective Jacobian approximation. 

686 

687 rdiff : float, optional 

688 Relative step size to use in numerical differentiation. 

689 method : str or callable, optional 

690 Krylov method to use to approximate the Jacobian. Can be a string, 

691 or a function implementing the same interface as the iterative 

692 solvers in `scipy.sparse.linalg`. If a string, needs to be one of: 

693 ``'lgmres'``, ``'gmres'``, ``'bicgstab'``, ``'cgs'``, ``'minres'``, 

694 ``'tfqmr'``. 

695 

696 The default is `scipy.sparse.linalg.lgmres`. 

697 inner_M : LinearOperator or InverseJacobian 

698 Preconditioner for the inner Krylov iteration. 

699 Note that you can use also inverse Jacobians as (adaptive) 

700 preconditioners. For example, 

701 

702 >>> jac = BroydenFirst() 

703 >>> kjac = KrylovJacobian(inner_M=jac.inverse). 

704 

705 If the preconditioner has a method named 'update', it will 

706 be called as ``update(x, f)`` after each nonlinear step, 

707 with ``x`` giving the current point, and ``f`` the current 

708 function value. 

709 inner_tol, inner_maxiter, ... 

710 Parameters to pass on to the "inner" Krylov solver. 

711 See `scipy.sparse.linalg.gmres` for details. 

712 outer_k : int, optional 

713 Size of the subspace kept across LGMRES nonlinear 

714 iterations. 

715 

716 See `scipy.sparse.linalg.lgmres` for details. 

717 """ 

718 pass