scipy_optimizer

class nrv.optim.scipy_optimizer(method: str = None, x0: <MagicMock name='mock.ndarray' id='139958332223088'> = None, args: tuple = (), jac: callable = None, hess: callable = None, hessp: callable = None, bounds: tuple = None, constraints: dict = (), tol: float = None, callback: callable = None, maxiter: int = None, options: dict = None, dimension: int = None, normalize: bool = False)[source]
Parameters:
  • method (str | callable, optional) –

    Type of solver. Should be one of
    • ’Nelder-Mead’

    • ’Powell’

    • ’CG’

    • ’BFGS’

    • ’Newton-CG’

    • ’L-BFGS-B’

    • ’TNC’

    • ’COBYLA’

    • ’SLSQP’

    • ’trust-constr’

    • ’dogleg’

    • ’trust-ncg’

    • ’trust-exact’

    • ’trust-krylov’

    • custom - a callable object

  • x0 (np.ndarray, optional) – Initial guess. Array of real elements of size (n,), where n is the number of independent variables,. by default None

  • args (tuple, optional) – Extra arguments passed to the objective function and its derivatives (fun, jac and hess functions), by default ()

  • jac ({callable, '2-point', '3-point', 'cs', bool}, optional) – Method for computing the gradient vector, optional _description_, by default None

  • hess ({callable, '2-point', '3-point', 'cs', HessianUpdateStrategy}, optional) – Method for computing the Hessian matrix, by default None

  • hessp (callable, optional) – Hessian of objective function times an arbitrary vector p. Only for Newton-CG, trust-ncg, trust-krylov, trust-constr, by default None

  • bounds (sequence or Bounds, optional) – Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell, trust-constr, and COBYLA methods., by default None

  • constraints ({Constraint, dict} or List of {Constraint, dict}, optional) – Constraints definition. Only for COBYLA, SLSQP and trust-constr, by default ()

  • tol (float, optional) – Tolerance for termination, by default None

  • callback (callable, optional) – A callable called after each iteration, by default None

  • maxiter (int, optional) – _description_, by default None

  • options (dict, optional) – A dictionary of solver options, by default None

  • dimension (int, optional) – _description_, by default None

  • normalize (bool, optional) – _description_, by default False

Note

The following arguments are those used in scipy.optimize.minimize (see scipy documentation [2] for more informations): x0, args, jac, hess, hessp, bounds, constraints, tol, callback, options

Examples

The following lines shows how scipy_optimizer can be used to minimze a 2D sphere function.

>>> import nrv
>>> my_cost1 = nrv.sphere()
>>> my_opt = nrv.scipy_optimizer(dimension=2, x0= [100, 10], maxiter=10)
>>> res = my_opt.minimize(my_cost1)
>>> print("best position",res.x, "best cost", res.best_cost)

best position [-1.52666570e-08 -1.32835147e-07] best cost 1.337095622502969e-07

References

[1] scipy

[2] scipy.optimize.minimize

Methods

scipy_optimizer.__init__([method, x0, args, ...])

Init method for NRV_class

scipy_optimizer.get_parameters()

Generic method returning all the atributes of an NRV_class instance

scipy_optimizer.load(data[, blacklist])

Generic loading method for NRV_class instance

scipy_optimizer.minimize(f, **kwargs)

Minimze the function f using the optimzer's parameters

scipy_optimizer.save([save, fname, blacklist])

Generic saving method for NRV_class instance.

scipy_optimizer.set_parameters(**kawrgs)

Generic method to set any attribute of NRV_class instance