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)¶
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, optional) Stopping tolerance on the infinity norm of the Newton update.maxfev(int, optional) Maximum number of Newton iterations.solver({‘spsolve’, ‘cg’, ‘bicgstab’} or callable, optional) Linear solver used for each Newton step. IfNone, the routine picks'spsolve'for smaller systems and'bicgstab'for larger systems. 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.
Returns¶
scipy.optimize.OptimizeResultResult object with fieldsx,success,nit,fun, andmessage.
Raises¶
ValueErrorIfsolveris not one of the supported names and is not callable.RuntimeErrorIf an iterative linear solver fails to converge.