Directsearch Optimization Solver
directsearch is a Python package for solving unconstrained minimization problems without requiring derivatives of the objective function. It is particularly useful when objective function evaluations are expensive or noisy, implementing a family of direct search methods. The current version is 1.0.1, with releases focused on stability and compatibility.
Warnings
- gotcha Older versions of directsearch (e.g., v1.0.0) may encounter errors or deprecation warnings with newer NumPy versions due to internal API changes in NumPy. Version 1.0.1 specifically addresses this.
- gotcha The initial guess `x0` passed to `directsearch.solve` must be a one-dimensional `numpy.ndarray`.
- gotcha The objective function `f` passed to `directsearch.solve` must return a single `float` value.
Install
-
pip install directsearch
Imports
- solve
from directsearch import solve
Quickstart
import numpy as np
from directsearch import solve
def rosenbrock(x):
# The Rosenbrock function (a common optimization test problem)
return (1.0 - x[0])**2 + 100.0 * (x[1] - x[0]**2)**2
# Initial guess for the minimizer
x0 = np.array([0.0, 0.0])
# Solve the optimization problem
soln = solve(rosenbrock, x0)
print(f"Optimal value: {soln.f}")
print(f"Optimal solution: {soln.x}")