Skip to content

API reference

minimize() runs the optimizer and returns a Result.

Minimize a function using an improved SCE-UA algorithm.

Parameters:

Name Type Description Default
func callable

The objective function to be minimized. func(x, *args) -> float where x is an 1-D array with shape (n,) and args are positional arguments.

required
bounds sequence of tuples

Bounds for variables, (min, max) pairs for each element in x.

required
args tuple

Extra arguments passed to the objective function, defaults to ().

()
n_complexes int

Number of complexes, defaults to None (adaptive based on dimensionality).

None
n_points_complex int

Number of points in each complex. If None, calculated automatically.

None
alpha float

Reflection coefficient, defaults to 1.0.

1.0
beta float

Contraction coefficient, defaults to 0.5.

0.5
max_evals int

Maximum number of function evaluations, defaults to 50000. It must be at least the population size, n_complexes * n_points_complex. The budget is checked once per iteration, so the last iteration can exceed it slightly.

50000
max_iter int

Maximum number of iterations, defaults to 1000.

1000
max_tolerant_iter int

Maximum number of iterations in which neither the best objective value nor the population's median value beats its record, defaults to 30. Scaling the objective by a positive factor or shifting it leaves the stopping point unchanged, up to floating-point resolution.

30
x_tolerance float

Parameter convergence: the run stops once every parameter's range across the population is below this fraction of its bound range, defaults to 1e-4. On a smooth objective this test usually ends the run, and a parameter the objective ignores can keep it from firing.

0.0001
seed int

Random seed for reproducibility, defaults to None.

None
pca_freq int

Frequency of PCA recovery, defaults to 1, i.e., every iterations.

1
pca_tol float

Tolerance for PCA recovery, defaults to 1e-3. This is the threshold for eigenvalues to be considered significant. This threshold is used to apply PCA recovery based on the ratio of eigenvalues to the maximum eigenvalue, i.e., eig / max(eig) < pca_tol, computed with each parameter scaled to [0, 1] by its bounds.

0.001
x0 ndarray

Initial parameter sets to evaluate, each within bounds, defaults to None.

None
max_workers int

Number of workers for parallel execution, defaults to 1 (no parallelism). This is passed to the ThreadPoolExecutor.

1

Returns:

Name Type Description
result Result

The optimization result with the following fields:

  • x : numpy.ndarray The optimal parameters found.
  • fun : float Best function value corresponding to the best parameters.
  • nit : int Number of iterations.
  • nfev : int Number of function evaluations.
  • message : str Description of the termination reason.
  • success : bool Whether the optimizer exited successfully; False when the objective returned NaN at every evaluated point.
  • xv : numpy.ndarray All parameter vectors that were evaluated.
  • funv : numpy.ndarray Function values for all evaluated parameter vectors.

Result object for the optimization.

Attributes:

Name Type Description
x ndarray

Best parameters found.

fun float

Best function value corresponding to the best parameters.

nit int

Number of iterations.

nfev int

Number of function evaluations.

message str

Message describing the termination reason.

success bool

Whether the optimization was successful; False when the objective returned NaN at every evaluated point.

xv ndarray

All evaluated parameter sets.

funv ndarray

Function values for all evaluated parameter sets.