mindspore.scipy.optimize.minimize
- mindspore.scipy.optimize.minimize(func, x0, args=(), *, method, tol=None, options=None)[source]
Minimization of scalar function of one or more variables.
This API for this function matches SciPy with some minor deviations:
Gradients of
func
are calculated automatically using MindSpore’s autodiff support when required.The
method
argument is required. You must specify a solver.Various optional arguments in the SciPy interface have not yet been implemented.
Optimization results may differ from SciPy due to differences in the line search implementation.
It does not yet support differentiation or arguments in the form of multi-dimensional Tensor, but support for both is planned.
- Parameters
func (Callable) – the objective function to be minimized, \(fun(x, *args) -> float\), where x is a 1-D array with shape \((n,)\) and args is a tuple of the fixed parameters needed to completely specify the function. fun must support differentiation.
x0 (Tensor) – initial guess. Array of real elements of size \((n,)\), where n is the number of independent variables.
args (Tuple) – extra arguments passed to the objective function. Default: ().
method (str) – solver type. Currently only “BFGS” is supported.
tol (float, optional) – tolerance for termination. For detailed control, use solver-specific options. Default: None.
options (Mapping[str, Any], optional) –
a dictionary of solver options. All methods accept the following generic options, Default: None.
maxiter (int): Maximum number of iterations to perform. Depending on the method each iteration may use several function evaluations.
- Returns
OptimizeResults, object holding optimization results.
- Supported Platforms:
CPU
GPU
Examples
>>> import numpy as onp >>> from mindspore.scipy.optimize import minimize >>> from mindspore.common import Tensor >>> x0 = Tensor(onp.zeros(2).astype(onp.float32)) >>> def func(p): >>> x, y = p >>> return (x ** 2 + y - 11.) ** 2 + (x + y ** 2 - 7.) ** 2 >>> res = minimize(func, x0, method='BFGS', options=dict(maxiter=None, gtol=1e-6)) >>> res.x Tensor(shape=[2], dtype=Float32, value= [ 3.00000000e+00, 2.00000000e+00])