cosapp.core.numerics.root¶
Module provides dispatch to different non-linear algorithms.
Functions
Returns kwargs as a dictionary, using inspect.currentframe |
|
|
Classes
|
|
|
Custom Newton-Raphson solver. |
|
Encapsulation of scipy.optimize.root |
- class cosapp.core.numerics.root.BaseNumericalSolver(options={})[source]¶
Bases:
ABC- property options: Dict[str, Any]¶
- abstract solve(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[Any] = (), *other_args, **kwargs) SolverResults | OptimizeResult[source]¶
- class cosapp.core.numerics.root.CustomSolver(tol='auto', factor=1.0, max_iter=100, verbose=False, eps=1.1920928955078125e-07, jac_update_tol=0.01, history=False, partial_jac=True, partial_jac_tries=5, tol_update_period=4, tol_to_noise_ratio=16)[source]¶
Bases:
BaseNumericalSolverCustom Newton-Raphson solver.
- solve(fresidues: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[float | str] = (), jac=None, callback: Callable[[ndarray[float], ndarray[float]], None] | None = None, **options) SolverResults[source]¶
Customized Newton-Raphson algorithm to solve fresidues starting with x0.
- Parameters:
[callable[[Sequence[float] (- fresidues) – Callable residues function
Any] – Callable residues function
numpy.ndarray[float]]] – Callable residues function
[sequence[float]] (- x0) – Initial solution guess
[tuple[Any (- args) – Additional arguments for fun
...]] – Additional arguments for fun
[dict (- options) – A dictionary of problem-dependent solver options.
optional] – A dictionary of problem-dependent solver options.
[callable (- callback) – Optional callback function. It is called on every iteration as callback(x, r), where x is the current solution and r the corresponding residual.
optional] – Optional callback function. It is called on every iteration as callback(x, r), where x is the current solution and r the corresponding residual.
Options
-------
ndarray[int] (- jac_lup [ndarray[float] |) – LU decomposition of Jacobian given as tuple (LU, perm) to reuse as initial direction
optional] – LU decomposition of Jacobian given as tuple (LU, perm) to reuse as initial direction
[ndarray (- jac) – Jacobian to reuse for partial update
optional] – Jacobian to reuse for partial update
[bool] (- compute_jacobian) – Force to update the Jacobian matrix even if the provided one is useful
[numpy.ndarray] (- rel_step) – Min values for parameters iterated by solver.
[numpy.ndarray] – Max values for parameters iterated by solver.
[numpy.ndarray] – Max absolute step for parameters iterated by solver.
[numpy.ndarray] – Max relative step for parameters iterated by solver.
- Returns:
The solution represented as a SolverResults object. See
cosapp.core.numerics.basics.SolverResultsfor details.- Return type:
- class cosapp.core.numerics.root.NumpySolver(method: str, options={})[source]¶
Bases:
BaseNumericalSolverEncapsulation of scipy.optimize.root
- solve(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[float | str] = (), jac=None, callback=None) OptimizeResult[source]¶
Cancel residues produced by fun starting with x0 as initial guess.
- Parameters:
[callable[[sequence[float] (- fun) – Callable residues function
Any] – Callable residues function
numpy.ndarray[float]]] – Callable residues function
[sequence[float]] (- x0) – Initial solution guess
[tuple[Any (- args) – Additional arguments passed to fun
...]] – Additional arguments passed to fun
callable (- jac [bool or) – If jac is a Boolean and is True, fun is assumed to return the value of Jacobian along with the objective function. If False, the Jacobian will be estimated numerically. jac can also be a callable returning the Jacobian of fun. In this case, it must accept the same arguments as fun. (default: None)
optional] – If jac is a Boolean and is True, fun is assumed to return the value of Jacobian along with the objective function. If False, the Jacobian will be estimated numerically. jac can also be a callable returning the Jacobian of fun. In this case, it must accept the same arguments as fun. (default: None)
[Callable (- callback) – Optional callback function. It is called on every iteration as callback(x, r), where x is the current solution and r the corresponding residual.
optional] – Optional callback function. It is called on every iteration as callback(x, r), where x is the current solution and r the corresponding residual.
- Returns:
The solution represented as a OptimizeResult object. Important attributes are: x the solution array, success a Boolean flag indicating if the algorithm exited successfully and message which describes the cause of the termination. See
cosapp.core.numerics.basics.SolverResultsfor a description of other attributes.- Return type:
scipy.optimize.OptimizeResult
- cosapp.core.numerics.root.get_kwargs()[source]¶
Returns kwargs as a dictionary, using inspect.currentframe
- cosapp.core.numerics.root.root(fun: Callable[[Sequence[float], Any], ndarray], x0: Sequence[float], args: Tuple[Any] = (), method: NonLinearMethods = NonLinearMethods.POWELL, options: Dict[str, Any] = {}, callback: Callable[[], None] | None = None) SolverResults | OptimizeResult[source]¶