Nonlinear-solver utilities used by pymrm.
Public API¶
| Symbol | Type | Summary |
|---|---|---|
clip_approach | function | Project values onto bounds, optionally with a relaxed approach rule. |
newton | function | Solve function(x) = 0 with Newton iterations. |
clip_approach(values, dummy, lower_bounds = 0, upper_bounds = None, factor = 0)¶
Project values onto bounds, optionally with a relaxed approach rule.
Parameters¶
values(numpy.ndarray) Values to modify in place.dummy(Any) Placeholder argument kept for API compatibility.lower_bounds, upper_bounds(float or numpy.ndarray, optional) Lower and upper bounds. Scalars and broadcastable arrays are supported.factor(float, optional) Relaxation factor for out-of-bound entries.0applies strict clipping. Non-zero values apply a linear approach update toward the violated bound.
newton(function, initial_guess, args = (), tol = 1.49012e-08, maxfev = 100, solver = None, lin_solver_kwargs = None, callback = None, rtol = 0.0)¶
Solve function(x) = 0 with Newton iterations.
Parameters¶
function(callable) Callable with signaturefunction(x, *args) -> (residual, jacobian).initial_guess(numpy.ndarray) Starting point of the iterations.args(tuple, optional) Extra positional arguments passed tofunction.tol(float or numpy.ndarray, optional) Absolute stopping tolerance on the Newton update. With the defaultrtol=0and a scalartolthe iteration stops when the infinity norm of the update is belowtol. This is an ABSOLUTE criterion: for unknowns much smaller thantol(trace concentrations, for example) it can stop after one step with a wrong answer. Scale the unknowns to order one, or usetol=0withrtol. An array must broadcast to the unknowns.maxfev(int, optional) Maximum number of Newton iterations.solver({‘spsolve’, ‘cg’, ‘bicgstab’, ‘splu’} or callable, optional) Linear solver used for each Newton step. IfNone, the routine picks'spsolve'for smaller systems and'bicgstab'for larger systems. When'splu'is selected, the Jacobian returned byfunctionis expected to be an already-decomposedSuperLUobject (as returned byscipy.sparse.linalg.splu), and the solve step calls its.solve()method directly. A callable solver must accept(jac_matrix, rhs, **kwargs)and return the solution vector.lin_solver_kwargs(dict, optional) Keyword arguments forwarded to the selected linear solver.callback(callable, optional) Optional hook called ascallback(x, residual)after each iteration.rtol(float, optional) Relative stopping tolerance. Whenrtol > 0ortolis an array, the iteration stops when every component satisfiesabs(update) <= tol + rtol * abs(x).tol=0, rtol=1e-8gives a purely relative criterion.
Returns¶
scipy.optimize.OptimizeResultResult object with fieldsx,success,nit,fun,messageandstep_norm(infinity norm of the last update).funis the residual evaluated at the iterate BEFORE the last update, not atx; evaluatefunction(x)to check the final residual.
Raises¶
ValueErrorIfsolveris not one of the supported names and is not callable.RuntimeErrorIf an iterative linear solver fails to converge.